r283499 - [analyzer] Add explanation why analyzer report is not generated (fix for PR12421).

Anton Yartsev via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 14:42:22 PDT 2016


Author: ayartsev
Date: Thu Oct  6 16:42:21 2016
New Revision: 283499

URL: http://llvm.org/viewvc/llvm-project?rev=283499&view=rev
Log:
[analyzer] Add explanation why analyzer report is not generated (fix for PR12421).

Currently if the path diagnostic consumer (e.g HTMLDiagnostics and PlistDiagnostics) do not support cross file diagnostics then the path diagnostic report is silently omitted in the case of cross file diagnostics. The patch adds a little verbosity to Clang in this case.
The patch also adds help entry for the "--analyzer-output" driver option.

Added:
    cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.c
    cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.h
Modified:
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=283499&r1=283498&r2=283499&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Oct  6 16:42:21 2016
@@ -2005,7 +2005,8 @@ def _CLASSPATH : Separate<["--"], "CLASS
 def _all_warnings : Flag<["--"], "all-warnings">, Alias<Wall>;
 def _analyze_auto : Flag<["--"], "analyze-auto">, Flags<[DriverOption]>;
 def _analyzer_no_default_checks : Flag<["--"], "analyzer-no-default-checks">, Flags<[DriverOption]>;
-def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, Flags<[DriverOption]>;
+def _analyzer_output : JoinedOrSeparate<["--"], "analyzer-output">, Flags<[DriverOption]>,
+  HelpText<"Static analyzer report output format (html|plist|plist-multi-file|plist-html|text).">;
 def _analyze : Flag<["--"], "analyze">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Run the static analyzer">;
 def _assemble : Flag<["--"], "assemble">, Alias<S>;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=283499&r1=283498&r2=283499&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Thu Oct  6 16:42:21 2016
@@ -211,6 +211,12 @@ void PathDiagnosticConsumer::HandlePathD
     const SourceManager &SMgr = D->path.front()->getLocation().getManager();
     SmallVector<const PathPieces *, 5> WorkList;
     WorkList.push_back(&D->path);
+    SmallString<128> buf;
+    llvm::raw_svector_ostream warning(buf);
+    warning << "warning: Path diagnostic report is not generated. Current "
+            << "output format does not support diagnostics that cross file "
+            << "boundaries. Refer to --analyzer-output for valid output "
+            << "formats\n";
 
     while (!WorkList.empty()) {
       const PathPieces &path = *WorkList.pop_back_val();
@@ -222,19 +228,25 @@ void PathDiagnosticConsumer::HandlePathD
 
         if (FID.isInvalid()) {
           FID = SMgr.getFileID(L);
-        } else if (SMgr.getFileID(L) != FID)
-          return; // FIXME: Emit a warning?
+        } else if (SMgr.getFileID(L) != FID) {
+          llvm::errs() << warning.str();
+          return;
+        }
 
         // Check the source ranges.
         ArrayRef<SourceRange> Ranges = piece->getRanges();
         for (ArrayRef<SourceRange>::iterator I = Ranges.begin(),
                                              E = Ranges.end(); I != E; ++I) {
           SourceLocation L = SMgr.getExpansionLoc(I->getBegin());
-          if (!L.isFileID() || SMgr.getFileID(L) != FID)
-            return; // FIXME: Emit a warning?
+          if (!L.isFileID() || SMgr.getFileID(L) != FID) {
+            llvm::errs() << warning.str();
+            return;
+          }
           L = SMgr.getExpansionLoc(I->getEnd());
-          if (!L.isFileID() || SMgr.getFileID(L) != FID)
-            return; // FIXME: Emit a warning?
+          if (!L.isFileID() || SMgr.getFileID(L) != FID) {
+            llvm::errs() << warning.str();
+            return;
+          }
         }
 
         if (const PathDiagnosticCallPiece *call =

Added: cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.c?rev=283499&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.c (added)
+++ cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.c Thu Oct  6 16:42:21 2016
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-output=html -o PR12421.html %s 2>&1 | FileCheck %s
+
+// Test for PR12421
+#include "diag-cross-file-boundaries.h"
+
+int main(){
+  f();
+  return 0;
+}
+
+// CHECK: warning: Path diagnostic report is not generated.

Added: cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.h?rev=283499&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.h (added)
+++ cfe/trunk/test/Analysis/diagnostics/diag-cross-file-boundaries.h Thu Oct  6 16:42:21 2016
@@ -0,0 +1,4 @@
+static void f() {
+  int *p = 0;
+  *p = 1;       // expected-warning{{Dereference of null pointer}}
+}




More information about the cfe-commits mailing list