From: Anna Zaks Date: Wed, 6 Mar 2013 20:25:59 +0000 (+0000) Subject: [analyzer] IDC: Add config option; perform the idc check on first “null node” rather... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=713e07591995d761f65c7132289dce003a29870f;p=clang [analyzer] IDC: Add config option; perform the idc check on first “null node” rather than last “non-null”. 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 --- diff --git a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 0a869e05f3..eb58803065 100644 --- a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -214,6 +214,9 @@ private: /// \sa shouldAvoidSuppressingNullArgumentPaths Optional AvoidSuppressingNullArgumentPaths; + /// \sa shouldSuppressInlinedDefensiveChecks + Optional SuppressInlinedDefensiveChecks; + /// \sa getGraphTrimInterval Optional 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. /// diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 5198f4973a..dca68f71ab 100644 --- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -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); diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index b4ba2d4789..248f21cb71 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -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); diff --git a/test/Analysis/inlining/inline-defensive-checks.c b/test/Analysis/inlining/inline-defensive-checks.c index a91d6a3daf..df3a8f2281 100644 --- a/test/Analysis/inlining/inline-defensive-checks.c +++ b/test/Analysis/inlining/inline-defensive-checks.c @@ -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) {