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

[Meta] In-source false positive suppressions.

Open llvmbot opened this issue 18 years ago • 7 comments

Bugzilla Link 2650
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @AnnaZaks,@tkremenek,@haoNoQ

Extended Description

Every so often I run my code through the static analyzer. What's frustrating is to keep seeing warnings for bits of code that I already know about, but won't be changing for one reason or another.

Just like there is the concept of "#pragma unused" in C to tell the compiler "yes, I'm not using this variable on purpose, don't warn me about it", we need the ability to selectively prevent the static analyzer from warning us about particular items again.

Why? It depends.

  • Sometimes there are bits of code that aren't really my code, and I'm not comfortable fixing them. I have often put in a general #warning line to highlight the potential of the problem to the person who actually maintains the code (but may not be running the static analyzer) to point out the issue. Once I've done that, I don't want to be re-warned about the issue by the static analyzer because I've dealt with it.

  • Sometime it is a chunk of code that works just fine; though there is a minor technical error (such as not using the result of an expression) and I just don't want to mess with it, following the adage of "If it ain't broke, don't fix it." Again, once I've seen the warning and done my own analysis of it, I don't want to be notified by the static analyzer each time.

  • Another reason would be that my code is doing something "on purpose" -- e.g. creating an NSURLConnection that I'm planning on disposing of asynchronously when it's done loading. The static analyzer will flag this is a leak, which is technically correct; I just don't want to be warned about it over and over again (each time I run the analyzer.)

If I had a way of indicating, perhaps on the line above with something like #pragma no-warning blah blah blah, that the offending line below is already known about, then I would be able to make use of the static analyzer on a frequent basis, and only be warned of new conditions -- things I need to look at and possibly fix.

llvmbot avatar Aug 07 '08 18:08 llvmbot

These days we have a lot of suppression mechanisms to cover most of the needs:

  • Function annotations to tell Static Analyzer how does a library function behave.
  • Assertions in order to suppress bugs on unobviously impossible execution paths.
  • #ifndef clang_analyzer as a last-resort suppression to exclude code from analysis.

Apart from the FAQ page mentioned by Anna above, there's a documentation on annotations at http://clang-analyzer.llvm.org/annotations.html

However, there's still no direct and straightforward way to suppress reports from specific checkers on specific lines of code. Let's keep this bug report to track progress in this area.

haoNoQ avatar Dec 24 '18 00:12 haoNoQ

pragma approach does not work for the static analyzer. Some methods of silencing the analyzer false positives/giving hints to the analyzer are listed here: http://clang-analyzer.llvm.org/faq.html

AnnaZaks avatar Oct 25 '13 05:10 AnnaZaks

Since Xcode 5 seems to be using command line switches to pass in what is enabled/disabled; does that mean the plumbing is now there to support this? Say something like:

... #pragma clang analyzer push #pragma clang analyzer ignored "security.insecureAPI.rand" ... #pragma clang analyzer pop ...

llvmbot avatar Aug 22 '13 19:08 llvmbot

Is there any way to get this moved out of "new" status? Should I drum up some more support from the community? Is it something that is even feasable?

I find that most of my time wasted whenever I fire up the static analyzer is seeing the same reports that I already saw. If I had a way to indicate that I know what I'm doing; I want to initialize a variable with an empty value just to be a defensive coder, or I am returning a "shared instance" (retained item), I don't want to be reminded of this as a problem over and over again -- it's essentially a false positive once I've determined that it's doing what I intended.

This is still on my plans of things to do, and I understand your frustration. This is something I'd very much still like to implement.

These main reason this hasn't been tackled yet has largely been due to it not bubbling up high enough in my priority list. The other reason is that the bug reporting machinery for the analyzer has gone through some big changes over the last several months, and there currently is no way to have fine-grain control over checks from the command line. This isn't super hard to do, but it does require a little bit of work that just hasn't taken priority over other things. This fine-grain control would then naturally allow us to control static analyzer issues using pragmas or similar annotations.

tkremenek avatar Jun 03 '09 06:06 tkremenek

Is there any way to get this moved out of "new" status? Should I drum up some more support from the community? Is it something that is even feasable?

I find that most of my time wasted whenever I fire up the static analyzer is seeing the same reports that I already saw. If I had a way to indicate that I know what I'm doing; I want to initialize a variable with an empty value just to be a defensive coder, or I am returning a "shared instance" (retained item), I don't want to be reminded of this as a problem over and over again -- it's essentially a false positive once I've determined that it's doing what I intended.

llvmbot avatar Jun 02 '09 23:06 llvmbot

I would also be excited to see something like this. I was chatting with some colleagues about the problem of sifting through false positives, and this seems to be a feature many of us would be excited to have.

One person astutely observed that the clang team may wish to forego providing such a mechanism, because at this early stage in the project's development, it's more important to encourage bug reporting for false positives, etc. I can see the reasoning here, and I wonder if it might be true that the clang team is thinking of things this way.

However, the flip side of that coin is that the static analyzer will get used less often, and will be ultimately subjected to less varied testing, if the noise of acknowledge false positives is so great that it can't be easily run and reviewed on a regular basis.

Perhaps a useful compromise would be to support this marking of "acknowledged" warnings, but to keep them in the loop somehow, so they don't completely disappear from view. I.e. in the reports viewer, if I could have a checkbox for "acknowledged" issues, that I could uncheck when I want to focus only on new problems I might have introduced, I think I would be encouraged to use the checker more often.

Daniel

llvmbot avatar Feb 21 '09 19:02 llvmbot

assigned to @tkremenek

llvmbot avatar Aug 07 '08 18:08 llvmbot