Skip to content

Commit 89020aa

Browse files
adgrsc
authored andcommitted
[release-branch.go1.1] cmd/gc: avoid passing unevaluated constant expressions to backends.
««« CL 11107044 / 5baf6060648e cmd/gc: avoid passing unevaluated constant expressions to backends. Backends do not exactly expect receiving binary operators with constant operands or use workarounds to move them to register/stack in order to handle them. Fixes #5841. R=golang-dev, daniel.morsing, rsc CC=golang-dev https://golang.org/cl/11107044 »»» Update #5928 R=golang-dev, dave CC=golang-dev https://golang.org/cl/11879044
1 parent b5245b9 commit 89020aa

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cmd/gc/walk.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,13 @@ walkexpr(Node **np, NodeList **init)
13381338
fatal("missing switch %O", n->op);
13391339

13401340
ret:
1341+
// Expressions that are constant at run time but not
1342+
// considered const by the language spec are not turned into
1343+
// constants until walk. For example, if n is y%1 == 0, the
1344+
// walk of y%1 may have replaced it by 0.
1345+
// Check whether n with its updated args is itself now a constant.
1346+
evconst(n);
1347+
13411348
ullmancalc(n);
13421349

13431350
if(debug['w'] && n != N)

test/fixedbugs/issue5841.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// build
2+
3+
// Copyright 2013 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 5841: 8g produces invalid CMPL $0, $0.
8+
// Similar to issue 5002, used to fail at link time.
9+
10+
package main
11+
12+
func main() {
13+
var y int
14+
if y%1 == 0 {
15+
}
16+
}

0 commit comments

Comments
 (0)