cmd/compile: CMOV optimization allows GC to see invalid pointer #56990
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
This program when run on the playground, go1.18, go1.19, or tip, crashes when the Go runtime finds an invalid pointer on the stack.
@cherrymui determined that this has to do with a conditional move optimization. We have code like:
Which gets rewritten to a conditional move:
Unfortunately, we can't compute
&q.f
before we've checked ifq
is nil, because if it is nil,&q.f
is an invalid pointer (iff
's offset is nonzero but small).Normally this is not a problem because the
tmp
variable above immediately dies, and is thus not live across any safepoint. However, if later there is another&q.f
computation, those two computations are CSEd, causingtmp
to be used at both use points. That will extendtmp
's lifetime, possibly across a call.The text was updated successfully, but these errors were encountered: