]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] cmd/gc: fix inlining bug with receive operator.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Fri, 21 Sep 2012 19:54:22 +0000 (05:54 +1000)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Fri, 21 Sep 2012 19:54:22 +0000 (05:54 +1000)
««« backport d872ed20fccb
cmd/gc: fix inlining bug with receive operator.

The receive operator was given incorrect precedence
resulting in incorrect deletion of parentheses.

Fixes #3843.

R=rsc
CC=golang-dev, remy
https://golang.org/cl/6442049

»»»

src/cmd/gc/fmt.c
test/fixedbugs/bug448.dir/pkg1.go [new file with mode: 0644]
test/fixedbugs/bug448.dir/pkg2.go [new file with mode: 0644]
test/fixedbugs/bug448.go [new file with mode: 0644]

index 5672c00103ed3cc41adbba9af49ed55138d54f0a..3698833a626e1bd91c4d69afed4c6a6817badc6e 100644 (file)
@@ -962,7 +962,6 @@ static int opprec[] = {
        [OPAREN] = 8,
        [OPRINTN] = 8,
        [OPRINT] = 8,
-       [ORECV] = 8,
        [ORUNESTR] = 8,
        [OSTRARRAYBYTE] = 8,
        [OSTRARRAYRUNE] = 8,
@@ -994,6 +993,7 @@ static int opprec[] = {
        [OMINUS] = 7,
        [OADDR] = 7,
        [OIND] = 7,
+       [ORECV] = 7,
 
        [OMUL] = 6,
        [ODIV] = 6,
diff --git a/test/fixedbugs/bug448.dir/pkg1.go b/test/fixedbugs/bug448.dir/pkg1.go
new file mode 100644 (file)
index 0000000..032e5d9
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2012 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 pkg1
+
+var x = make(chan interface{})
+
+func Do() int {
+       return (<-x).(int)
+}
diff --git a/test/fixedbugs/bug448.dir/pkg2.go b/test/fixedbugs/bug448.dir/pkg2.go
new file mode 100644 (file)
index 0000000..5c78c7d
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2012 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.
+
+// Issue 3843: inlining bug due to wrong receive operator precedence.
+
+package pkg2
+
+import "./pkg1"
+
+func F() {
+       pkg1.Do()
+}
+
diff --git a/test/fixedbugs/bug448.go b/test/fixedbugs/bug448.go
new file mode 100644 (file)
index 0000000..242f599
--- /dev/null
@@ -0,0 +1,7 @@
+// compiledir
+
+// Copyright 2012 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 ignored