mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/compile: put constant value on node inside parentheses
That's where the unified IR writer expects it. Fixes #73476 Change-Id: Ic22bd8dee5be5991e6d126ae3f6eccb2acdc0b19 Reviewed-on: https://go-review.googlesource.com/c/go/+/667415 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
3672a09a48
commit
67e0681aef
@ -37,6 +37,16 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *syntax.ForStmt, no
|
|||||||
|
|
||||||
if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
|
if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
|
||||||
if t, ok := arrayPtrDeref(under(x.typ)).(*Array); ok {
|
if t, ok := arrayPtrDeref(under(x.typ)).(*Array); ok {
|
||||||
|
for {
|
||||||
|
// Put constant info on the thing inside parentheses.
|
||||||
|
// That's where (*../noder/writer).expr expects it.
|
||||||
|
// See issue 73476.
|
||||||
|
p, ok := rangeVar.(*syntax.ParenExpr)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
rangeVar = p.X
|
||||||
|
}
|
||||||
// Override type of rangeVar to be a constant
|
// Override type of rangeVar to be a constant
|
||||||
// (and thus side-effects will not be computed
|
// (and thus side-effects will not be computed
|
||||||
// by the backend).
|
// by the backend).
|
||||||
|
@ -40,6 +40,16 @@ func (check *Checker) rangeStmt(inner stmtContext, rangeStmt *ast.RangeStmt, noN
|
|||||||
|
|
||||||
if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
|
if isTypes2 && x.mode != invalid && sValue == nil && !check.hasCallOrRecv {
|
||||||
if t, ok := arrayPtrDeref(under(x.typ)).(*Array); ok {
|
if t, ok := arrayPtrDeref(under(x.typ)).(*Array); ok {
|
||||||
|
for {
|
||||||
|
// Put constant info on the thing inside parentheses.
|
||||||
|
// That's where (*../noder/writer).expr expects it.
|
||||||
|
// See issue 73476.
|
||||||
|
p, ok := rangeVar.(*ast.ParenExpr)
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
rangeVar = p.X
|
||||||
|
}
|
||||||
// Override type of rangeVar to be a constant
|
// Override type of rangeVar to be a constant
|
||||||
// (and thus side-effects will not be computed
|
// (and thus side-effects will not be computed
|
||||||
// by the backend).
|
// by the backend).
|
||||||
|
17
test/fixedbugs/issue73476.go
Normal file
17
test/fixedbugs/issue73476.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// run
|
||||||
|
|
||||||
|
// Copyright 2025 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 main
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func f(p *[4]int) {
|
||||||
|
for i := range (*p) { // Note the parentheses! gofmt wants to remove them - don't let it!
|
||||||
|
println(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func main() {
|
||||||
|
f(nil)
|
||||||
|
}
|
4
test/fixedbugs/issue73476.out
Normal file
4
test/fixedbugs/issue73476.out
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
Loading…
x
Reference in New Issue
Block a user