]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: suppress export of Note field within exported bodies
authorDavid Chase <drchase@google.com>
Thu, 31 Dec 2015 00:47:36 +0000 (19:47 -0500)
committerDavid Chase <drchase@google.com>
Tue, 5 Jan 2016 15:42:12 +0000 (15:42 +0000)
Added a format option to inhibit output of .Note field in
printing, and enabled that option during export.
Added test.

Fixes #13777.

Change-Id: I739f9785eb040f2fecbeb96d5a9ceb8c1ca0f772
Reviewed-on: https://go-review.googlesource.com/18217
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>

src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/internal/obj/fmt.go
test/fixedbugs/issue13777.dir/burnin.go [new file with mode: 0644]
test/fixedbugs/issue13777.dir/main.go [new file with mode: 0644]
test/fixedbugs/issue13777.go [new file with mode: 0644]

index b4182aea62b813a85ef5bc63f5660d934cb579a9..e50cf383d744fd3bd57338d53df3be2fc6b5df6b 100644 (file)
@@ -257,7 +257,7 @@ func dumpexportvar(s *Sym) {
                        }
 
                        // NOTE: The space after %#S here is necessary for ld's export data parser.
-                       exportf("\tfunc %v %v { %v }\n", Sconv(s, obj.FmtSharp), Tconv(t, obj.FmtShort|obj.FmtSharp), Hconv(n.Func.Inl, obj.FmtSharp))
+                       exportf("\tfunc %v %v { %v }\n", Sconv(s, obj.FmtSharp), Tconv(t, obj.FmtShort|obj.FmtSharp), Hconv(n.Func.Inl, obj.FmtSharp|obj.FmtBody))
 
                        reexportdeplist(n.Func.Inl)
                } else {
index 1cbaf17f38c60a877449430d0ef817690f90e168..4da60f4c89513e1bfa680b11d79cc1033369ea66 100644 (file)
@@ -63,6 +63,8 @@ var fmtmode int = FErr
 
 var fmtpkgpfx int // %uT stickyness
 
+var fmtbody bool
+
 //
 // E.g. for %S:        %+S %#S %-S     print an identifier properly qualified for debug/export/internal mode.
 //
@@ -87,8 +89,9 @@ var fmtpkgpfx int // %uT stickyness
 //     %-uT            type identifiers with package name instead of prefix (typesym, dcommontype, typehash)
 //
 
-func setfmode(flags *int) int {
-       fm := fmtmode
+func setfmode(flags *int) (fm int, fb bool) {
+       fm = fmtmode
+       fb = fmtbody
        if *flags&obj.FmtSign != 0 {
                fmtmode = FDbg
        } else if *flags&obj.FmtSharp != 0 {
@@ -97,8 +100,12 @@ func setfmode(flags *int) int {
                fmtmode = FTypeId
        }
 
-       *flags &^= (obj.FmtSharp | obj.FmtLeft | obj.FmtSign)
-       return fm
+       if *flags&obj.FmtBody != 0 {
+               fmtbody = true
+       }
+
+       *flags &^= (obj.FmtSharp | obj.FmtLeft | obj.FmtSign | obj.FmtBody)
+       return
 }
 
 // Fmt "%L": Linenumbers
@@ -741,7 +748,7 @@ func typefmt(t *Type, flag int) string {
                if name != "" {
                        str = name + " " + typ
                }
-               if flag&obj.FmtShort == 0 && t.Note != nil {
+               if flag&obj.FmtShort == 0 && !fmtbody && t.Note != nil {
                        str += " " + strconv.Quote(*t.Note)
                }
                return str
@@ -1599,10 +1606,11 @@ func Sconv(s *Sym, flag int) string {
        }
 
        sf := flag
-       sm := setfmode(&flag)
+       sm, sb := setfmode(&flag)
        str := symfmt(s, flag)
        flag = sf
        fmtmode = sm
+       fmtbody = sb
        return str
 }
 
@@ -1625,7 +1633,7 @@ func Tconv(t *Type, flag int) string {
 
        t.Trecur++
        sf := flag
-       sm := setfmode(&flag)
+       sm, sb := setfmode(&flag)
 
        if fmtmode == FTypeId && (sf&obj.FmtUnsigned != 0) {
                fmtpkgpfx++
@@ -1641,6 +1649,7 @@ func Tconv(t *Type, flag int) string {
        }
 
        flag = sf
+       fmtbody = sb
        fmtmode = sm
        t.Trecur--
        return str
@@ -1658,7 +1667,7 @@ func Nconv(n *Node, flag int) string {
                return "<N>"
        }
        sf := flag
-       sm := setfmode(&flag)
+       sm, sb := setfmode(&flag)
 
        var str string
        switch fmtmode {
@@ -1675,6 +1684,7 @@ func Nconv(n *Node, flag int) string {
        }
 
        flag = sf
+       fmtbody = sb
        fmtmode = sm
        return str
 }
@@ -1691,7 +1701,7 @@ func Hconv(l *NodeList, flag int) string {
        }
 
        sf := flag
-       sm := setfmode(&flag)
+       sm, sb := setfmode(&flag)
        sep := "; "
        if fmtmode == FDbg {
                sep = "\n"
@@ -1708,6 +1718,7 @@ func Hconv(l *NodeList, flag int) string {
        }
 
        flag = sf
+       fmtbody = sb
        fmtmode = sm
        return buf.String()
 }
index a6a97d55b5294486f90c998ddb8f08f1a4895e2b..f98bc6dc170d5326ba6c925fcb95c46895bfe86b 100644 (file)
@@ -24,4 +24,5 @@ const (
        FmtLong
        FmtComma
        FmtByte
+       FmtBody // for printing export bodies
 )
diff --git a/test/fixedbugs/issue13777.dir/burnin.go b/test/fixedbugs/issue13777.dir/burnin.go
new file mode 100644 (file)
index 0000000..5125639
--- /dev/null
@@ -0,0 +1,19 @@
+package burnin
+
+type sendCmdFunc func(string)
+
+func sendCommand(c string) {}
+
+func NewSomething() {
+       // This works...
+       // var sendCmd sendCmdFunc
+       // sendCmd = sendCommand
+
+       // So does this...
+       //sendCmd := sendCmdFunc(sendCommand)
+
+       // This fails...
+       sendCmd := sendCommand
+
+       _ = sendCmd
+}
diff --git a/test/fixedbugs/issue13777.dir/main.go b/test/fixedbugs/issue13777.dir/main.go
new file mode 100644 (file)
index 0000000..2512b93
--- /dev/null
@@ -0,0 +1,11 @@
+// build
+
+package main
+
+import (
+       x "./burnin"
+)
+
+func main() {
+       x.NewSomething()
+}
diff --git a/test/fixedbugs/issue13777.go b/test/fixedbugs/issue13777.go
new file mode 100644 (file)
index 0000000..8f83c13
--- /dev/null
@@ -0,0 +1,7 @@
+// rundir
+
+// Copyright 2015 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