Commit f495f549 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: don't bother compiling functions named "_"

They can't be used, so we don't need code generated for them. We just
need to report errors in their bodies.

The compiler currently has a bunch of special cases sprinkled about
for "_" functions, because we never generate a linker symbol for them.
Instead, abort compilation earlier so we never reach any of that
special-case code.

Fixes #29870

Change-Id: I3530c9c353deabcf75ce9072c0b740e992349ee5
Reviewed-on: https://go-review.googlesource.com/c/158845
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 933e34ac
...@@ -176,11 +176,6 @@ func (pp *Progs) settext(fn *Node) { ...@@ -176,11 +176,6 @@ func (pp *Progs) settext(fn *Node) {
ptxt := pp.Prog(obj.ATEXT) ptxt := pp.Prog(obj.ATEXT)
pp.Text = ptxt pp.Text = ptxt
if fn.Func.lsym == nil {
// func _() { }
return
}
fn.Func.lsym.Func.Text = ptxt fn.Func.lsym.Func.Text = ptxt
ptxt.From.Type = obj.TYPE_MEM ptxt.From.Type = obj.TYPE_MEM
ptxt.From.Name = obj.NAME_EXTERN ptxt.From.Name = obj.NAME_EXTERN
......
...@@ -258,17 +258,15 @@ func compile(fn *Node) { ...@@ -258,17 +258,15 @@ func compile(fn *Node) {
// be types of stack objects. We need to do this here // be types of stack objects. We need to do this here
// because symbols must be allocated before the parallel // because symbols must be allocated before the parallel
// phase of the compiler. // phase of the compiler.
if fn.Func.lsym != nil { // not func _(){} for _, n := range fn.Func.Dcl {
for _, n := range fn.Func.Dcl { switch n.Class() {
switch n.Class() { case PPARAM, PPARAMOUT, PAUTO:
case PPARAM, PPARAMOUT, PAUTO: if livenessShouldTrack(n) && n.Addrtaken() {
if livenessShouldTrack(n) && n.Addrtaken() { dtypesym(n.Type)
dtypesym(n.Type) // Also make sure we allocate a linker symbol
// Also make sure we allocate a linker symbol // for the stack object data, for the same reason.
// for the stack object data, for the same reason. if fn.Func.lsym.Func.StackObjects == nil {
if fn.Func.lsym.Func.StackObjects == nil { fn.Func.lsym.Func.StackObjects = lookup(fmt.Sprintf("%s.stkobj", fn.funcname())).Linksym()
fn.Func.lsym.Func.StackObjects = lookup(fmt.Sprintf("%s.stkobj", fn.funcname())).Linksym()
}
} }
} }
} }
......
...@@ -1426,26 +1426,26 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap { ...@@ -1426,26 +1426,26 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
} }
// Emit the live pointer map data structures // Emit the live pointer map data structures
if ls := e.curfn.Func.lsym; ls != nil { ls := e.curfn.Func.lsym
ls.Func.GCArgs, ls.Func.GCLocals, ls.Func.GCRegs = lv.emit() ls.Func.GCArgs, ls.Func.GCLocals, ls.Func.GCRegs = lv.emit()
p := pp.Prog(obj.AFUNCDATA) p := pp.Prog(obj.AFUNCDATA)
Addrconst(&p.From, objabi.FUNCDATA_ArgsPointerMaps) Addrconst(&p.From, objabi.FUNCDATA_ArgsPointerMaps)
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN p.To.Name = obj.NAME_EXTERN
p.To.Sym = ls.Func.GCArgs p.To.Sym = ls.Func.GCArgs
p = pp.Prog(obj.AFUNCDATA) p = pp.Prog(obj.AFUNCDATA)
Addrconst(&p.From, objabi.FUNCDATA_LocalsPointerMaps) Addrconst(&p.From, objabi.FUNCDATA_LocalsPointerMaps)
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN p.To.Name = obj.NAME_EXTERN
p.To.Sym = ls.Func.GCLocals p.To.Sym = ls.Func.GCLocals
p = pp.Prog(obj.AFUNCDATA) p = pp.Prog(obj.AFUNCDATA)
Addrconst(&p.From, objabi.FUNCDATA_RegPointerMaps) Addrconst(&p.From, objabi.FUNCDATA_RegPointerMaps)
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN p.To.Name = obj.NAME_EXTERN
p.To.Sym = ls.Func.GCRegs p.To.Sym = ls.Func.GCRegs
}
return lv.livenessMap return lv.livenessMap
} }
...@@ -5175,10 +5175,7 @@ func genssa(f *ssa.Func, pp *Progs) { ...@@ -5175,10 +5175,7 @@ func genssa(f *ssa.Func, pp *Progs) {
} }
case ssa.OpInlMark: case ssa.OpInlMark:
p := thearch.Ginsnop(s.pp) p := thearch.Ginsnop(s.pp)
if pp.curfn.Func.lsym != nil { pp.curfn.Func.lsym.Func.AddInlMark(p, v.AuxInt32())
// lsym is nil if the function name is "_".
pp.curfn.Func.lsym.Func.AddInlMark(p, v.AuxInt32())
}
// TODO: if matching line number, merge somehow with previous instruction? // TODO: if matching line number, merge somehow with previous instruction?
default: default:
......
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