]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: fix Link.Diag printf errors
authorAlan Donovan <adonovan@google.com>
Wed, 8 Oct 2025 16:19:14 +0000 (12:19 -0400)
committerAlan Donovan <adonovan@google.com>
Wed, 8 Oct 2025 20:44:19 +0000 (13:44 -0700)
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>
src/cmd/internal/obj/arm/asm5.go
src/cmd/internal/obj/arm64/asm7.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/loong64/asm.go
src/cmd/internal/obj/mips/asm0.go
src/cmd/internal/obj/plist.go
src/cmd/internal/obj/riscv/obj.go

index 0ef13b81f6f3f167c0cb9c68d324a955ce945851..1e2891de0a7ddc5a277e010c26c038ffdf540a17 100644 (file)
@@ -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)
index 743d09a319087dfdd3e4fff57bd1e4dfa2cf9db6..172c2256d7eede836259c133c6736926f8b696af 100644 (file)
@@ -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 {
index 816fed026f35ad52ad77aa8546a468f2ba0d5f3a..b7e116bae39dc42a9f4175eae664fc2344279ef4 100644 (file)
@@ -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...)
index ca6e2be4aa9eb672285fb989f32154384b14000c..ccf093ca9e8d548137dfe3fc16690b8394b8c2af 100644 (file)
@@ -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
 }
index 2de5a4d6c0b8fc849ef344e156e104744802ea3c..a55953e741432afcd20a912ce0e53cb1faa3d87b 100644 (file)
@@ -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 */
index 698e5ace9ccca82bdec797abb7e00fd0ca014a91..69914b1c1f36d5d1c04d62a6ba1a1f9ae7e2cb8b 100644 (file)
@@ -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
index 91642ffbcb0e5043992047d1929850fe61bc8952..4a9c54a3967c4e6a9c94627870915aacac75b578 100644 (file)
@@ -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 {