Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/compile: expand checkptr to find conversions of smaller types into bigger #34959
Per discussion in golang-dev.
Playground link: https://play.golang.org/p/32lWMkFPvm5.
According to @mdempsky:
Detecting that is not currently supported, but I think there may at least be some cases where we can detect it. (…)
We do this sometimes in
So we'd need to check that the underlying object allocation is large enough. Just having the base type be larger is not in itself an error.
CL 201778 can now detect the invalid conversion here:
It still doesn't detect the original example, but because in that one
One solution would be to make
This CL extends the runtime instrumentation for (*T)(ptr) to also check that the first and last bytes of *(*T)(ptr) are part of the same heap object. Updates #22218. Updates #34959. Change-Id: I2c8063fe1b7fe6e6145e41c5654cb64dd1c9dd41 Reviewed-on: https://go-review.googlesource.com/c/go/+/201778 Run-TryBot: Matthew Dempsky <firstname.lastname@example.org> Reviewed-by: Keith Randall <email@example.com> Reviewed-by: Cuong Manh Le <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com>
Escaping all unsafe.Pointer conversions for -d=checkptr seems like it might be a little too aggressive to enable for -race/-msan mode, since at least some tests are written to expect unsafe.Pointer conversions to not affect escape analysis. So instead only enable that functionality behind -d=checkptr=2. Updates #22218. Updates #34959. Change-Id: I2f0a774ea5961dabec29bc5b8ebe387a1b90d27b Reviewed-on: https://go-review.googlesource.com/c/go/+/201840 Run-TryBot: Matthew Dempsky <firstname.lastname@example.org> Reviewed-by: Brad Fitzpatrick <email@example.com>