From: David Chase Date: Thu, 31 Dec 2015 00:47:36 +0000 (-0500) Subject: cmd/compile: suppress export of Note field within exported bodies X-Git-Tag: go1.6beta2~155 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ab5d2bf92f04ea56c560536e03787a9a111eac25;p=gostls13.git cmd/compile: suppress export of Note field within exported bodies 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 Run-TryBot: David Chase --- diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go index b4182aea62..e50cf383d7 100644 --- a/src/cmd/compile/internal/gc/export.go +++ b/src/cmd/compile/internal/gc/export.go @@ -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 { diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 1cbaf17f38..4da60f4c89 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -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 "" } 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() } diff --git a/src/cmd/internal/obj/fmt.go b/src/cmd/internal/obj/fmt.go index a6a97d55b5..f98bc6dc17 100644 --- a/src/cmd/internal/obj/fmt.go +++ b/src/cmd/internal/obj/fmt.go @@ -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 index 0000000000..512563975e --- /dev/null +++ b/test/fixedbugs/issue13777.dir/burnin.go @@ -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 index 0000000000..2512b93a81 --- /dev/null +++ b/test/fixedbugs/issue13777.dir/main.go @@ -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 index 0000000000..8f83c13ab9 --- /dev/null +++ b/test/fixedbugs/issue13777.go @@ -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