[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
This commit is contained in:
Anna Zaks 2013-03-06 20:25:59 +00:00
Родитель 398253ab0e
Коммит 713e075919
4 изменённых файлов: 24 добавлений и 3 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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) {