https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80776
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |13.0 --- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Martin Sebor from comment #7) > Reconfirming that test case in comment #2 still triggers the warning in GCC > 10. The dump shows that the warning thinks the fifth directive (%02d) > generates between 2 and 10 bytes of output. The symptoms feel similar to > pr94021 but I haven't looked into whether they underlying root causes are > related. That testcase looks to be fixed in GCC 13: /app/example.cpp:13: __builtin_sprintf: objsize = 15, fmtstr = "%04d%02d%02d%02d%02d%02d" Directive 1 at offset 0: "%04d" Result: 4, 4, 4, 4 (4, 4, 4, 4) Directive 2 at offset 4: "%02d" Result: 2, 2, 2, 2 (6, 6, 6, 6) Directive 3 at offset 8: "%02d" Result: 2, 2, 2, 2 (8, 8, 8, 8) Directive 4 at offset 12: "%02d" Result: 2, 2, 2, 2 (10, 10, 10, 10) Directive 5 at offset 16: "%02d" Result: 2, 2, 2, 2 (12, 12, 12, 12) Directive 6 at offset 20: "%02d" Result: 2, 2, 2, 2 (14, 14, 14, 14) Directive 7 at offset 24: "", length = 1 Substituting 14 for return value. GCC 13: # RANGE [irange] int [-999, 9999] intD.6 a_14(D) = aD.2739; # RANGE [irange] int [1, 12] NONZERO 0xf intD.6 b_15(D) = bD.2740; # RANGE [irange] int [1, 31] NONZERO 0x1f intD.6 c_16(D) = cD.2741; # RANGE [irange] int [0, 23] NONZERO 0x1f intD.6 d_17(D) = dD.2742; # RANGE [irange] int [0, 59] NONZERO 0x3f intD.6 e_18(D) = eD.2743; # RANGE [irange] int [0, 60] NONZERO 0x3f intD.6 f_19(D) = fD.2744; GCC 12: # RANGE [-999, 9999] intD.6 a_14(D) = aD.1979; # RANGE [1, 12] NONZERO 15 intD.6 b_15(D) = bD.1980; # RANGE [1, 31] NONZERO 31 intD.6 c_16(D) = cD.1981; # RANGE [0, 23] NONZERO 31 intD.6 d_17(D) = dD.1982; # RANGE [0, 2147483647] NONZERO 2147483647 intD.6 e_18(D) = eD.1983; # RANGE [0, 2147483647] NONZERO 2147483647 intD.6 f_19(D) = fD.1984; So yes this has been fixed for GCC 13.