Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
gccgo: dereference of nil pointer to zero-width type does not panic #31151
The Go spec says "For an operand x of pointer type *T, the pointer indirection *x denotes the variable of type T pointed to by x. If x is nil, an attempt to evaluate *x will cause a run-time panic."
This program correctly panics with cmd/compile, but does not with gccgo 8.0.0:
The problem seems not specific to zero-sized type.
This also does not panic. I think as long as the type is not big (>4096 bytes), if the backend somehow optimizes the dereference away, it will not panic.
Adjust the dummy use function to a real use. As suggested by the println calls in the test, nilptr2.go supposes to check that a used nil pointer dereference panics. This use function is not real enough so an optimized compiler such as gccgo could eliminate the call. The spec requires that even a dummy use would cause a panic. Unfortunately, due to #31151 this is not true for gccgo at -O1 or above. Change-Id: Ie07c8a5969ab94dad82d4f7cfec30597c25b7c46 Reviewed-on: https://go-review.googlesource.com/c/go/+/176579 Run-TryBot: Cherry Zhang <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Ian Lance Taylor <firstname.lastname@example.org> Reviewed-by: Brad Fitzpatrick <email@example.com>