• Matthew Dempsky's avatar
    cmd/compile: handle unsafe.Pointer(f()) correctly · c65647d6
    Matthew Dempsky authored
    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: 's avatarKeith Randall <khr@golang.org>
    Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    c65647d6
order.go 34.4 KB