Skip to content

Commit 59d0bae

Browse files
committed
cmd/compile: add test for OPmodify ops clobbering flags
Code fix was in CL 122556. This is a corresponding test case. Fixes #26426 Change-Id: Ib8769f367aed8bead029da0a8d2ddccee1d1dccb Reviewed-on: https://go-review.googlesource.com/124535 Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent f3582de commit 59d0bae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/fixedbugs/issue26426.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
package main
8+
9+
//go:noinline
10+
func f(p *int, v int, q1, q2 *int, r *bool) {
11+
x := *r
12+
if x {
13+
*q1 = 1
14+
}
15+
*p = *p + v // This must clobber flags. Otherwise we keep x in a flags register.
16+
if x {
17+
*q2 = 1
18+
}
19+
}
20+
21+
func main() {
22+
var p int
23+
var q1, q2 int
24+
var b bool
25+
f(&p, 1, &q1, &q2, &b)
26+
if q1 != 0 || q2 != 0 {
27+
panic("bad")
28+
}
29+
}

0 commit comments

Comments
 (0)