diff --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp --- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp +++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp @@ -607,10 +607,17 @@ )<<<"; } +static bool shouldDisplayPopUpRange(const SourceRange &Range) { + return !(Range.getBegin().isMacroID() || Range.getEnd().isMacroID()); +} + static void HandlePopUpPieceStartTag(Rewriter &R, const std::vector &PopUpRanges) { for (const auto &Range : PopUpRanges) { + if (!shouldDisplayPopUpRange(Range)) + continue; + html::HighlightRange(R, Range.getBegin(), Range.getEnd(), "", "", /*IsTokenRange=*/true); @@ -626,6 +633,8 @@ llvm::raw_svector_ostream Out(Buf); SourceRange Range(Piece.getLocation().asRange()); + if (!shouldDisplayPopUpRange(Range)) + return; // Write out the path indices with a right arrow and the message as a row. Out << ""; + << ")\">←"; } os << " +// CHECK-NOT: +// CHECK-SAME: +// CHECK-SAME: MACRO +// CHECK-SAME: +// CHECK-SAME: if (b) +// CHECK-SAME: +// CHECK-SAME: diff --git a/clang/test/Analysis/html_diagnostics/variable-popups-multiple.c b/clang/test/Analysis/html_diagnostics/variable-popups-multiple.c new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/html_diagnostics/variable-popups-multiple.c @@ -0,0 +1,29 @@ +// RUN: rm -fR %t +// RUN: mkdir %t +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-output=html -o %t -verify %s +// RUN: cat %t/report-*.html | FileCheck %s + +void bar(int); + +void foo() { + int a; + for (unsigned i = 0; i < 3; ++i) + if (i) + bar(a); // expected-warning{{1st function call argument is an uninitialized value}} +} + +// CHECK: i +// CHECK-SAME:
" @@ -870,7 +879,7 @@ << (num - 1) << "\" title=\"Previous event (" << (num - 1) - << ")\">←
"; diff --git a/clang/test/Analysis/html_diagnostics/td-hotfix.c b/clang/test/Analysis/html_diagnostics/td-hotfix.c new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/html_diagnostics/td-hotfix.c @@ -0,0 +1,31 @@ +// RUN: rm -fR %t +// RUN: mkdir %t +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-output=html -o %t -verify %s +// RUN: cat %t/report-*.html | FileCheck %s + +void bar(int); + +void foo() { + int a; + bar(a); // expected-warning{{1st function call argument is an uninitialized value}} +} + +// CHECK-LABEL:
+// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-NOT: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME:
+// CHECK-SAME:
2
+// CHECK-SAME:
+// CHECK-SAME:
+// CHECK-SAME: +// CHECK-SAME:
+// CHECK-SAME:
+// CHECK-SAME: 1st function call argument is an uninitialized value +// CHECK-SAME:
+// CHECK-SAME:
diff --git a/clang/test/Analysis/html_diagnostics/variable-popups-macro.c b/clang/test/Analysis/html_diagnostics/variable-popups-macro.c new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/html_diagnostics/variable-popups-macro.c @@ -0,0 +1,28 @@ +// RUN: rm -fR %t +// RUN: mkdir %t +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-output=html -o %t -verify %s +// RUN: cat %t/report-*.html | FileCheck %s + +void bar(int); + +#define MACRO if (b) + +void foo2() { + int a; + int b = 1; + MACRO + bar(a); // expected-warning{{1st function call argument is an uninitialized value}} +} + +// For now we don't emit popups inside macros due to UI limitations. +// Once we do, we should test it thoroughly. + +// CHECK-LABEL:
+// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME:
+// CHECK-SAME:
2.1
+// CHECK-SAME:
'i' is 0
+// CHECK-SAME:
4.1
+// CHECK-SAME:
'i' is 1
+// CHECK-SAME: diff --git a/clang/test/Analysis/html_diagnostics/variable-popups-simple.c b/clang/test/Analysis/html_diagnostics/variable-popups-simple.c new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/html_diagnostics/variable-popups-simple.c @@ -0,0 +1,23 @@ +// RUN: rm -fR %t +// RUN: mkdir %t +// RUN: %clang_analyze_cc1 -analyzer-checker=core \ +// RUN: -analyzer-output=html -o %t -verify %s +// RUN: cat %t/report-*.html | FileCheck %s + +void bar(int); + +void foo2() { + int a; + int b = 1; + if (b) + bar(a); // expected-warning{{1st function call argument is an uninitialized value}} +} + +// CHECK: b +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME: +// CHECK-SAME:
+// CHECK-SAME:
1.1
+// CHECK-SAME:
'b' is 1
+// CHECK-SAME: