]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix internal error on complex comparison
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>
Mon, 24 Jun 2019 07:23:38 +0000 (14:23 +0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 29 Aug 2019 18:24:31 +0000 (18:24 +0000)
Complex type is the only TIDEAL that lack of support for all comparison
operators. When rewriting constant comparison into literal node, that
missing cause compiler raise an internal error.

Checking the operator is available for complex type before that fix the
problem.

We can make this check works more generally if there's more type lack of
supporting all comparison operators added, but it does not seem to be
happened, so just check explicitly for complex only.

Fixes #32723

Change-Id: I4938b1bdcbcdae9a9d87436024984bd2ab12995e
Reviewed-on: https://go-review.googlesource.com/c/go/+/183459
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue32723.go [new file with mode: 0644]

index 5e5d692824d9bf59941bf17604610faf45008b18..03c5528c3d1a2463d4aba892a2f19c0ab05a2189 100644 (file)
@@ -763,6 +763,13 @@ func typecheck1(n *Node, top int) (res *Node) {
 
                t = l.Type
                if iscmp[n.Op] {
+                       // TIDEAL includes complex constant, but only OEQ and ONE are defined for complex,
+                       // so check that the n.op is available for complex  here before doing evconst.
+                       if !okfor[n.Op][TCOMPLEX128] && (Isconst(l, CTCPLX) || Isconst(r, CTCPLX)) {
+                               yyerror("invalid operation: %v (operator %v not defined on untyped complex)", n, n.Op)
+                               n.Type = nil
+                               return n
+                       }
                        evconst(n)
                        t = types.Idealbool
                        if n.Op != OLITERAL {
diff --git a/test/fixedbugs/issue32723.go b/test/fixedbugs/issue32723.go
new file mode 100644 (file)
index 0000000..7d9e403
--- /dev/null
@@ -0,0 +1,22 @@
+// errorcheck
+
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Complex literal comparison
+
+package p
+
+const x = 1i
+const y = 1i < 2i // ERROR "invalid operation: .*not defined on untyped complex"
+const z = x < 2i  // ERROR "invalid operation: .*not defined on untyped complex"
+
+func f() {
+       _ = 1i < 2i // ERROR "invalid operation: .*not defined on untyped complex"
+       _ = 1i < 2  // ERROR "invalid operation: .*not defined on untyped complex"
+       _ = 1 < 2i  // ERROR "invalid operation: .*not defined on untyped complex"
+
+       c := 1i
+       _ = c < 2i // ERROR "invalid operation: .*not defined on complex128"
+}