]> Cypherpunks repositories - gostls13.git/commit
cmd/gc: never pass ptr to uninit temp to runtime
authorRuss Cox <rsc@golang.org>
Fri, 28 Mar 2014 15:30:02 +0000 (11:30 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 28 Mar 2014 15:30:02 +0000 (11:30 -0400)
commite150ca9c9aba9b8d8e61d0953ea4b90deef620bc
tree2a11976b2354d69db17584566f8fc29d308b6b41
parentea3353b64c04a12a284fba10f6927e970849a33a
cmd/gc: never pass ptr to uninit temp to runtime

chanrecv now expects a pointer to the data to be filled in.
mapiterinit expects a pointer to the hash iterator to be filled in.
In both cases, the temporary being pointed at changes from
dead to alive during the call. In order to make sure it is
preserved if a garbage collection happens after that transition
but before the call returns, the temp must be marked as live
during the entire call.

But if it is live during the entire call, it needs to be safe for
the garbage collector to scan at the beginning of the call,
before the new data has been filled in. Therefore, it must be
zeroed by the caller, before the call. Do that.

My previous attempt waited to mark it live until after the
call returned, but that's unsafe (see first paragraph);
undo that change in plive.c.

This makes powser2 pass again reliably.

I looked at every call to temp in the compiler.
The vast majority are followed immediately by an
initialization of temp, so those are fine.
The only ones that needed changing were the ones
where the next operation is to pass the address of
the temp to a function call, and there aren't too many.

Maps are exempted from this because mapaccess
returns a pointer to the data and lets the caller make
the copy.

Fixes many builds.

TBR=khr
CC=golang-codereviews
https://golang.org/cl/80700046
src/cmd/gc/plive.c
src/cmd/gc/range.c
src/cmd/gc/select.c
src/cmd/gc/walk.c