Skip to content

cmd/compile: new escape analysis implementation doesn't heap-allocate pointer #33662

@dsnet

Description

@dsnet

Apache Beam has a function as follows:

func LoadFunction(ptr uintptr, t reflect.Type) interface{} {
	v := reflect.New(t).Elem()
	*(*uintptr)(unsafe.Pointer(v.Addr().Pointer())) = (uintptr)(unsafe.Pointer(&ptr))
	return v.Interface()
}

When compiled on Go1.12 with -gcflags=-m, we see:

functions.go:43: &ptr escapes to heap

When compiled on Go1.13 with -gcflags=-m, the fact that &ptr escapes is no longer true. The effect of this change is a subtle memory corruption where since &ptr now points to the heap, rather than a copy of the value on the stack.

Git bisect reports that the issue is due to CL/170448, which seems to suggest that this breakage is intentional. The fix the Beam code is relatively straight forward by manually allocating ptr on the heap.

I'm filing an issue to confirm that this is an expected regression.

\cc @mdempsky @dr2chase

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.SoonThis needs action soon. (recent regressions, service outages, unusual time-sensitive situations)release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions