Sorry for the delay in responding. Filed as https://github.com/golang/go/issues/32579.
On Tue, Jun 11, 2019 at 1:21 AM Ian Lance Taylor <[email protected]> wrote: > On Mon, Jun 10, 2019 at 9:14 PM Neil Schellenberger > <[email protected]> wrote: > > > > When upgrading our build container from 1.11.10 to 1.12.5, some of our > tests failed in a surprising way. I've boiled down the issue to this short > example code fragment. > > > > package main > > > > // #include <string.h> > > // struct S { unsigned char data[18]; }; > > import "C" > > import "unsafe" > > > > func main() { > > var array [5]C.struct_S > > for i := range array { > > C.memset(unsafe.Pointer(&array[i].data[0]), 0xff, C.sizeof_struct_S) > > } > > for i := range array { > > for j := range array[i].data { > > if array[i].data[j] != C.uchar(0xff) { > > panic("oops") > > } > > } > > } > > } > > > > Under 1.11 this runs to completion; under 1.12 it panics. > > > > Debugging and instrumenting shows that the problem is the first argument > to memset is not what one would expect when run under 1.12. (The address > of a heap temporary copy rather than the original perhaps?) > > > > Strangely, either parenthesising the argument expression to the address > operand ("&(array[i].data[0])") or removing the final index expression > ("&array[i].data") "fixes" the problem. > > > > I've spelunked through the AST (identical under both); the liveness and > escape analysis (different); the parse tree (different); and the go asm > (different). Frankly, my gc-fu is very weak and I don't really know what > I'm looking for. > > > > I assume that the root cause is that we were violating some sort of > liveness or escape policy, but I can't figure out what it would be (or why > minor syntactic changes "fix" things). I'd be quite curious to know. > > > > The workaround in the real code is simple, so this isn't a huge issue, > just a a bit of a mystery. > > It's a bug. Would you mind opening an issue with this test case at > https://golang.org/issue? Thanks. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAM3gH5_3By%2B37NxrvarWqTw3h-aAuC4owyJnELhpE%3DDcQJhMLA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
