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) {
}
// 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 {
......
......@@ -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()
}
......
......@@ -24,4 +24,5 @@ const (
FmtLong
FmtComma
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