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) {
ptxt := pp.Prog(obj.ATEXT)
pp.Text = ptxt
if fn.Func.lsym == nil {
// func _() { }
return
}
fn.Func.lsym.Func.Text = ptxt
ptxt.From.Type = obj.TYPE_MEM
ptxt.From.Name = obj.NAME_EXTERN
......
......@@ -258,7 +258,6 @@ func compile(fn *Node) {
// be types of stack objects. We need to do this here
// because symbols must be allocated before the parallel
// phase of the compiler.
if fn.Func.lsym != nil { // not func _(){}
for _, n := range fn.Func.Dcl {
switch n.Class() {
case PPARAM, PPARAMOUT, PAUTO:
......@@ -272,7 +271,6 @@ func compile(fn *Node) {
}
}
}
}
if compilenow() {
compileSSA(fn, 0)
......
......@@ -1426,7 +1426,7 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
}
// 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()
p := pp.Prog(obj.AFUNCDATA)
......@@ -1446,6 +1446,6 @@ func liveness(e *ssafn, f *ssa.Func, pp *Progs) LivenessMap {
p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN
p.To.Sym = ls.Func.GCRegs
}
return lv.livenessMap
}
......@@ -5175,10 +5175,7 @@ func genssa(f *ssa.Func, pp *Progs) {
}
case ssa.OpInlMark:
p := thearch.Ginsnop(s.pp)
if pp.curfn.Func.lsym != nil {
// 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?
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