[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 9 05:37:48 PST 2018


aaron.ballman added a comment.

In https://reviews.llvm.org/D44231#1032011, @pfultz2 wrote:

> > If the return type of foo() is changed, then the use for s1 will be automatically updated
>
> But usually you write it as:
>
>   using foo_return = uint16_t;
>   foo_return foo();
>   ...
>   size_t s1 = sizeof(foo());
>   size_t s2 = sizeof(foo_return);
>
>
> So you just update the `foo_return` typedef, and it will update it everywhere that type is used.


Again, that only works for C++ and not C.

>> I think we need some data measurements over several large (>500k LoC) C and C++ code bases to see how frequently this check yields false positives.
> 
> So I ran it on llvm. It mainly complained about areas where `sizeof` is used for building traits. I should add an extra check that the function is not overloaded.
> 
> It did complain once about `sizeof` in a detection idiom(in BitmaskEnum.h) and once with `sizeof(getVersion())`, like you mentioned.

Did it report any true positives that would need correcting?

LLVM is a good start, but hardly representative. Can you check some other large repos (both C++ and C), such as: Qt, cocos2d, rethinkdb, redis, and php-src? Did they produce true positives? How was the false positive rate?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231





More information about the cfe-commits mailing list