[PATCH] D32346: [clang-tidy] New readability check for strlen argument
Daniel Marjamäki via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 25 03:45:12 PDT 2017
danielmarjamaki added a comment.
I am thinking about making my check more strict so it only warns in allocations. I believe the example code is much more motivating when there is allocation.
In https://reviews.llvm.org/D32346#733430, @JonasToth wrote:
> My thoughts on the check added.
> Have you run it over a big codebase? What is the turnout?
>
> And please add the check to the ReleaseNotes.
I have a script that runs clang/clang-tidy on all debian source code. It basically grabs all packages and if it has a configure script it runs: ./configure && bear make && clang-tidy .. Running that right now.
It goes slowly I have run clang-tidy on 22 packages (735 files) so far and got 13 warnings.
Unfortunately most warnings so far are false positives as in this example code:
#include <string.h>
void dostuff(const char *P) {
if (strncmp(P+2,"xyz",3)==0) {}
}
Without -O2 I get no warning. With -O2 I get a false positive:
danielm at debian:~$ ~/llvm/build/bin/clang-tidy -checks=-*,readability-strlen-argument strlen.c -- -O2
1 warning generated.
/home/danielm/strlen.c:3:16: warning: strlen() argument has pointer addition, it is recommended to subtract the result instead. [readability-strlen-argument]
if (strncmp(P+2,"xyz",3)==0) {}
^
When the -O2 flag is used then on my machine the strncmp() function call is expanded to lots of code. and in that code, there are calls to strlen().
I should probably avoid these, I guess skipping all warnings in macro code sounds ok to me.
Repository:
rL LLVM
https://reviews.llvm.org/D32346
More information about the cfe-commits
mailing list