Skip to content

Commit

Permalink
cmd/compile: fixing writebarrier.go for -G=3
Browse files Browse the repository at this point in the history
This is caused by some nodes didn't carry the real line number.
Noder1 wraps these node with ir.ParenExpr. To fix this issue,
wraps this node like what noder1 does.

Change-Id: I212cad09b93b8bf1a7adfad416d229d15711918a
Reviewed-on: https://go-review.googlesource.com/c/go/+/349769
Reviewed-by: Matthew Dempsky <[email protected]>
Run-TryBot: Matthew Dempsky <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Trust: Keith Randall <[email protected]>
  • Loading branch information
wdvxdr1123 authored and mdempsky committed Sep 16, 2021
1 parent bcdc61d commit d09e09b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/cmd/compile/internal/noder/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
} else {
key = g.expr(elem.Key)
}
exprs[i] = ir.NewKeyExpr(g.pos(elem), key, g.expr(elem.Value))
value := wrapname(g.pos(elem.Value), g.expr(elem.Value))
exprs[i] = ir.NewKeyExpr(g.pos(elem), key, value)
default:
exprs[i] = g.expr(elem)
exprs[i] = wrapname(g.pos(elem), g.expr(elem))
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/cmd/compile/internal/noder/noder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ func (p *noder) mkname(name *syntax.Name) ir.Node {
return mkname(p.name(name))
}

func (p *noder) wrapname(n syntax.Node, x ir.Node) ir.Node {
func wrapname(pos src.XPos, x ir.Node) ir.Node {
// These nodes do not carry line numbers.
// Introduce a wrapper node to give them the correct line.
switch x.Op() {
Expand All @@ -1547,13 +1547,17 @@ func (p *noder) wrapname(n syntax.Node, x ir.Node) ir.Node {
}
fallthrough
case ir.ONAME, ir.ONONAME, ir.OPACK:
p := ir.NewParenExpr(p.pos(n), x)
p := ir.NewParenExpr(pos, x)
p.SetImplicit(true)
return p
}
return x
}

func (p *noder) wrapname(n syntax.Node, x ir.Node) ir.Node {
return wrapname(p.pos(n), x)
}

func (p *noder) setlineno(n syntax.Node) {
if n != nil {
base.Pos = p.pos(n)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/noder/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (g *irgen) stmt(stmt syntax.Stmt) ir.Node {
case *syntax.BlockStmt:
return ir.NewBlockStmt(g.pos(stmt), g.blockStmt(stmt))
case *syntax.ExprStmt:
return g.expr(stmt.X)
return wrapname(g.pos(stmt.X), g.expr(stmt.X))
case *syntax.SendStmt:
n := ir.NewSendStmt(g.pos(stmt), g.expr(stmt.Chan), g.expr(stmt.Value))
if n.Chan.Type().HasTParam() || n.Value.Type().HasTParam() {
Expand Down
4 changes: 4 additions & 0 deletions src/cmd/compile/internal/noder/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ func assignconvfn(n ir.Node, t *types.Type) ir.Node {
return n
}

if n.Op() == ir.OPAREN {
n = n.(*ir.ParenExpr).X
}

if types.IdenticalStrict(n.Type(), t) {
return n
}
Expand Down
2 changes: 0 additions & 2 deletions test/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,8 +2184,6 @@ var types2Failures32Bit = setOf(
)

var g3Failures = setOf(
"writebarrier.go", // correct diagnostics, but different lines (probably irgen's fault)

"typeparam/nested.go", // -G=3 doesn't support function-local types with generics
)

Expand Down

0 comments on commit d09e09b

Please sign in to comment.