[PATCH] D59135: Add check for matching HeaderFilter before emitting Diagnostic
Thorsten via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 8 06:06:21 PDT 2019
thorsten-klein added a comment.
Hello @alexfh ,
Let me extend your example
$ cat a.cc
#include "b.h"
#include "d.h"
int main(){check(nullptr);}
$ cat b.h
#include "c.h"
inline void b() { c(/*y=*/42); }
$ cat c.h
void c(int x);
$ cat d.h
inline char* check(char* buffer)
{
*buffer++=1; // Should be clang-analyzer-core.NullDereference
return buffer;
}
Now an additional warning is found and shown (=not suppressed):
$ clang-tidy -checks=-*,clang-*,bugprone-argument-comment a.cc --
2 warnings generated.
/home/default/Temp/clang-tidy-test/d.h:3:11: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/a.cc:3:12: note: Calling 'check'
int main(){check(0);}
^
/home/default/Temp/clang-tidy-test/d.h:3:3: note: Null pointer value stored to 'buffer'
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/d.h:3:11: note: Dereference of null pointer
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
**How can I use -header-filter now?**
With -header-filter=b.h clang-tidy shows both warnings:
$ clang-tidy -checks=-*,clang-*,bugprone-argument-comment a.cc -header-filter=b.h --
2 warnings generated.
/home/default/Temp/clang-tidy-test/b.h:2:21: warning: argument name 'y' in comment does not match parameter name 'x' [bugprone-argument-comment]
inline void b() { c(/*y=*/42); }
^~~~~~
/*x=*/
/home/default/Temp/clang-tidy-test/c.h:1:12: note: 'x' declared here
void c(int x);
^
/home/default/Temp/clang-tidy-test/d.h:3:11: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/a.cc:3:12: note: Calling 'check'
int main(){check(0);}
^
/home/default/Temp/clang-tidy-test/d.h:3:3: note: Null pointer value stored to 'buffer'
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/d.h:3:11: note: Dereference of null pointer
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
With -header-filter=c.h clang-tidy shows both warnings:
$ clang-tidy -checks=-*,clang-*,bugprone-argument-comment a.cc -header-filter=c.h --
2 warnings generated.
/home/default/Temp/clang-tidy-test/b.h:2:21: warning: argument name 'y' in comment does not match parameter name 'x' [bugprone-argument-comment]
inline void b() { c(/*y=*/42); }
^~~~~~
/*x=*/
/home/default/Temp/clang-tidy-test/c.h:1:12: note: 'x' declared here
void c(int x);
^
/home/default/Temp/clang-tidy-test/d.h:3:11: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/a.cc:3:12: note: Calling 'check'
int main(){check(0);}
^
/home/default/Temp/clang-tidy-test/d.h:3:3: note: Null pointer value stored to 'buffer'
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/d.h:3:11: note: Dereference of null pointer
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
With -header-filter=c.h clang-tidy shows both warnings:
$ clang-tidy -checks=-*,clang-*,bugprone-argument-comment a.cc -header-filter=d.h --
2 warnings generated.
/home/default/Temp/clang-tidy-test/d.h:3:11: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/a.cc:3:12: note: Calling 'check'
int main(){check(nullptr);}
^
/home/default/Temp/clang-tidy-test/d.h:3:3: note: Null pointer value stored to 'buffer'
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
/home/default/Temp/clang-tidy-test/d.h:3:11: note: Dereference of null pointer
*buffer++=1; // Should be clang-analyzer-core.NullDereference
^
Suppressed 1 warnings (1 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
How can I suppress warning for my header file //**d.h**// so that only warning from //**b.h**// is shown?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59135/new/
https://reviews.llvm.org/D59135
More information about the cfe-commits
mailing list