llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Possible QoI request: Warn when running the analyzer without the core checkers

Open llvmbot opened this issue 16 years ago • 14 comments

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);

llvmbot avatar Apr 24 '10 03:04 llvmbot

Since https://reviews.llvm.org/D66042 scan-build automatically "silences" core checkers without disabling them when the user asks to disable them.

haoNoQ avatar Dec 10 '19 17:12 haoNoQ

Is this still relevant?

llvmbot avatar Apr 23 '19 21:04 llvmbot

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.

AnnaZaks avatar Oct 10 '17 19:10 AnnaZaks

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...

llvmbot avatar Oct 10 '17 08:10 llvmbot

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).

llvmbot avatar Oct 10 '17 08:10 llvmbot

Does this reproduce with $clang --analyze test_case.c

AnnaZaks avatar Oct 09 '17 18:10 AnnaZaks

So the correct command line would look like:

clang -cc1 -analyze -analyzer-checker=core,nullability.NullableDereferenced pr6912.c

Xazax-hun avatar Oct 05 '17 09:10 Xazax-hun

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?

Xazax-hun avatar Oct 05 '17 09:10 Xazax-hun

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?

llvmbot avatar Sep 26 '17 13:09 llvmbot

Snippet of some C code that triggers some false positives Code pulled from Python trunk (2.7).

llvmbot avatar May 07 '10 01:05 llvmbot

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).

llvmbot avatar May 07 '10 01:05 llvmbot

test case Still in 102838. "Crazy" (getpid() > 0) condition isn't needed here. I attach a simpler test case.

llvmbot avatar May 02 '10 10:05 llvmbot

I left out this important detail: Clang revision: 102190

llvmbot avatar Apr 24 '10 03:04 llvmbot

assigned to @devincoughlin

llvmbot avatar Apr 24 '10 03:04 llvmbot