Commit d3f6d11d authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: fix typechecking of untyped boolean expressions

Previously, if we typechecked a statement like

    var x bool = p1.f == p2.f && p1.g == p2.g

we would correctly update the '&&' node's type from 'untyped bool' to
'bool', but the '==' nodes would stay 'untyped bool'. This is
inconsistent, and caused consistency checks during walk to fail.

This CL doesn't pass toolstash because it seems to slightly affect the
register allocator's heuristics. (Presumably 'untyped bool's were
previously making it all the way through SSA?)

Fixes #23414.

Change-Id: Ia85f8cfc69b5ba35dfeb157f4edf57612ecc3285
Reviewed-on: https://go-review.googlesource.com/94022
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarRobert Griesemer <gri@golang.org>
parent bcb563f4
......@@ -232,11 +232,17 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
switch n.Op {
default:
if n.Type == types.Idealbool {
if t.IsBoolean() {
n.Type = t
} else {
n.Type = types.Types[TBOOL]
if !t.IsBoolean() {
t = types.Types[TBOOL]
}
switch n.Op {
case ONOT:
n.Left = convlit(n.Left, t)
case OANDAND, OOROR:
n.Left = convlit(n.Left, t)
n.Right = convlit(n.Right, t)
}
n.Type = t
}
if n.Type.Etype == TIDEAL {
......
// compile
// Copyright 2018 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.
package p
var x struct{}
func f() bool {
return x == x && x == x
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment