Skip to content

Commit d4830c6

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent e1ca1de commit d4830c6

File tree

7 files changed

+15
-8
lines changed

7 files changed

+15
-8
lines changed

src/cmd/internal/obj/arm/asm5.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
579579
}
580580

581581
if int64(pc) > p.Pc {
582-
ctxt.Diag("PC padding invalid: want %#d, has %#d: %v", p.Pc, pc, p)
582+
ctxt.Diag("PC padding invalid: want %d, has %d: %v", p.Pc, pc, p)
583583
}
584584
for int64(pc) != p.Pc {
585585
// emit 0xe1a00000 (MOVW R0, R0)

src/cmd/internal/obj/arm64/asm7.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4354,7 +4354,7 @@ func (c *ctxt7) asmout(p *obj.Prog, out []uint32) (count int) {
43544354
// remove the NOTUSETMP flag in optab.
43554355
op := c.opirr(p, p.As)
43564356
if op&Sbit != 0 {
4357-
c.ctxt.Diag("can not break addition/subtraction when S bit is set", p)
4357+
c.ctxt.Diag("can not break addition/subtraction when S bit is set (%v)", p)
43584358
}
43594359
rt, r := p.To.Reg, p.Reg
43604360
if r == obj.REG_NONE {

src/cmd/internal/obj/link.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,13 @@ type Link struct {
12161216
Fingerprint goobj.FingerprintType // fingerprint of symbol indices, to catch index mismatch
12171217
}
12181218

1219+
// Assert to vet's printf checker that Link.DiagFunc is a printf-like.
1220+
func _(ctxt *Link) {
1221+
ctxt.DiagFunc = func(format string, args ...any) {
1222+
_ = fmt.Sprintf(format, args...)
1223+
}
1224+
}
1225+
12191226
func (ctxt *Link) Diag(format string, args ...interface{}) {
12201227
ctxt.Errors++
12211228
ctxt.DiagFunc(format, args...)

src/cmd/internal/obj/loong64/asm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
20572057

20582058
switch o.type_ {
20592059
default:
2060-
c.ctxt.Diag("unknown type %d %v", o.type_)
2060+
c.ctxt.Diag("unknown type %d", o.type_)
20612061
prasm(p)
20622062

20632063
case 0: // pseudo ops
@@ -4438,7 +4438,7 @@ func (c *ctxt0) specialFpMovInst(a obj.As, fclass int, tclass int) uint32 {
44384438
}
44394439
}
44404440

4441-
c.ctxt.Diag("bad class combination: %s %s,%s\n", a, fclass, tclass)
4441+
c.ctxt.Diag("bad class combination: %s %d,%s\n", a, fclass, tclass)
44424442

44434443
return 0
44444444
}

src/cmd/internal/obj/mips/asm0.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ func (c *ctxt0) asmout(p *obj.Prog, o *Optab, out []uint32) {
11721172
}
11731173
switch o.type_ {
11741174
default:
1175-
c.ctxt.Diag("unknown type %d %v", o.type_)
1175+
c.ctxt.Diag("unknown type %d", o.type_)
11761176
prasm(p)
11771177

11781178
case 0: /* pseudo ops */

src/cmd/internal/obj/plist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ func Flushplist(ctxt *Link, plist *Plist, newprog ProgAlloc) {
6363
switch p.To.Sym.Name {
6464
case "go_args_stackmap":
6565
if p.From.Type != TYPE_CONST || p.From.Offset != abi.FUNCDATA_ArgsPointerMaps {
66-
ctxt.Diag("%s: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p.Pos)
66+
ctxt.Diag("%v: FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps", p)
6767
}
6868
p.To.Sym = ctxt.LookupDerived(curtext, curtext.Name+".args_stackmap")
6969
case "no_pointers_stackmap":
7070
if p.From.Type != TYPE_CONST || p.From.Offset != abi.FUNCDATA_LocalsPointerMaps {
71-
ctxt.Diag("%s: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p.Pos)
71+
ctxt.Diag("%v: FUNCDATA use of no_pointers_stackmap(SB) without FUNCDATA_LocalsPointerMaps", p)
7272
}
7373
// funcdata for functions with no local variables in frame.
7474
// Define two zero-length bitmaps, because the same index is used

src/cmd/internal/obj/riscv/obj.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ func instructionsForOpImmediate(p *obj.Prog, as obj.As, rs int16) []*instruction
30263026

30273027
low, high, err := Split32BitImmediate(ins.imm)
30283028
if err != nil {
3029-
p.Ctxt.Diag("%v: constant %d too large", p, ins.imm, err)
3029+
p.Ctxt.Diag("%v: constant %d too large: %v", p, ins.imm, err)
30303030
return nil
30313031
}
30323032
if high == 0 {

0 commit comments

Comments
 (0)