github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/interp/testdata/slice-copy.ll (about)

     1  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
     2  target triple = "x86_64--linux"
     3  
     4  @main.uint8SliceSrc.buf = internal global [2 x i8] c"\03d"
     5  @main.uint8SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.uint8SliceSrc.buf, i64 2, i64 2 }
     6  @main.uint8SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer
     7  @main.int16SliceSrc.buf = internal global [3 x i16] [i16 5, i16 123, i16 1024]
     8  @main.int16SliceSrc = internal unnamed_addr global { ptr, i64, i64 } { ptr @main.int16SliceSrc.buf, i64 3, i64 3 }
     9  @main.int16SliceDst = internal unnamed_addr global { ptr, i64, i64 } zeroinitializer
    10  @main.sliceSrcUntaint.buf = internal global [2 x i8] c"ab"
    11  @main.sliceDstUntaint.buf = internal global [2 x i8] zeroinitializer
    12  @main.sliceSrcTaint.buf = internal global [2 x i8] c"cd"
    13  @main.sliceDstTaint.buf = internal global [2 x i8] zeroinitializer
    14  
    15  declare i64 @runtime.sliceCopy(ptr %dst, ptr %src, i64 %dstLen, i64 %srcLen, i64 %elemSize) unnamed_addr
    16  
    17  declare ptr @runtime.alloc(i64, ptr) unnamed_addr
    18  
    19  declare void @runtime.printuint8(i8)
    20  
    21  declare void @runtime.printint16(i16)
    22  
    23  declare void @use(ptr)
    24  
    25  define void @runtime.initAll() unnamed_addr {
    26  entry:
    27    call void @main.init()
    28    ret void
    29  }
    30  
    31  define void @main() unnamed_addr {
    32  entry:
    33    ; print(uintSliceSrc[0])
    34    %uint8SliceSrc.buf = load ptr, ptr @main.uint8SliceSrc
    35    %uint8SliceSrc.val = load i8, ptr %uint8SliceSrc.buf
    36    call void @runtime.printuint8(i8 %uint8SliceSrc.val)
    37  
    38    ; print(uintSliceDst[0])
    39    %uint8SliceDst.buf = load ptr, ptr @main.uint8SliceDst
    40    %uint8SliceDst.val = load i8, ptr %uint8SliceDst.buf
    41    call void @runtime.printuint8(i8 %uint8SliceDst.val)
    42  
    43    ; print(int16SliceSrc[0])
    44    %int16SliceSrc.buf = load ptr, ptr @main.int16SliceSrc
    45    %int16SliceSrc.val = load i16, ptr %int16SliceSrc.buf
    46    call void @runtime.printint16(i16 %int16SliceSrc.val)
    47  
    48    ; print(int16SliceDst[0])
    49    %int16SliceDst.buf = load ptr, ptr @main.int16SliceDst
    50    %int16SliceDst.val = load i16, ptr %int16SliceDst.buf
    51    call void @runtime.printint16(i16 %int16SliceDst.val)
    52  
    53    ; print(sliceDstUntaint[0])
    54    %sliceDstUntaint.val = load i8, ptr getelementptr inbounds (i8, ptr @main.sliceDstUntaint.buf, i32 0)
    55    call void @runtime.printuint8(i8 %sliceDstUntaint.val)
    56  
    57    ; print(sliceDstTaint[0])
    58    %sliceDstTaint.val = load i8, ptr getelementptr inbounds (i8, ptr @main.sliceDstTaint.buf, i32 0)
    59    call void @runtime.printuint8(i8 %sliceDstTaint.val)
    60  
    61    ret void
    62  }
    63  
    64  define internal void @main.init() unnamed_addr {
    65  entry:
    66    ; equivalent of:
    67    ;     uint8SliceDst = make([]uint8, len(uint8SliceSrc))
    68    %uint8SliceSrc = load { ptr, i64, i64 }, ptr @main.uint8SliceSrc
    69    %uint8SliceSrc.len = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 1
    70    %uint8SliceDst.buf = call ptr @runtime.alloc(i64 %uint8SliceSrc.len, ptr null)
    71    %0 = insertvalue { ptr, i64, i64 } undef, ptr %uint8SliceDst.buf, 0
    72    %1 = insertvalue { ptr, i64, i64 } %0, i64 %uint8SliceSrc.len, 1
    73    %2 = insertvalue { ptr, i64, i64 } %1, i64 %uint8SliceSrc.len, 2
    74    store { ptr, i64, i64 } %2, ptr @main.uint8SliceDst
    75  
    76    ; equivalent of:
    77    ;     copy(uint8SliceDst, uint8SliceSrc)
    78    %uint8SliceSrc.buf = extractvalue { ptr, i64, i64 } %uint8SliceSrc, 0
    79    %copy.n = call i64 @runtime.sliceCopy(ptr %uint8SliceDst.buf, ptr %uint8SliceSrc.buf, i64 %uint8SliceSrc.len, i64 %uint8SliceSrc.len, i64 1)
    80  
    81    ; equivalent of:
    82    ;     int16SliceDst = make([]int16, len(int16SliceSrc))
    83    %int16SliceSrc = load { ptr, i64, i64 }, ptr @main.int16SliceSrc
    84    %int16SliceSrc.len = extractvalue { ptr, i64, i64 } %int16SliceSrc, 1
    85    %int16SliceSrc.len.bytes = mul i64 %int16SliceSrc.len, 2
    86    %int16SliceDst.buf = call ptr @runtime.alloc(i64 %int16SliceSrc.len.bytes, ptr null)
    87    %3 = insertvalue { ptr, i64, i64 } undef, ptr %int16SliceDst.buf, 0
    88    %4 = insertvalue { ptr, i64, i64 } %3, i64 %int16SliceSrc.len, 1
    89    %5 = insertvalue { ptr, i64, i64 } %4, i64 %int16SliceSrc.len, 2
    90    store { ptr, i64, i64 } %5, ptr @main.int16SliceDst
    91  
    92    ; equivalent of:
    93    ;     copy(int16SliceDst, int16SliceSrc)
    94    %int16SliceSrc.buf = extractvalue { ptr, i64, i64 } %int16SliceSrc, 0
    95    %copy.n2 = call i64 @runtime.sliceCopy(ptr %int16SliceDst.buf, ptr %int16SliceSrc.buf, i64 %int16SliceSrc.len, i64 %int16SliceSrc.len, i64 2)
    96  
    97    ; Copy slice that has a known value.
    98    %copy.n3 = call i64 @runtime.sliceCopy(ptr @main.sliceDstUntaint.buf, ptr @main.sliceSrcUntaint.buf, i64 2, i64 2, i64 1)
    99  
   100    ; Copy slice that might have been modified by the external @use call.
   101    ; This is a fix for https://github.com/tinygo-org/tinygo/issues/3890.
   102    call void @use(ptr @main.sliceSrcTaint.buf)
   103    %copy.n4 = call i64 @runtime.sliceCopy(ptr @main.sliceDstTaint.buf, ptr @main.sliceSrcTaint.buf, i64 2, i64 2, i64 1)
   104  
   105    ret void
   106  }