aboutsummaryrefslogtreecommitdiff
path: root/test/const2.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-11-24 21:56:47 -0800
committerRuss Cox <rsc@golang.org>2020-11-25 15:47:36 +0000
commit259fd8adbb15f2a44433c7b8b40a35e97992b345 (patch)
treee7f2596897f662b68e03902c63dc6f5eb5e53d05 /test/const2.go
parent18573aea3cc5098c5c27e357e15c507a05de5599 (diff)
downloadgo-259fd8adbb15f2a44433c7b8b40a35e97992b345.tar.gz
go-259fd8adbb15f2a44433c7b8b40a35e97992b345.zip
[dev.regabi] cmd/compile: fix reporting of overflow
In the previous CL, I had incorrectly removed one of the error messages from issue20232.go, because I thought go/constant was just handling it. But actually the compiler was panicking in nodlit, because it didn't handle constant.Unknown. So this CL makes it leave n.Type == nil for unknown constant.Values. While here, also address #42732 by making sure to report an error message when origConst is called with an unknown constant.Value (as can happen when multiplying two floating-point constants overflows). Finally, add OXOR and OBITNOT to the list of operations to report errors about, since they're also constant expressions that can produce a constant with a greater bit length than their operands. Fixes #42732. Change-Id: I4a538fbae9b3ac4c553d7de5625dc0c87d9acce3 Reviewed-on: https://go-review.googlesource.com/c/go/+/272928 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'test/const2.go')
-rw-r--r--test/const2.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/const2.go b/test/const2.go
index 048d0cb9f3..d104a2fa71 100644
--- a/test/const2.go
+++ b/test/const2.go
@@ -19,3 +19,14 @@ const LargeB = LargeA * LargeA * LargeA
const LargeC = LargeB * LargeB * LargeB // GC_ERROR "constant multiplication overflow"
const AlsoLargeA = LargeA << 400 << 400 >> 400 >> 400 // GC_ERROR "constant shift overflow"
+
+// Issue #42732.
+
+const a = 1e+500000000
+const b = a * a // ERROR "constant multiplication overflow"
+const c = b * b
+
+const MaxInt512 = (1<<256 - 1) * (1<<256 + 1)
+const _ = MaxInt512 + 1 // ERROR "constant addition overflow"
+const _ = MaxInt512 ^ -1 // ERROR "constant bitwise XOR overflow"
+const _ = ^MaxInt512 // ERROR "constant bitwise complement overflow"