<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99249>99249</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            printf argument checking gets confused with 34 arguments
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          eliotmiranda
      </td>
    </tr>
</table>

<pre>
    In a 34 argument printf of the register state of an ARMv8 processor the compiler mistakenly claims the 32'nd argument isn't used:
printf_warning_bug.c:56:43: warning: data argument not used by format string [-Wformat-extra-args]
                        vr(__x[28]), vr(__fp),    vr(__lr),    vr(__sp),
 ^
printf_warning_bug.c:38:18: note: expanded from macro 'vr'
#   define vr(r) v(regs->r)
 ^
printf_warning_bug.c:21:14: note: expanded from macro 'v'
#define v(v) ((void *)(v))
=============================================
cc -v
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

uname -a
Darwin Machado.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Apr 24 06:05:14 PDT 2024; root:xnu-8020.240.18.708.4~1/RELEASE_ARM64_T6000 arm64
============ printf_warning_bug.c ===============
#include <stdio.h>
#include <sys/ucontext.h>

#if __x86_64__
#       define _PC_IN_UCONTEXT uc_mcontext->__ss.__rip
#       define _FP_IN_UCONTEXT uc_mcontext->__ss.__rbp
#       define _SP_IN_UCONTEXT uc_mcontext->__ss.__rsp
#elif __arm64__
#       define _PC_IN_UCONTEXT uc_mcontext->__ss.__pc
#       define _FP_IN_UCONTEXT uc_mcontext->__ss.__fp
#       define _SP_IN_UCONTEXT uc_mcontext->__ss.__sp
#       define _JIT_SP_IN_UCONTEXT uc_mcontext->__ss.__x[16]
#endif

/* Attempt to dump the registers to stdout.  Only do so if we know how. 
 * Answer the pc (or 0).
 */
static void *
printRegisterState(FILE *file,ucontext_t *uap)
{
#define v(v) ((void *)(v))
#if __x86_64__
        _STRUCT_X86_THREAD_STATE64 *regs = &uap->uc_mcontext->__ss;
        fprintf(file,
                        "    rax %14p rbx %14p rcx %14p rdx %14p\n"
                        "    rdi %14p rsi %14p rbp %14p rsp %14p\n"
                        "    r8  %14p r9  %14p r10 %14p r11 %14p\n"
                        " r12 %14p r13 %14p r14 %14p r15 %14p\n"
                        "    rip %14p\n",
                        v(regs->__rax), v(regs->__rbx), v(regs->__rcx), v(regs->__rdx),
                        v(regs->__rdi), v(regs->__rsi), v(regs->__rbp), v(regs->__rsp),
                        v(regs->__r8 ), v(regs->__r9 ), v(regs->__r10), v(regs->__r11),
                        v(regs->__r12), v(regs->__r13), v(regs->__r14), v(regs->__r15),
                        v(regs->__rip));
        return v(regs->__rip);
# elif defined(__arm64__) || defined(__aarch64__)
        _STRUCT_ARM_THREAD_STATE64 *regs = &uap->uc_mcontext->__ss;
#   define vr(r) v(regs->r)
        fprintf(file,
                        "     x0 %14p  x1 %14p  x2 %14p  x3 %14p\n"
                        "     x4 %14p  x5 %14p  x6 %14p  x7 %14p\n"
                        " x8 %14p  x9 %14p x10 %14p x11 %14p\n"
                        "    x12 %14p x13 %14p x14 %14p x15 %14p\n"
                        "    x16 %14p x17 %14p x18 %14p x19 %14p\n"
                        "    x20 %14p x21 %14p x22 %14p x23 %14p\n"
                        " x24 %14p x25 %14p x26 %14p x27 %14p\n"
                        "    x28 %14p  fp %14p lr %14p  sp %14p\n",
                        "     pc %14p cpsr 0x%08x\n",
                        vr( __x[0]), vr( __x[1]), vr( __x[2]), vr( __x[3]),
                        vr( __x[4]), vr( __x[5]), vr( __x[6]), vr( __x[7]),
                        vr( __x[8]), vr( __x[9]), vr(__x[10]), vr(__x[11]),
                        vr(__x[12]), vr(__x[13]), vr(__x[14]), vr(__x[15]),
                        vr(__x[16]), vr(__x[17]), vr(__x[18]), vr(__x[19]),
                        vr(__x[20]), vr(__x[21]), vr(__x[22]), vr(__x[23]),
                        vr(__x[24]), vr(__x[25]), vr(__x[26]), vr(__x[27]),
                        vr(__x[28]), vr(__fp),    vr(__lr), vr(__sp),
                        vr(__pc), regs->__cpsr);
        return vr(__pc);
#else
        fprintf(file,"don't know how to derive register state from a ucontext_t on this platform\n");
        return v(0);
#endif
}

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWEuT4jgS_jXikoHDTj8wBw4Uj9janZ7pqGJ2-uYQtgzaNpZDkin3ZX_7hmyDaMpUe7v3sBUVkHzKl1KpTElUKX4oGVuQ8ImE6wmt9VHIBSu40CcuaZnRyV5k3xbPJVDwA6DyUJ9YqaGSvNQ5iBz0kYFkB640k6A01cygtITly6dzDJUUKVNKyJYxFaeKF0zCiStNv7Ky-AZpQflJtcM-EpyVmTXDVUlwpqFWLCP-krhr4i4728kblSUvD8m-Pjgp8ZdhRPxl4BN_Cf2QITOqqdVXik4X7L9BLuSJalBa8vIAJHya_tVBU9ZoSadUHhQJ151NePB3lgTjJGlI-ISx4cY5wdUFzqv-t-Us5DtI9Vy9JRJuPpynHxN_6ZkPMx1mvllT0TJjGeRSnOBEUymA4Mzon3W6CPoAkLGcl6yza_yAsyHYQU2Jv2kdG-cCesaFYIwLtx5czBOMz8Y6wdiQgmdAcNkGoR24OkL89f_Ff-tMmsL03JHLqiqYSdzyAGcmFRcleIHjOq6ZU4tPvcB1HdfBuYMuXme0o_LAtAkYlacomFKjaZpR-cZL9JzIcXu-o2Q0g5PIWGG4K6F40w09l0rTomDZmkszRHBr_OEp1VyUiuD2Syoy5tCqIrhdiVKzUht4zc6sEBWTBLc7IYr0SLnlX7Oc1oV2mlRfxghua2W497zsF6T9rEt6YjCl3a916zx8oumRZsIpREoL6OYC_dg_mCxZAf_sQ9VP1F_CXyyDZSUBA3DN9nXDNrHg83oH6GJA_CeQQpiANWU9jV10HQxcx4udmRs7wb89gtuXzW-b5esmWb58ioJkF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