mirror of
https://github.com/golang/go
synced 2024-11-23 14:20:05 -07:00
cmd/compile: detect invalid NIH conversions within unified IR
Unified IR currently relies on typecheck to diagnose invalid //go:notinheap conversions, which prevents removing all of its (otherwise) dead error-reporting code. This CL updates the unified IR reader to instead proactively diagnose these invalid conversions. This logic can be removed again once #46731 is implemented, but in the mean time it allows progress on #51691. Updates #46731. Updates #51691. Change-Id: Ifae81aaad770209ec7a67bc10b55660f291e403e Reviewed-on: https://go-review.googlesource.com/c/go/+/392917 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
c0158b6a00
commit
a1bf50eefe
@ -1676,6 +1676,20 @@ func (r *reader) expr() (res ir.Node) {
|
||||
typ := r.typ()
|
||||
pos := r.pos()
|
||||
x := r.expr()
|
||||
|
||||
// TODO(mdempsky): Stop constructing expressions of untyped type.
|
||||
x = typecheck.DefaultLit(x, typ)
|
||||
|
||||
if op, why := typecheck.Convertop(x.Op() == ir.OLITERAL, x.Type(), typ); op == ir.OXXX {
|
||||
// types2 ensured that x is convertable to typ under standard Go
|
||||
// semantics, but cmd/compile also disallows some conversions
|
||||
// involving //go:notinheap.
|
||||
//
|
||||
// TODO(mdempsky): This can be removed after #46731 is implemented.
|
||||
base.ErrorfAt(pos, "cannot convert %L to type %v%v", x, typ, why)
|
||||
base.ErrorExit() // harsh, but prevents constructing invalid IR
|
||||
}
|
||||
|
||||
return typecheck.Expr(ir.NewConvExpr(pos, ir.OCONV, typ, x))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user