This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy/google-runtime-int] Allow passing non-bitwidth types to printf()-style APIs
ClosedPublic

Authored by benhamilton on Apr 30 2018, 3:29 PM.

Details

Summary

The google-runtime-int check currently fires on calls like:

printf("%lu", (unsigned long)foo);

However, the style guide says:

Where possible, avoid passing arguments of types specified by
bitwidth typedefs to printf-based APIs.

http://google.github.io/styleguide/cppguide.html#64-bit_Portability

This diff relaxes the check to not fire on parameters to functions
with the __format__ attribute. (I didn't specifically check
for __printf__ since there are a few variations.)

Test Plan: New tests added. Ran tests with:

% make -j16 check-clang-tools

Diff Detail

Repository
rL LLVM

Event Timeline

benhamilton created this revision.Apr 30 2018, 3:29 PM
alexfh accepted this revision.Apr 30 2018, 4:03 PM

LG with one comment. Thank you for the fix!

test/clang-tidy/google-runtime-int.cpp
77 ↗(On Diff #144645)

Please add another function similar to this one, but without the attribute and verify that the check fires on arguments to that function.

This revision is now accepted and ready to land.Apr 30 2018, 4:03 PM
alexfh added inline comments.Apr 30 2018, 4:09 PM
clang-tidy/google/IntegerTypesCheck.cpp
66 ↗(On Diff #144645)

I vaguely remember that there were some problems matching ancestors of TypeLocs. I hope this has been solved since then, but making a test more robust would be useful. See the other comment.

Add another test for printf without attribute

benhamilton marked 2 inline comments as done.May 1 2018, 7:51 AM

Thanks for the review. Added another test.

test/clang-tidy/google-runtime-int.cpp
77 ↗(On Diff #144645)

Sure, done.

This revision was automatically updated to reflect the committed changes.
benhamilton marked an inline comment as done.