From 6fe2fc633aa736253317340154127329bee73fe7 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Wed, 6 Mar 2013 20:25:59 +0000 Subject: [PATCH] =?utf8?q?[analyzer]=20IDC:=20Add=20config=20option;=20per?= =?utf8?q?form=20the=20idc=20check=20on=20first=20=E2=80=9Cnull=20node?= =?utf8?q?=E2=80=9D=20rather=20than=20last=20=E2=80=9Cnon-null=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. llvm-svn: 176576 --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h | 10 ++++++++++ clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 6 ++++++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 9 +++++++-- clang/test/Analysis/inlining/inline-defensive-checks.c | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 0a869e0..eb58803 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/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/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 5198f49..dca68f7 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/clang/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/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index b4ba2d4..248f21c 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/clang/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/clang/test/Analysis/inlining/inline-defensive-checks.c b/clang/test/Analysis/inlining/inline-defensive-checks.c index a91d6a3..df3a8f2 100644 --- a/clang/test/Analysis/inlining/inline-defensive-checks.c +++ b/clang/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) { -- 2.7.4