]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: handle unsafe.Pointer(f()) correctly
authorMatthew Dempsky <mdempsky@google.com>
Tue, 19 Apr 2016 22:02:06 +0000 (15:02 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 18 May 2016 14:01:22 +0000 (14:01 +0000)
commitc65647d6204531e93c19ea2dba01ff13d1b8ef31
treec74f441438a59ec6f08640a3219e018d85460497
parentc6a5b3602a87b2d1321ad11aa64b7f588bbb683b
cmd/compile: handle unsafe.Pointer(f()) correctly

Previously statements like

    f(unsafe.Pointer(g()), int(h()))

would be reordered into a sequence of statements like

    autotmp_g := g()
    autotmp_h := h()
    f(unsafe.Pointer(autotmp_g), int(autotmp_h))

which can leave g's temporary value on the stack as a uintptr, rather
than an unsafe.Pointer. Instead, recognize uintptr-to-unsafe.Pointer
conversions when reordering function calls to instead produce:

    autotmp_g := unsafe.Pointer(g())
    autotmp_h := h()
    f(autotmp_g, int(autotmp_h))

Fixes #15329.

Change-Id: I2cdbd89d233d0d5c94791513a9fd5fd958d11ed5
Reviewed-on: https://go-review.googlesource.com/22273
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/gc/order.go
test/fixedbugs/issue15329.go [new file with mode: 0644]