mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
transform: fix bug in StringToBytes optimization pass
Previously, this pass would convert any read-only use of a runtime.stringToBytes call to use the original string buffer instead. This is incorrect: if there are any writes to the resulting buffer, none of the slice buffer pointers can be converted to use the original read-only string buffer. This commit fixes that bug and adds a test to prove the new (correct) behavior.
This commit is contained in:
committed by
Ron Evans
parent
081d2e58c6
commit
a896f7f218
Vendored
+16
@@ -30,3 +30,19 @@ entry:
|
||||
call fastcc void @writeToSlice(ptr %1, i64 %2, i64 %3)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Test that pointer values are never propagated if there is even a single write
|
||||
; to the pointer value (but len/cap values still can be).
|
||||
define void @testReadSome() {
|
||||
entry:
|
||||
%s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6)
|
||||
%s.ptr = extractvalue { ptr, i64, i64 } %s, 0
|
||||
%s.len = extractvalue { ptr, i64, i64 } %s, 1
|
||||
%s.cap = extractvalue { ptr, i64, i64 } %s, 2
|
||||
call fastcc void @writeToSlice(ptr %s.ptr, i64 %s.len, i64 %s.cap)
|
||||
%s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0
|
||||
%s.len2 = extractvalue { ptr, i64, i64 } %s, 1
|
||||
%s.cap2 = extractvalue { ptr, i64, i64 } %s, 2
|
||||
call fastcc void @printSlice(ptr %s.ptr2, i64 %s.len2, i64 %s.cap2)
|
||||
ret void
|
||||
}
|
||||
|
||||
+10
@@ -22,3 +22,13 @@ entry:
|
||||
call fastcc void @writeToSlice(ptr %1, i64 6, i64 6)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @testReadSome() {
|
||||
entry:
|
||||
%s = call fastcc { ptr, i64, i64 } @runtime.stringToBytes(ptr @str, i64 6)
|
||||
%s.ptr = extractvalue { ptr, i64, i64 } %s, 0
|
||||
call fastcc void @writeToSlice(ptr %s.ptr, i64 6, i64 6)
|
||||
%s.ptr2 = extractvalue { ptr, i64, i64 } %s, 0
|
||||
call fastcc void @printSlice(ptr %s.ptr2, i64 6, i64 6)
|
||||
ret void
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user