]> granicus.if.org Git - clang/commitdiff
[analyzer] IDC: Add config option; perform the idc check on first “null node” rather...
authorAnna Zaks <ganna@apple.com>
Wed, 6 Mar 2013 20:25:59 +0000 (20:25 +0000)
committerAnna Zaks <ganna@apple.com>
Wed, 6 Mar 2013 20:25:59 +0000 (20:25 +0000)
The second modification does not lead to any visible result, but, theoretically, is what we should
have been looking at to begin with since we are checking if the node was assumed to be null in
an inlined function.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176576 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
test/Analysis/inlining/inline-defensive-checks.c

index 0a869e05f30ce45adb6ecf9f84701a41c9594b74..eb58803065f9fc51afff293488e9c0d29391705a 100644 (file)
@@ -214,6 +214,9 @@ private:
   /// \sa shouldAvoidSuppressingNullArgumentPaths
   Optional<bool> AvoidSuppressingNullArgumentPaths;
 
+  /// \sa shouldSuppressInlinedDefensiveChecks
+  Optional<bool> SuppressInlinedDefensiveChecks;
+
   /// \sa getGraphTrimInterval
   Optional<unsigned> GraphTrimInterval;
 
@@ -296,6 +299,13 @@ public:
   /// option, which accepts the values "true" and "false".
   bool shouldAvoidSuppressingNullArgumentPaths();
 
+  /// Returns whether or not diagnostics containing inlined defensive NULL
+  /// checks should be suppressed.
+  ///
+  /// This is controlled by the 'suppress-inlined-defensive-checks' config
+  /// option, which accepts the values "true" and "false".
+  bool shouldSuppressInlinedDefensiveChecks();
+
   /// Returns whether irrelevant parts of a bug report path should be pruned
   /// out of the final output.
   ///
index 5198f4973ad2f547ac41a849e7a7fccf2e3b6033..dca68f71ab54e0545f3bfbcf699c00d2e6c216c7 100644 (file)
@@ -152,6 +152,12 @@ bool AnalyzerOptions::shouldAvoidSuppressingNullArgumentPaths() {
                           /* Default = */ false);
 }
 
+bool AnalyzerOptions::shouldSuppressInlinedDefensiveChecks() {
+  return getBooleanOption(SuppressInlinedDefensiveChecks,
+                          "suppress-inlined-defensive-checks",
+                          /* Default = */ true);
+}
+
 int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {
   SmallString<10> StrBuf;
   llvm::raw_svector_ostream OS(StrBuf);
index b4ba2d478900ac318ea80c2adc2266bf16792756..248f21cb719ef4df89b23216b81e25926aaec683 100644 (file)
@@ -690,7 +690,12 @@ SuppressInlineDefensiveChecksVisitor::VisitNode(const ExplodedNode *N,
                                                 BugReport &BR) {
   if (IsSatisfied)
     return 0;
-  
+
+  AnalyzerOptions &Options =
+    BRC.getBugReporter().getEngine().getAnalysisManager().options;
+  if (!Options.shouldSuppressInlinedDefensiveChecks())
+    return 0;
+
   // Check if in the previous state it was feasible for this value
   // to *not* be null.
   if (PrevN->getState()->assume(V, true)) {
@@ -700,7 +705,7 @@ SuppressInlineDefensiveChecksVisitor::VisitNode(const ExplodedNode *N,
     //       is non-null in N could lead to false negatives.
 
     // Check if this is inline defensive checks.
-    const LocationContext *CurLC = PrevN->getLocationContext();
+    const LocationContext *CurLC = N->getLocationContext();
     const LocationContext *ReportLC = BR.getErrorNode()->getLocationContext();
     if (CurLC != ReportLC && !CurLC->isParentOf(ReportLC))
       BR.markInvalid("Suppress IDC", CurLC);
index a91d6a3daff72cd7f3a184879715bd562e255c3e..df3a8f22811e65ae1d60ceb48cd9fda84d575d40 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config suppress-inlined-defensive-checks=true -verify %s
 
 // Perform inline defensive checks.
 void idc(int *p) {