Hi Folks, 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. Regards, Neil -- 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 golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5528b76b-c182-4cab-b3a8-ed5216042259%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.