Skip to content

Commit 50520f1

Browse files
committed
cmd/compile: use Fatalf for more internal errors
There were a surprising number of places in the tree that used yyerror for failed internal consistency checks. Switch them to Fatalf. Updates #15756 Updates #19250 Change-Id: Ie4278148185795a28ff3c27dacffc211cda5bbdd Reviewed-on: https://go-review.googlesource.com/38153 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 57107f3 commit 50520f1

File tree

12 files changed

+36
-40
lines changed

12 files changed

+36
-40
lines changed

src/cmd/compile/internal/gc/dcl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func testdclstack() {
106106
if nerrors != 0 {
107107
errorexit()
108108
}
109-
yyerror("mark left on the stack")
109+
Fatalf("mark left on the stack")
110110
}
111111
}
112112
}

src/cmd/compile/internal/gc/export.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func exportsym(n *Node) {
3333
}
3434
if n.Sym.Export() || n.Sym.Package() {
3535
if n.Sym.Package() {
36-
yyerror("export/package mismatch: %v", n.Sym)
36+
Fatalf("export/package mismatch: %v", n.Sym)
3737
}
3838
return
3939
}
@@ -220,7 +220,7 @@ func pkgtype(s *Sym) *Type {
220220
}
221221

222222
if s.Def.Type == nil {
223-
yyerror("pkgtype %v", s)
223+
Fatalf("pkgtype %v", s)
224224
}
225225
return s.Def.Type
226226
}

src/cmd/compile/internal/gc/fmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ func (t *Type) typefmt(flag FmtFlag) string {
725725
return "map.iter[" + m.Key().String() + "]" + m.Val().String()
726726
}
727727

728-
yyerror("unknown internal map type")
728+
Fatalf("unknown internal map type")
729729
}
730730

731731
buf := make([]byte, 0, 64)

src/cmd/compile/internal/gc/gen.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ func tempname(nn *Node, t *Type) {
192192
}
193193

194194
if t == nil {
195-
yyerror("tempname called with nil type")
196-
t = Types[TINT32]
195+
Fatalf("tempname called with nil type")
197196
}
198197

199198
// give each tmp a different name so that there

