diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 8 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 23 |
2 files changed, 25 insertions, 6 deletions
diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 04eb0ad97b..1ffd105766 100644 --- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -90,6 +90,14 @@ bool AnalyzerOptions::mayInlineObjCMethod() const { return *ObjCInliningMode; } +bool AnalyzerOptions::shouldPruneNullReturnPaths() const { + if (!PruneNullReturnPaths.hasValue()) + const_cast<llvm::Optional<bool> &>(PruneNullReturnPaths) = + getBooleanOption("suppress-null-return-paths", /*Default=*/true); + + return *PruneNullReturnPaths; +} + int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) const { std::string OptStr = Config.lookup(Name); if (OptStr.empty()) diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index 445500ba31..00d7d3becf 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -140,9 +140,13 @@ public: ReturnVisitor(const StackFrameContext *Frame) : StackFrame(Frame), Satisfied(false) {} - virtual void Profile(llvm::FoldingSetNodeID &ID) const { + static void *getTag() { static int Tag = 0; - ID.AddPointer(&Tag); + return static_cast<void *>(&Tag); + } + + virtual void Profile(llvm::FoldingSetNodeID &ID) const { + ID.AddPointer(ReturnVisitor::getTag()); ID.AddPointer(StackFrame); } @@ -215,10 +219,6 @@ public: // Don't print any more notes after this one. Satisfied = true; - // Build an appropriate message based on the return value. - SmallString<64> Msg; - llvm::raw_svector_ostream Out(Msg); - const Expr *RetE = Ret->getRetValue(); assert(RetE && "Tracking a return value for a void function"); RetE = RetE->IgnoreParenCasts(); @@ -234,7 +234,18 @@ public: // If we're returning 0, we should track where that 0 came from. bugreporter::trackNullOrUndefValue(N, RetE, BR); + // Build an appropriate message based on the return value. + SmallString<64> Msg; + llvm::raw_svector_ostream Out(Msg); + if (isa<Loc>(V)) { + // If we are pruning null-return paths as unlikely error paths, mark the + // report invalid. We still want to emit a path note, however, in case + // the report is resurrected as valid later on. + ExprEngine &Eng = BRC.getBugReporter().getEngine(); + if (Eng.getAnalysisManager().options.shouldPruneNullReturnPaths()) + BR.markInvalid(ReturnVisitor::getTag(), StackFrame); + if (RetE->getType()->isObjCObjectPointerType()) Out << "Returning nil"; else |