Skip to content

Commit 48c7973

Browse files
committed
test: add test for gccgo bug #26495
Gccgo produced incorrect order of evaluation for expressions involving &&, || subexpressions. The fix is CL 125299. Updates #26495. Change-Id: I18d873281709f3160b3e09f0b2e46f5c120e1cab Reviewed-on: https://go-review.googlesource.com/125301 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 8898097 commit 48c7973

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/fixedbugs/issue26495.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// run
2+
3+
// Copyright 2018 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 26495: gccgo produces incorrect order of evaluation
8+
// for expressions involving &&, || subexpressions.
9+
10+
package main
11+
12+
var i int
13+
14+
func checkorder(order int) {
15+
if i != order {
16+
panic("FAIL: wrong evaluation order")
17+
}
18+
i++
19+
}
20+
21+
func A() bool { checkorder(1); return true }
22+
func B() bool { checkorder(2); return true }
23+
func C() bool { checkorder(5); return false }
24+
func D() bool { panic("FAIL: D should not be called") }
25+
func E() int { checkorder(3); return 0 }
26+
func F() int { checkorder(0); return 0 }
27+
func G(bool) int { checkorder(9); return 0 }
28+
func H(int, bool, int) int { checkorder(7); return 0 }
29+
func I(int) bool { checkorder(8); return true }
30+
func J() int { checkorder(4); return 0 }
31+
func K() int { checkorder(6); return 0 }
32+
func L() int { checkorder(10); return 0 }
33+
34+
func main() {
35+
_ = F() + G(A() && B() && I(E()+H(J(), C() && D(), K()))) + L()
36+
}

0 commit comments

Comments
 (0)