github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/testdata/allocs.out.ll (about)

     1  target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
     2  target triple = "armv7m-none-eabi"
     3  
     4  @runtime.zeroSizedAlloc = internal global i8 0, align 1
     5  
     6  declare nonnull ptr @runtime.alloc(i32, ptr)
     7  
     8  define void @testInt() {
     9    %stackalloc = alloca [4 x i8], align 4
    10    store [4 x i8] zeroinitializer, ptr %stackalloc, align 4
    11    store i32 5, ptr %stackalloc, align 4
    12    ret void
    13  }
    14  
    15  define i16 @testArray() {
    16    %stackalloc = alloca [6 x i8], align 2
    17    store [6 x i8] zeroinitializer, ptr %stackalloc, align 2
    18    %alloc.1 = getelementptr i16, ptr %stackalloc, i32 1
    19    store i16 5, ptr %alloc.1, align 2
    20    %alloc.2 = getelementptr i16, ptr %stackalloc, i32 2
    21    %val = load i16, ptr %alloc.2, align 2
    22    ret i16 %val
    23  }
    24  
    25  define void @testEscapingCall() {
    26    %alloc = call ptr @runtime.alloc(i32 4, ptr null)
    27    %val = call ptr @escapeIntPtr(ptr %alloc)
    28    ret void
    29  }
    30  
    31  define void @testEscapingCall2() {
    32    %alloc = call ptr @runtime.alloc(i32 4, ptr null)
    33    %val = call ptr @escapeIntPtrSometimes(ptr %alloc, ptr %alloc)
    34    ret void
    35  }
    36  
    37  define void @testNonEscapingCall() {
    38    %stackalloc = alloca [4 x i8], align 4
    39    store [4 x i8] zeroinitializer, ptr %stackalloc, align 4
    40    %val = call ptr @noescapeIntPtr(ptr %stackalloc)
    41    ret void
    42  }
    43  
    44  define ptr @testEscapingReturn() {
    45    %alloc = call ptr @runtime.alloc(i32 4, ptr null)
    46    ret ptr %alloc
    47  }
    48  
    49  define void @testNonEscapingLoop() {
    50  entry:
    51    %stackalloc = alloca [4 x i8], align 4
    52    br label %loop
    53  
    54  loop:                                             ; preds = %loop, %entry
    55    store [4 x i8] zeroinitializer, ptr %stackalloc, align 4
    56    %ptr = call ptr @noescapeIntPtr(ptr %stackalloc)
    57    %result = icmp eq ptr null, %ptr
    58    br i1 %result, label %loop, label %end
    59  
    60  end:                                              ; preds = %loop
    61    ret void
    62  }
    63  
    64  define void @testZeroSizedAlloc() {
    65    %ptr = call ptr @noescapeIntPtr(ptr @runtime.zeroSizedAlloc)
    66    ret void
    67  }
    68  
    69  declare ptr @escapeIntPtr(ptr)
    70  
    71  declare ptr @noescapeIntPtr(ptr nocapture)
    72  
    73  declare ptr @escapeIntPtrSometimes(ptr nocapture, ptr)