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: fatal error: out of memory on reslice with negative index #28797
What version of Go are you using (
@randall77, wouldn't mind your opinion on this.
and we generate code based on that assumption, using an unsigned comparison -- this will fail if AX below happens to be a negative number (and of course it is).
The source code is
I think our two choices for fixing this are either to remove the assumption from prove, or in ssa.go to catch the case where arg1 of OpIsSliceInBounds might be negative and explicitly check for that.
I favor the explicit extra check, since as it happens we compile this to code that would not do the correct thing if fed a negative number. Here's another test case making the trick more explicit:
One possibility for improving code for the unoptimized case is to only insert the extra explicit test when phase "prove" is enabled.
Turns out this makes the fix for 28797 unnecessary, because this order ensures that the RHS of IsSliceInBounds ops are always nonnegative. The real reason for this change is that it also makes dealing with <0 values easier for reporting values in bounds check panics (issue #30116). Makes cmd/go negligibly smaller. Update #28797 Change-Id: I1f25ba6d2b3b3d4a72df3105828aa0a4b629ce85 Reviewed-on: https://go-review.googlesource.com/c/go/+/166377 Run-TryBot: Keith Randall <firstname.lastname@example.org> Reviewed-by: Brad Fitzpatrick <email@example.com> TryBot-Result: Gobot Gobot <firstname.lastname@example.org>