Possible QoI request: Warn when running the analyzer without the core checkers
| Bugzilla Link | 6912 |
| Resolution | FIXED |
| Resolved on | Dec 10, 2019 09:28 |
| Version | trunk |
| OS | Linux |
| Attachments | test case |
| Reporter | LLVM Bugzilla Contributor |
| CC | @AnnaZaks,@haoNoQ,@Xazax-hun |
Extended Description
I just tried out scan-build on a large project and reduced many of the spurious warnings to the attached simple test case.
The pattern is that there's a global variable along with a function that may initialize it, and anyone who uses it tests either that the variable has been initialized or that the initialization function succeeds. So we always either return or have the variable end up initialized.
This code is kind of crazy, I agree, but it's a real open source library (NSS, from http://www.mozilla.org/projects/security/pki/nss/) that does this.
The error message is as follows: crazy.c:19:18: warning: Dereference of null pointer (loaded from variable 'global_p') printf("%d\n", *global_p);
Since https://reviews.llvm.org/D66042 scan-build automatically "silences" core checkers without disabling them when the user asks to disable them.
Is this still relevant?
Running the analyzer without the core checkers is not supported. We support clang --analyze option as well as scan-build. Calling clang and passing it selected checkers on command line provides "use at your own risk" behavior and should be used by checker developers for debugging, not end users.
We could potentially emit a warning when core checkers are not enabled to enhance user experience.
So the correct command line would look like:
clang -cc1 -analyze -analyzer-checker=core,nullability.NullableDereferenced pr6912.c
Thanks for the explanation and the proposed correction, it works. I think, nonetheless, that this assertion failure sugests some problem in the software architecture...
Does this reproduce with $clang --analyze test_case.c
Not with a recent revision: 313982. Note, however, that Evan Martin referred to revision 102190 (which I have not tried).
Does this reproduce with $clang --analyze test_case.c
So the correct command line would look like:
clang -cc1 -analyze -analyzer-checker=core,nullability.NullableDereferenced pr6912.c
Using the test case pr6912.c and clang svn revision 313982 I get an assertion failure at checker registration.
The command used (in linux):
clang -cc1 -analyze -analyzer-checker=nullability.NullableDereferenced pr6912.c
It appears to me that the class NullabilityChecker needs to inherit from EventDispatcher
in order to succeed the assertion... Am I missing something?
I think you need to turn on core checkers as well. We expect core checkers to be always turned on. They are turned on by the driver but if you use cc1, they need to be turned on explicitly. I do not get any warnings on that test case with the current analyzer. Maybe this issue can be closed?
Using the test case pr6912.c and clang svn revision 313982 I get an assertion failure at checker registration.
The command used (in linux):
clang -cc1 -analyze -analyzer-checker=nullability.NullableDereferenced pr6912.c
It appears to me that the class NullabilityChecker needs to inherit from EventDispatcher
Am I missing something?
Snippet of some C code that triggers some false positives Code pulled from Python trunk (2.7).
I have (possibly) similar problems on the Python trunk (2.7) code base. My spurious warnings about dereferencing a NULL all come from macros for handling reference counting. They are definitely false positives as the variables are explicitly checked either just before or very closely before dereference.
The reason I think the warnings I am getting for Python might be related to this as the macros pass the pointer to some global functions and operate on some global variables.
I have attached a file that contains the relevant snippets of C code (it isn't a valid C file, though, as the errors are coming from big chunks of code).
test case Still in 102838. "Crazy" (getpid() > 0) condition isn't needed here. I attach a simpler test case.
I left out this important detail: Clang revision: 102190
assigned to @devincoughlin