Patch for addressing format warnings on 32-bit

Message: 1
Date: Sat, 26 Dec 2015 21:15:53 +0100
From: Joerg Sonnenberger via lldb-dev <lldb-dev@lists.llvm.org>
To: lldb-dev@lists.llvm.org
Subject: Re: [lldb-dev] Patch for addressing format warnings on 32-bit
Message-ID: <20151226201553.GB14119@britannica.bec.de>
Content-Type: text/plain; charset=utf-8

There are a handful of -Wformat warnings on 32-bit platforms.
I addressed all those that I’ve seen while working on Swift.
Let me know if the git diff format is inappropriate for this.

Don't cast size_t to uint64_t, format it with %zu directly.

Joerg

I can go ahead and do that, but I wonder whether there should be two different ways of handling this, even on the same line. For example:

- error.SetErrorStringWithFormat ("SoftwareBreakpointr::%s addr=0x%" PRIx64 ": tried to read %lu bytes but only read %" PRIu64, __FUNCTION__, m_addr, m_opcode_size, (uint64_t)bytes_read);
+ error.SetErrorStringWithFormat ("SoftwareBreakpointr::%s addr=0x%" PRIx64 ": tried to read %" PRIu64 " bytes but only read %" PRIu64, __FUNCTION__, m_addr, (uint64_t)m_opcode_size, (uint64_t)bytes_read);

- Will

Hi William,

It looks like just the PRIx64/PRIu64 bits are needed from a visual inspection. The source variables that are printed from already are 64-bit always, aren’t they? If they’re not but they should be, that seems like the real underlying problem rather than needing to cast.

What kind of warning are you seeing if you just replace the % format specifier?

Thanks!

-Todd

Hi Todd,

The example I put in my last email is one of a few (maybe one more) instances where the existing code casts to 64-bit and uses PRIu64. When I’m dabbling in existing code I try to copy the conventions that are already in place, so that’s why I went this way. I’m happy to change it to %zu. I was just checking about that.

  • Will

I believe %z will not work on MSVC 2013, which we are still using on windows.

pl

Please do cast to 64 bit and user PRI*64 macros. %z isn't supported on all platforms and we need to get away from using it.

Incidentally, once we can start requiring VS 2015 %z will be supported there. Not sure if MSVC is the only supported platform that currently doesn’t support %z