src/cmd/compile/internal/gc/mpfloat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (a *Mpflt) Float64() float64 {
128128

129129
// check for overflow
130130
if math.IsInf(x, 0) && nsavederrors+nerrors == 0 {
131-
yyerror("ovf in Mpflt Float64")
131+
Fatalf("ovf in Mpflt Float64")
132132
}
133133

134134
return x + 0 // avoid -0 (should not be needed, but be conservative)
@@ -140,7 +140,7 @@ func (a *Mpflt) Float32() float64 {
140140

141141
// check for overflow
142142
if math.IsInf(x, 0) && nsavederrors+nerrors == 0 {
143-
yyerror("ovf in Mpflt Float32")
143+
Fatalf("ovf in Mpflt Float32")
144144
}
145145

146146
return x + 0 // avoid -0 (should not be needed, but be conservative)

src/cmd/compile/internal/gc/mpint.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (a *Mpint) SetFloat(b *Mpflt) bool {
7373
func (a *Mpint) Add(b *Mpint) {
7474
if a.Ovf || b.Ovf {
7575
if nsavederrors+nerrors == 0 {
76-
yyerror("ovf in Mpint Add")
76+
Fatalf("ovf in Mpint Add")
7777
}
7878
a.SetOverflow()
7979
return
@@ -89,7 +89,7 @@ func (a *Mpint) Add(b *Mpint) {
8989
func (a *Mpint) Sub(b *Mpint) {
9090
if a.Ovf || b.Ovf {
9191
if nsavederrors+nerrors == 0 {
92-
yyerror("ovf in Mpint Sub")
92+
Fatalf("ovf in Mpint Sub")
9393
}
9494
a.SetOverflow()
9595
return
@@ -105,7 +105,7 @@ func (a *Mpint) Sub(b *Mpint) {
105105
func (a *Mpint) Mul(b *Mpint) {
106106
if a.Ovf || b.Ovf {
107107
if nsavederrors+nerrors == 0 {
108-
yyerror("ovf in Mpint Mul")
108+
Fatalf("ovf in Mpint Mul")
109109
}
110110
a.SetOverflow()
111111
return
@@ -121,7 +121,7 @@ func (a *Mpint) Mul(b *Mpint) {
121121
func (a *Mpint) Quo(b *Mpint) {
122122
if a.Ovf || b.Ovf {
123123
if nsavederrors+nerrors == 0 {
124-
yyerror("ovf in Mpint Quo")
124+
Fatalf("ovf in Mpint Quo")
125125
}
126126
a.SetOverflow()
127127
return
@@ -138,7 +138,7 @@ func (a *Mpint) Quo(b *Mpint) {
138138
func (a *Mpint) Rem(b *Mpint) {
139139
if a.Ovf || b.Ovf {
140140
if nsavederrors+nerrors == 0 {
141-
yyerror("ovf in Mpint Rem")
141+
Fatalf("ovf in Mpint Rem")
142142
}
143143
a.SetOverflow()
144144
return
@@ -155,7 +155,7 @@ func (a *Mpint) Rem(b *Mpint) {
155155
func (a *Mpint) Or(b *Mpint) {
156156
if a.Ovf || b.Ovf {
157157
if nsavederrors+nerrors == 0 {
158-
yyerror("ovf in Mpint Or")
158+
Fatalf("ovf in Mpint Or")
159159
}
160160
a.SetOverflow()
161161
return
@@ -167,7 +167,7 @@ func (a *Mpint) Or(b *Mpint) {
167167
func (a *Mpint) And(b *Mpint) {
168168
if a.Ovf || b.Ovf {
169169
if nsavederrors+nerrors == 0 {
170-
yyerror("ovf in Mpint And")
170+
Fatalf("ovf in Mpint And")
171171
}
172172
a.SetOverflow()
173173
return
@@ -179,7 +179,7 @@ func (a *Mpint) And(b *Mpint) {
179179
func (a *Mpint) AndNot(b *Mpint) {
180180
if a.Ovf || b.Ovf {
181181
if nsavederrors+nerrors == 0 {
182-
yyerror("ovf in Mpint AndNot")
182+
Fatalf("ovf in Mpint AndNot")
183183
}
184184
a.SetOverflow()
185185
return
@@ -191,7 +191,7 @@ func (a *Mpint) AndNot(b *Mpint) {
191191
func (a *Mpint) Xor(b *Mpint) {
192192
if a.Ovf || b.Ovf {
193193
if nsavederrors+nerrors == 0 {
194-
yyerror("ovf in Mpint Xor")
194+
Fatalf("ovf in Mpint Xor")
195195
}
196196
a.SetOverflow()
197197
return
@@ -203,7 +203,7 @@ func (a *Mpint) Xor(b *Mpint) {
203203
func (a *Mpint) Lsh(b *Mpint) {
204204
if a.Ovf || b.Ovf {
205205
if nsavederrors+nerrors == 0 {
206-
yyerror("ovf in Mpint Lsh")
206+
Fatalf("ovf in Mpint Lsh")
207207
}
208208
a.SetOverflow()
209209
return
@@ -230,7 +230,7 @@ func (a *Mpint) Lsh(b *Mpint) {
230230
func (a *Mpint) Rsh(b *Mpint) {
231231
if a.Ovf || b.Ovf {
232232
if nsavederrors+nerrors == 0 {
233-
yyerror("ovf in Mpint Rsh")
233+
Fatalf("ovf in Mpint Rsh")
234234
}
235235
a.SetOverflow()
236236
return
@@ -268,7 +268,7 @@ func (a *Mpint) Neg() {
268268
func (a *Mpint) Int64() int64 {
269269
if a.Ovf {
270270
if nsavederrors+nerrors == 0 {
271-
yyerror("constant overflow")
271+
Fatalf("constant overflow")
272272
}
273273
return 0
274274
}

src/cmd/compile/internal/gc/order.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ func orderstmt(n *Node, order *Order) {
799799
if r != nil {
800800
switch r.Op {
801801
default:
802-
yyerror("unknown op in select %v", r.Op)
803802
Dump("select case", r)
803+
Fatalf("unknown op in select %v", r.Op)
804804

805805
// If this is case x := <-ch or case x, y := <-ch, the case has
806806
// the ODCL nodes to declare x and y. We want to delay that
@@ -821,8 +821,8 @@ func orderstmt(n *Node, order *Order) {
821821
}
822822

823823
if r.Ninit.Len() != 0 {
824-
yyerror("ninit on select recv")
825824
dumplist("ninit", r.Ninit)
825+
Fatalf("ninit on select recv")
826826
}
827827

828828
// case x = <-c
@@ -883,8 +883,8 @@ func orderstmt(n *Node, order *Order) {
883883

884884
case OSEND:
885885
if r.Ninit.Len() != 0 {
886-
yyerror("ninit on select send")
887886
dumplist("ninit", r.Ninit)
887+
Fatalf("ninit on select send")
888888
}
889889

890890
// case c <- x

src/cmd/compile/internal/gc/pgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func gvardefx(n *Node, as obj.As) {
9090
Fatalf("gvardef nil")
9191
}
9292
if n.Op != ONAME {
93-
yyerror("gvardef %#v; %v", n.Op, n)
93+
Fatalf("gvardef %#v; %v", n.Op, n)
9494
return
9595
}
9696

src/cmd/compile/internal/gc/plive.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func checkauto(fn *Node, p *obj.Prog, n *Node) {
751751
for _, ln := range fn.Func.Dcl {
752752
fmt.Printf("\t%v (%p; class=%d)\n", ln, ln, ln.Class)
753753
}
754-
yyerror("checkauto: invariant lost")
754+
Fatalf("checkauto: invariant lost")
755755
}
756756

757757
func checkparam(fn *Node, p *obj.Prog, n *Node) {
@@ -768,7 +768,7 @@ func checkparam(fn *Node, p *obj.Prog, n *Node) {
768768
for _, ln := range fn.Func.Dcl {
769769
fmt.Printf("\t%v (%p; class=%d)\n", ln, ln, ln.Class)
770770
}
771-
yyerror("checkparam: invariant lost")
771+
Fatalf("checkparam: invariant lost")
772772
}
773773

774774
func checkprog(fn *Node, p *obj.Prog) {
@@ -1258,7 +1258,7 @@ func livenessepilogue(lv *Liveness) {
12581258
}
12591259
n := lv.vars[j]
12601260
if n.Class != PPARAM {
1261-
yyerrorl(p.Pos, "internal error: %v %L recorded as live on entry, p.Pc=%v", Curfn.Func.Nname, n, p.Pc)
1261+
Fatalf("internal error: %v %L recorded as live on entry, p.Pc=%v", Curfn.Func.Nname, n, p.Pc)
12621262
}
12631263
}
12641264
}

src/cmd/compile/internal/gc/racewalk.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,10 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
364364
OAS2RECV,
365365
OAS2MAPR,
366366
OASOP:
367-
yyerror("instrument: %v must be lowered by now", n.Op)
368-
369-
goto ret
367+
Fatalf("instrument: %v must be lowered by now", n.Op)
370368

371369
case OGETG:
372-
yyerror("instrument: OGETG can happen only in runtime which we don't instrument")
373-
goto ret
370+
Fatalf("instrument: OGETG can happen only in runtime which we don't instrument")
374371

375372
case OFOR, OFORUNTIL:
376373
if n.Left != nil {

src/cmd/compile/internal/gc/reflect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func mapbucket(t *Type) *Type {
165165
// Double-check that overflow field is final memory in struct,
166166
// with no padding at end. See comment above.
167167
if ovf.Offset != bucket.Width-int64(Widthptr) {
168-
yyerror("bad math in mapbucket for %v", t)
168+
Fatalf("bad math in mapbucket for %v", t)
169169
}
170170

171171
t.MapType().Bucket = bucket
@@ -245,7 +245,7 @@ func hiter(t *Type) *Type {
245245
i.SetFields(field[:])
246246
dowidth(i)
247247
if i.Width != int64(12*Widthptr) {
248-
yyerror("hash_iter size not correct %d %d", i.Width, 12*Widthptr)
248+
Fatalf("hash_iter size not correct %d %d", i.Width, 12*Widthptr)
249249
}
250250
t.MapType().Hiter = i
251251
i.StructType().Map = t

src/cmd/compile/internal/gc/walk.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func adjustargs(n *Node, adjust int) {
120120
callfunc := n.Left
121121
for _, arg = range callfunc.List.Slice() {
122122
if arg.Op != OAS {
123-
yyerror("call arg not assignment")
123+
Fatalf("call arg not assignment")
124124
}
125125
lhs = arg.Left
126126
if lhs.Op == ONAME {
@@ -130,12 +130,12 @@ func adjustargs(n *Node, adjust int) {
130130
}
131131

132132
if lhs.Op != OINDREGSP {
133-
yyerror("call argument store does not use OINDREGSP")
133+
Fatalf("call argument store does not use OINDREGSP")
134134
}
135135

136136
// can't really check this in machine-indep code.
137137
//if(lhs->val.u.reg != D_SP)
138-
// yyerror("call arg assign not indreg(SP)");
138+
// Fatalf("call arg assign not indreg(SP)")
139139
lhs.Xoffset += int64(adjust)
140140
}
141141
}
@@ -1694,7 +1694,7 @@ func ascompatee(op Op, nl, nr []*Node, init *Nodes) []*Node {
16941694
var nln, nrn Nodes
16951695
nln.Set(nl)
16961696
nrn.Set(nr)
1697-
yyerror("error in shape across %+v %v %+v / %d %d [%s]", nln, op, nrn, len(nl), len(nr), Curfn.Func.Nname.Sym.Name)
1697+
Fatalf("error in shape across %+v %v %+v / %d %d [%s]", nln, op, nrn, len(nl), len(nr), Curfn.Func.Nname.Sym.Name)
16981698
}
16991699
return nn
17001700
}
@@ -1760,7 +1760,7 @@ func ascompatet(op Op, nl Nodes, nr *Type) []*Node {
17601760
}
17611761

17621762
if i < nl.Len() || r != nil {
1763-
yyerror("ascompatet: assignment count mismatch: %d = %d", nl.Len(), nr.NumFields())
1763+
Fatalf("ascompatet: assignment count mismatch: %d = %d", nl.Len(), nr.NumFields())
17641764
}
17651765

17661766
if ullmanOverflow {
@@ -2678,7 +2678,7 @@ func addstr(n *Node, init *Nodes) *Node {
26782678
c := n.List.Len()
26792679

26802680
if c < 2 {
2681-
yyerror("addstr count %d too small", c)
2681+
Fatalf("addstr count %d too small", c)
26822682
}
26832683

26842684
buf := nodnil()

0 commit comments

Comments
 (0)