github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/testdata/stringtobytes.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 @str = constant [6 x i8] c"foobar" 5 6 declare { ptr, i64, i64 } @runtime.stringToBytes(ptr, i64) 7 8 declare void @printSlice(ptr nocapture readonly, i64, i64) 9 10 declare void @writeToSlice(ptr nocapture, i64, i64) 11 12 ; Test that runtime.stringToBytes can be fully optimized away. 13 define void @testReadOnly() { 14 entry: 15 %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) 16 %1 = extractvalue { ptr, i64, i64 } %0, 0 17 %2 = extractvalue { ptr, i64, i64 } %0, 1 18 %3 = extractvalue { ptr, i64, i64 } %0, 2 19 call fastcc void @printSlice(ptr %1, i64 %2, i64 %3) 20 ret void 21 } 22 23 ; Test that even though the slice is written to, some values can be propagated. 24 define void @testReadWrite() { 25 entry: 26 %0 = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) 27 %1 = extractvalue { ptr, i64, i64 } %0, 0 28 %2 = extractvalue { ptr, i64, i64 } %0, 1 29 %3 = extractvalue { ptr, i64, i64 } %0, 2 30 call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3) 31 ret void 32 } 33 34 ; Test that pointer values are never propagated if there is even a single write 35 ; to the pointer value (but len/cap values still can be). 36 define void @testReadSome() { 37 entry: 38 %s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6) 39 %s.ptr = extractvalue { ptr, i64, i64 } %s, 0 40 %s.len = extractvalue { ptr, i64, i64 } %s, 1 41 %s.cap = extractvalue { ptr, i64, i64 } %s, 2 42 call fastcc void @writeToSlice(ptr %s.ptr, i64 %s.len, i64 %s.cap) 43 %s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0 44 %s.len2 = extractvalue { ptr, i64, i64 } %s, 1 45 %s.cap2 = extractvalue { ptr, i64, i64 } %s, 2 46 call fastcc void @printSlice(ptr %s.ptr2, i64 %s.len2, i64 %s.cap2) 47 ret void 48 }