Commit ab5d2bf9 authored by David Chase's avatar David Chase

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/18217Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
Run-TryBot: David Chase <drchase@google.com>
parent d731315c
...@@ -257,7 +257,7 @@ func dumpexportvar(s *Sym) { ...@@ -257,7 +257,7 @@ func dumpexportvar(s *Sym) {
} }
// NOTE: The space after %#S here is necessary for ld's export data parser. // 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) reexportdeplist(n.Func.Inl)
} else { } else {
......
...@@ -63,6 +63,8 @@ var fmtmode int = FErr ...@@ -63,6 +63,8 @@ var fmtmode int = FErr
var fmtpkgpfx int // %uT stickyness 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. // 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 ...@@ -87,8 +89,9 @@ var fmtpkgpfx int // %uT stickyness
// %-uT type identifiers with package name instead of prefix (typesym, dcommontype, typehash) // %-uT type identifiers with package name instead of prefix (typesym, dcommontype, typehash)
// //
func setfmode(flags *int) int { func setfmode(flags *int) (fm int, fb bool) {
fm := fmtmode fm = fmtmode
fb = fmtbody
if *flags&obj.FmtSign != 0 { if *flags&obj.FmtSign != 0 {
fmtmode = FDbg fmtmode = FDbg
} else if *flags&obj.FmtSharp != 0 { } else if *flags&obj.FmtSharp != 0 {
...@@ -97,8 +100,12 @@ func setfmode(flags *int) int { ...@@ -97,8 +100,12 @@ func setfmode(flags *int) int {
fmtmode = FTypeId fmtmode = FTypeId
} }
*flags &^= (obj.FmtSharp | obj.FmtLeft | obj.FmtSign) if *flags&obj.FmtBody != 0 {
return fm fmtbody = true
}
*flags &^= (obj.FmtSharp | obj.FmtLeft | obj.FmtSign | obj.FmtBody)
return
} }
// Fmt "%L": Linenumbers // Fmt "%L": Linenumbers
...@@ -741,7 +748,7 @@ func typefmt(t *Type, flag int) string { ...@@ -741,7 +748,7 @@ func typefmt(t *Type, flag int) string {
if name != "" { if name != "" {
str = name + " " + typ 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) str += " " + strconv.Quote(*t.Note)
} }
return str return str
...@@ -1599,10 +1606,11 @@ func Sconv(s *Sym, flag int) string { ...@@ -1599,10 +1606,11 @@ func Sconv(s *Sym, flag int) string {
} }
sf := flag sf := flag
sm := setfmode(&flag) sm, sb := setfmode(&flag)
str := symfmt(s, flag) str := symfmt(s, flag)
flag = sf flag = sf
fmtmode = sm fmtmode = sm
fmtbody = sb
return str return str
} }
...@@ -1625,7 +1633,7 @@ func Tconv(t *Type, flag int) string { ...@@ -1625,7 +1633,7 @@ func Tconv(t *Type, flag int) string {
t.Trecur++ t.Trecur++
sf := flag sf := flag
sm := setfmode(&flag) sm, sb := setfmode(&flag)
if fmtmode == FTypeId && (sf&obj.FmtUnsigned != 0) { if fmtmode == FTypeId && (sf&obj.FmtUnsigned != 0) {
fmtpkgpfx++ fmtpkgpfx++
...@@ -1641,6 +1649,7 @@ func Tconv(t *Type, flag int) string { ...@@ -1641,6 +1649,7 @@ func Tconv(t *Type, flag int) string {
} }
flag = sf flag = sf
fmtbody = sb
fmtmode = sm fmtmode = sm
t.Trecur-- t.Trecur--
return str return str
...@@ -1658,7 +1667,7 @@ func Nconv(n *Node, flag int) string { ...@@ -1658,7 +1667,7 @@ func Nconv(n *Node, flag int) string {
return "<N>" return "<N>"
} }
sf := flag sf := flag
sm := setfmode(&flag) sm, sb := setfmode(&flag)
var str string var str string
switch fmtmode { switch fmtmode {
...@@ -1675,6 +1684,7 @@ func Nconv(n *Node, flag int) string { ...@@ -1675,6 +1684,7 @@ func Nconv(n *Node, flag int) string {
} }
flag = sf flag = sf
fmtbody = sb
fmtmode = sm fmtmode = sm
return str return str
} }
...@@ -1691,7 +1701,7 @@ func Hconv(l *NodeList, flag int) string { ...@@ -1691,7 +1701,7 @@ func Hconv(l *NodeList, flag int) string {
} }
sf := flag sf := flag
sm := setfmode(&flag) sm, sb := setfmode(&flag)
sep := "; " sep := "; "
if fmtmode == FDbg { if fmtmode == FDbg {
sep = "\n" sep = "\n"
...@@ -1708,6 +1718,7 @@ func Hconv(l *NodeList, flag int) string { ...@@ -1708,6 +1718,7 @@ func Hconv(l *NodeList, flag int) string {
} }
flag = sf flag = sf
fmtbody = sb
fmtmode = sm fmtmode = sm
return buf.String() return buf.String()
} }
......
...@@ -24,4 +24,5 @@ const ( ...@@ -24,4 +24,5 @@ const (
FmtLong FmtLong
FmtComma FmtComma
FmtByte FmtByte
FmtBody // for printing export bodies
) )
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
}
// build
package main
import (
x "./burnin"
)
func main() {
x.NewSomething()
}
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment