File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed
Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -154,9 +154,18 @@ func valueEscapesAt(value llvm.Value) llvm.Value {
154154 return use
155155 }
156156 case llvm .Call :
157- if ! hasFlag (use , value , "nocapture" ) {
158- return use
157+ if hasFlag (use , value , "nocapture" ) {
158+ break
159+ }
160+ // If built-in append function escapes its first argument if and
161+ // only if the return value escapes.
162+ if fn := use .CalledValue (); ! fn .IsAFunction ().IsNil () && fn .Name () == "runtime.sliceAppend" {
163+ if at := valueEscapesAt (use ); ! at .IsNil () {
164+ return at
165+ }
166+ break
159167 }
168+ return use
160169 case llvm .ICmp :
161170 // Comparing pointers don't let the pointer escape.
162171 // This is often a compiler-inserted nil check.
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ func main() {
2323 s4 := make ([]byte , 300 ) // OUT: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
2424 readByteSlice (s4 )
2525
26- s5 := make ([]int , 4 ) // OUT: object allocated on the heap: escapes at line 27
26+ s5 := make ([]int , 4 )
2727 _ = append (s5 , 5 )
2828
2929 s6 := make ([]int , 3 )
You can’t perform that action at this time.
0 commit comments