Fatalf("walkexpr: invalid index %v", r)
}
- // if len < 0 { panicmakeslicelen }
- nif := nod(OIF, nod(OLT, l, nodintconst(0)), nil)
- nif.Nbody.Set1(mkcall("panicmakeslicelen", nil, init))
- nif = typecheck(nif, ctxStmt)
- init.Append(nif)
-
- // if len > cap { panicmakeslicecap }
- nif = nod(OIF, nod(OGT, conv(l, types.Types[TUINT64]), nodintconst(i)), nil)
- nif.Nbody.Set1(mkcall("panicmakeslicecap", nil, init))
+ // cap is constrained to [0,2^31), so it's safe to do:
+ //
+ // if uint64(len) > cap {
+ // if len < 0 { panicmakeslicelen() }
+ // panicmakeslicecap()
+ // }
+ nif := nod(OIF, nod(OGT, conv(l, types.Types[TUINT64]), nodintconst(i)), nil)
+ niflen := nod(OIF, nod(OLT, l, nodintconst(0)), nil)
+ niflen.Nbody.Set1(mkcall("panicmakeslicelen", nil, init))
+ nif.Nbody.Append(niflen, mkcall("panicmakeslicecap", nil, init))
nif = typecheck(nif, ctxStmt)
init.Append(nif)