diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2022-03-15 22:25:36 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2022-03-16 18:30:48 +0000 |
| commit | a1bf50eefe35087ac7151116558f4c19095b8473 (patch) | |
| tree | 7a590b817ee4378d201bd7fee409145c32db955c /src/cmd/compile/internal/noder/reader.go | |
| parent | c0158b6a00eaecbd28ded0f66e65b9985f6db078 (diff) | |
| download | go-a1bf50eefe35087ac7151116558f4c19095b8473.tar.xz | |
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>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/reader.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 73e4ddbbed..dd3bb1523e 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -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)) } } |
