Skip to content

Commit

Permalink
still escaple pointer when only noescape exists.
Browse files Browse the repository at this point in the history
Signed-off-by: doujiang24 <doujiang24@gmail.com>
  • Loading branch information
doujiang24 committed Jul 17, 2024
1 parent 4098234 commit 8dc86e0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/cmd/cgo/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ int add(int x, int y) {
// escape vs noescape
#cgo noescape handleGoStringPointerNoescape
#cgo nocallback handleGoStringPointerNoescape
void handleGoStringPointerNoescape(void *s) {}
void handleGoStringPointerEscape(void *s) {}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cgo/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,11 @@ func (p *Package) writeDefsFunc(fgo2 io.Writer, n *Name, callsMalloc *bool) {
fmt.Fprintf(fgo2, "\t_Cgo_no_callback(false)\n")
}

// use _Cgo_keepalive instead of _Cgo_use when noescape exist,
// use _Cgo_keepalive instead of _Cgo_use when noescape & nocallback exist,
// so that the compiler won't force to escape them to heap.
// instead, make the compiler keep them alive by using _Cgo_keepalive.
touchFunc := "_Cgo_use"
if p.noEscapes[n.C] {
if p.noEscapes[n.C] && p.noCallbacks[n.C] {
touchFunc = "_Cgo_keepalive"
}
fmt.Fprintf(fgo2, "\tif _Cgo_always_false {\n")
Expand Down
1 change: 1 addition & 0 deletions src/runtime/testdata/testprogcgo/cgonoescape.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package main

/*
#cgo noescape runCWithNoEscape
#cgo nocallback runCWithNoEscape
void runCWithNoEscape(void *p) {
}
Expand Down

0 comments on commit 8dc86e0

Please sign in to comment.