<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Apr 1, 2013, at 5:26 PM, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Author: jrose<br>Date: Mon Apr  1 19:26:15 2013<br>New Revision: 178513<br><br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=178513&view=rev">http://llvm.org/viewvc/llvm-project?rev=178513&view=rev</a><br>Log:<br>[analyzer] Allow suppressing diagnostics reported within the 'std' namespace<br><br>This is controlled by the 'suppress-c++-stdlib' analyzer-config flag.<br>It is currently off by default.<br><br>This is more suppression than we'd like to do, since obviously there can<br>be user-caused issues within 'std', but it gives us the option to wield<br>a large hammer to suppress false positives the user likely can't work<br>around.<br><br>Added:<br>   cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp<br>Modified:<br>   cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h<br>   cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp<br>   cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>   cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h<br><br>Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=178513&r1=178512&r2=178513&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=178513&r1=178512&r2=178513&view=diff</a><br>==============================================================================<br>--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)<br>+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Apr  1 19:26:15 2013<br>@@ -217,6 +217,9 @@ private:<br>  /// \sa shouldSuppressInlinedDefensiveChecks<br>  Optional<bool> SuppressInlinedDefensiveChecks;<br><br>+  /// \sa shouldSuppressFromCXXStandardLibrary<br>+  Optional<bool> SuppressFromCXXStandardLibrary;<br>+<br>  /// \sa getGraphTrimInterval<br>  Optional<unsigned> GraphTrimInterval;<br><br>@@ -306,6 +309,13 @@ public:<br>  /// option, which accepts the values "true" and "false".<br>  bool shouldSuppressInlinedDefensiveChecks();<br><br>+  /// Returns whether or not diagnostics reported within the C++ standard<br>+  /// library should be suppressed.<br>+  ///<br>+  /// This is controlled by the 'suppress-c++-stdlib' config option,<br>+  /// which accepts the values "true" and "false".<br>+  bool shouldSuppressFromCXXStandardLibrary();<br>+<br>  /// Returns whether irrelevant parts of a bug report path should be pruned<br>  /// out of the final output.<br>  ///<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=178513&r1=178512&r2=178513&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=178513&r1=178512&r2=178513&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Mon Apr  1 19:26:15 2013<br>@@ -158,6 +158,12 @@ bool AnalyzerOptions::shouldSuppressInli<br>                          /* Default = */ true);<br>}<br><br>+bool AnalyzerOptions::shouldSuppressFromCXXStandardLibrary() {<br>+  return getBooleanOption(SuppressFromCXXStandardLibrary,<br>+                          "suppress-c++-stdlib",<br>+                          /* Default = */ false);<br>+}<br>+<br>int AnalyzerOptions::getOptionAsInteger(StringRef Name, int DefaultVal) {<br>  SmallString<10> StrBuf;<br>  llvm::raw_svector_ostream OS(StrBuf);<br><br>Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=178513&r1=178512&r2=178513&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=178513&r1=178512&r2=178513&view=diff</a><br>==============================================================================<br>--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)<br>+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Mon Apr  1 19:26:15 2013<br>@@ -1421,28 +1421,53 @@ ConditionBRVisitor::VisitTrueTest(const<br>  return event;<br>}<br><br>+<br>+// FIXME: Copied from ExprEngineCallAndReturn.cpp.<br>+static bool isInStdNamespace(const Decl *D) {<br>+  const DeclContext *DC = D->getDeclContext()->getEnclosingNamespaceContext();<br>+  const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC);<br>+  if (!ND)<br>+    return false;<br>+<br>+  while (const NamespaceDecl *Parent = dyn_cast<NamespaceDecl>(ND->getParent()))<br>+    ND = Parent;<br>+<br>+  return ND->getName() == "std";<br>+}<br>+<br>+<br>PathDiagnosticPiece *<br>LikelyFalsePositiveSuppressionBRVisitor::getEndPath(BugReporterContext &BRC,<br>                                                    const ExplodedNode *N,<br>                                                    BugReport &BR) {<br>-  const Stmt *S = BR.getStmt();<br>-  if (!S)<br>-    return 0;<br>-<br>-  // Here we suppress false positives coming from system macros. This list is<br>+  // Here we suppress false positives coming from system headers. This list is<br>  // based on known issues.<br><br>+  // Skip reports within the 'std' namespace. Although these can sometimes be<br>+  // the user's fault, we currently don't report them very well, and<br>+  // Note that this will not help for any other data structure libraries, like<br>+  // TR1, Boost, or llvm/ADT.<br>+  ExprEngine &Eng = BRC.getBugReporter().getEngine();<br>+  AnalyzerOptions &Options = Eng.getAnalysisManager().options;<br>+  if (Options.shouldSuppressFromCXXStandardLibrary()) {<br>+    const LocationContext *LCtx = N->getLocationContext();<br>+    if (isInStdNamespace(LCtx->getDecl())) {<br>+      BR.markInvalid(getTag(), 0);<br>+      return 0;<br>+    }<br>+  }<br>+<br>  // Skip reports within the sys/queue.h macros as we do not have the ability to<br>  // reason about data structure shapes.<br>  SourceManager &SM = BRC.getSourceManager();<br>-  SourceLocation Loc = S->getLocStart();<br>+  FullSourceLoc Loc = BR.getLocation(SM).asLocation();<br>  while (Loc.isMacroID()) {<br>    if (SM.isInSystemMacro(Loc) &&<br>       (SM.getFilename(SM.getSpellingLoc(Loc)).endswith("sys/queue.h"))) {<br>      BR.markInvalid(getTag(), 0);<br>      return 0;<br>    }<br>-    Loc = SM.getSpellingLoc(Loc);<br>+    Loc = Loc.getSpellingLoc();<br>  }<br><br>  return 0;<br><br>Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=178513&r1=178512&r2=178513&view=diff">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=178513&r1=178512&r2=178513&view=diff</a><br>==============================================================================<br>--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original)<br>+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Mon Apr  1 19:26:15 2013<br>@@ -73,6 +73,13 @@ namespace std {<br>  struct nothrow_t {};<br><br>  extern const nothrow_t nothrow;<br>+<br>+  template<class InputIter, class OutputIter><br>+  OutputIter copy(InputIter II, InputIter IE, OutputIter OI) {<br>+    while (II != IE)<br>+      *OI++ = *II++;<br>+    return OI;<br>+  }<br>}<br><br>void* operator new(std::size_t, const std::nothrow_t&) throw();<br><br>Added: cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp<br>URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp?rev=178513&view=auto">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp?rev=178513&view=auto</a><br>==============================================================================<br>--- cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp (added)<br>+++ cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp Mon Apr  1 19:26:15 2013<br>@@ -0,0 +1,71 @@<br>+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config suppress-c++-stdlib=false -verify %s<br>+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-config suppress-c++-stdlib=true -DSUPPRESSED=1 -verify %s<br>+<br>+#ifdef SUPPRESSED<br>+// expected-no-diagnostics<br>+#endif<br>+<br>+#include "../Inputs/system-header-simulator-cxx.h"<br>+<br>+void clang_analyzer_eval(bool);<br>+<br>+void testCopyNull(int *I, int *E) {<br>+  std::copy(I, E, (int *)0);<br>+#ifndef SUPPRESSED<br>+  // This line number comes from system-header-simulator-cxx.h.<br>+  // expected-warning@65 {{Dereference of null pointer}}<br>+#endif<br>+}<br>+<br>+<br></div></blockquote><div><br></div>These new lines are probably unintentional.</div><div><br><blockquote type="cite"><div style="letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+<br>+// PR15613: expected-* can't refer to diagnostics in other source files.<br>+// The current implementation only matches line numbers, but has an upper limit<br>+// of the number of lines in the main source file.<br><br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a></div></blockquote></div><br></body></html>