mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: fix Link.Diag printf errors
go1.26's vet printf checker can associate the printf-wrapper property with local vars and struct fields if they are assigned from a printf-like func literal (CL 706635). This leads to better detection of mistakes. Change-Id: I604be1e200aa1aba75e09d4f36ab68c1dba3b8a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/710195 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
e1ca1de123
commit
d4830c6130
7 changed files with 15 additions and 8 deletions
|
|
@ -579,7 +579,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
|
|||
}
|
||||
|
||||
if int64(pc) > p.Pc {
|
||||
ctxt.Diag("PC padding invalid: want %#d, has %#d: %v", p.Pc, pc, p)
|
||||
ctxt.Diag("PC padding invalid: want %d, has %d: %v", p.Pc, pc, p)
|
||||
}
|
||||
for int64(pc) != p.Pc {
|
||||
// emit 0xe1a00000 (MOVW R0, R0)
|
||||
|
|
|
|||
|
|
@ -4354,7 +4354,7 @@ func (c *ctxt7) asmout(p *obj.Prog, out []uint32) (count int) {
|
|||
// remove the NOTUSETMP flag in optab.
|
||||
op := c.opirr(p, p.As)
|
||||
if op&Sbit != 0 {
|
||||
c.ctxt.Diag("can not break addition/subtraction when S bit is set", p)
|
||||
c.ctxt.Diag("can not break addition/subtraction when S bit is set (%v)", p)
|
||||
}
|
||||
rt, r := p.To.Reg, p.Reg
|
||||
if r == obj.REG_NONE {
|
||||
|
|
|
|||
|
|
@ -1216,6 +1216,13 @@ type Link struct {
|
|||
Fingerprint goobj.FingerprintType // fingerprint of symbol indices, to catch index mismatch
|
||||
}
|
||||
|
||||
// Assert to vet's printf checker that Link.DiagFunc is a printf-like.
|
||||
func _(ctxt *Link) {
|
||||
ctxt.DiagFunc = func(format string, args ...any) {
|
||||
_ = fmt.Sprintf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (ctxt *Link) Diag(format string, args ...interface{}) {
|
||||
ctxt.Errors++
|
||||
ctxt.DiagFunc(format, args...)
|
||||
|
|
|
|||
|
|
@ -2057,7 +2057,7 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
|
|||
|
||||
switch o.type_ {
|
||||
default:
|
||||
c.ctxt.Diag("unknown type %d %v", o.type_)
|
||||
c.ctxt.Diag("unknown type %d", o.type_)
|
||||
prasm(p)
|
||||
|
||||
case 0: // pseudo ops
|
||||
|
|
@ -4438,7 +4438,7 @@ func (c *ctxt0) specialFpMovInst(a obj.As, fclass int, tclass int) uint32 {
|
|||
}
|
||||
}
|
||||
|
||||
c.ctxt.Diag("bad class combination: %s %s,%s\n", a, fclass, tclass)
|
||||
c.ctxt.Diag("bad class combination: %s %d,%s\n", a, fclass, tclass)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1172,7 +1172,7 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
|
|||
}
|
||||
switch o.type_ {
|
||||
default:
|
||||
c.ctxt.Diag("unknown type %d %v", o.type_)
|
||||
c.ctxt.Diag("unknown type %d", o.type_)
|
||||
prasm(p)
|
||||
|
||||
case 0: /* pseudo ops */
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
|
|||
switch p.To.Sym.Name {
|
||||
case "go_args_stackmap":
|
||||
if p.From.Type != TYPE_CONST || p.From.Offset != abi.FUNCDATA_ArgsPointerMaps {
|
||||
ctxt.Diag("%s: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p.Pos)
|
||||
ctxt.Diag("%v: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p)
|
||||
}
|
||||
p.To.Sym = ctxt.LookupDerived(curtext, curtext.Name+".args_stackmap")
|
||||
case "no_pointers_stackmap":
|
||||
if p.From.Type != TYPE_CONST || p.From.Offset != abi.FUNCDATA_LocalsPointerMaps {
|
||||
ctxt.Diag("%s: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p.Pos)
|
||||
ctxt.Diag("%v: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p)
|
||||
}
|
||||
// funcdata for functions with no local variables in frame.
|
||||
// Define two zero-length bitmaps, because the same index is used
|
||||
|
|
|
|||
|
|
@ -3026,7 +3026,7 @@ func instructionsForOpImmediate(p *obj.Prog, as obj.As, rs int16) []*instruction
|
|||
|
||||
low, high, err := Split32BitImmediate(ins.imm)
|
||||
if err != nil {
|
||||
p.Ctxt.Diag("%v: constant %d too large", p, ins.imm, err)
|
||||
p.Ctxt.Diag("%v: constant %d too large: %v", p, ins.imm, err)
|
||||
return nil
|
||||
}
|
||||
if high == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue