Skip to content

Commit 720870e

Browse files
haoNoQzmodem
authored andcommitted
[analyzer] Fix a couple of bugs in HTML report generation.
It should now produce valid HTML again. Differential Revision: https://reviews.llvm.org/D73993 (cherry picked from commit 482e236)
1 parent e2c0c70 commit 720870e

File tree

5 files changed

+121
-1
lines changed

5 files changed

+121
-1
lines changed

clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,17 @@ window.addEventListener("keydown", function (event) {
607607
)<<<";
608608
}
609609

610+
static bool shouldDisplayPopUpRange(const SourceRange &Range) {
611+
return !(Range.getBegin().isMacroID() || Range.getEnd().isMacroID());
612+
}
613+
610614
static void
611615
HandlePopUpPieceStartTag(Rewriter &R,
612616
const std::vector<SourceRange> &PopUpRanges) {
613617
for (const auto &Range : PopUpRanges) {
618+
if (!shouldDisplayPopUpRange(Range))
619+
continue;
620+
614621
html::HighlightRange(R, Range.getBegin(), Range.getEnd(), "",
615622
"<table class='variable_popup'><tbody>",
616623
/*IsTokenRange=*/true);
@@ -626,6 +633,8 @@ static void HandlePopUpPieceEndTag(Rewriter &R,
626633
llvm::raw_svector_ostream Out(Buf);
627634

628635
SourceRange Range(Piece.getLocation().asRange());
636+
if (!shouldDisplayPopUpRange(Range))
637+
return;
629638

630639
// Write out the path indices with a right arrow and the message as a row.
631640
Out << "<tr><td valign='top'><div class='PathIndex PathIndexPopUp'>"
@@ -870,7 +879,7 @@ void HTMLDiagnostics::HandlePiece(Rewriter &R, FileID BugFileID,
870879
<< (num - 1)
871880
<< "\" title=\"Previous event ("
872881
<< (num - 1)
873-
<< ")\">&#x2190;</a></div></td>";
882+
<< ")\">&#x2190;</a></div>";
874883
}
875884

876885
os << "</td><td>";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
void foo() {
10+
int a;
11+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
12+
}
13+
14+
// CHECK-LABEL: <div id="EndPath" class="msg msgEvent" style="margin-left:3ex">
15+
// CHECK-SAME: <table class="msgT">
16+
// CHECK-SAME: <tr>
17+
// CHECK-SAME: <td valign="top">
18+
// CHECK-SAME: <div class="PathIndex PathIndexEvent">2</div>
19+
// CHECK-SAME: </td>
20+
// CHECK-SAME: <td>
21+
// CHECK-SAME: <div class="PathNav">
22+
// CHECK-SAME: <a href="#Path1" title="Previous event (1)">&#x2190;</a>
23+
// CHECK-SAME: </div>
24+
// CHECK-SAME: </td>
25+
// CHECK-NOT: </td>
26+
// CHECK-SAME: <td>
27+
// CHECK-SAME: 1st function call argument is an uninitialized value
28+
// CHECK-SAME: </td>
29+
// CHECK-SAME: </tr>
30+
// CHECK-SAME: </table>
31+
// CHECK-SAME: </div>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
#define MACRO if (b)
10+
11+
void foo2() {
12+
int a;
13+
int b = 1;
14+
MACRO
15+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
16+
}
17+
18+
// For now we don't emit popups inside macros due to UI limitations.
19+
// Once we do, we should test it thoroughly.
20+
21+
// CHECK-LABEL: <tr class="codeline" data-linenumber="14">
22+
// CHECK-NOT: <span class='variable'>
23+
// CHECK-SAME: <span class='macro'>
24+
// CHECK-SAME: MACRO
25+
// CHECK-SAME: <span class='macro_popup'>
26+
// CHECK-SAME: if (b)
27+
// CHECK-SAME: </span>
28+
// CHECK-SAME: </span>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
void foo() {
10+
int a;
11+
for (unsigned i = 0; i < 3; ++i)
12+
if (i)
13+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
14+
}
15+
16+
// CHECK: <span class='variable'>i
17+
// CHECK-SAME: <table class='variable_popup'><tbody><tr>
18+
// CHECK-SAME: <td valign='top'>
19+
// CHECK-SAME: <div class='PathIndex PathIndexPopUp'>2.1</div>
20+
// CHECK-SAME: </td>
21+
// CHECK-SAME: <td>'i' is 0</td>
22+
// CHECK-SAME: </tr>
23+
// CHECK-SAME: <tr>
24+
// CHECK-SAME: <td valign='top'>
25+
// CHECK-SAME: <div class='PathIndex PathIndexPopUp'>4.1</div>
26+
// CHECK-SAME: </td>
27+
// CHECK-SAME: <td>'i' is 1</td>
28+
// CHECK-SAME: </tr></tbody></table>
29+
// CHECK-SAME: </span>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: rm -fR %t
2+
// RUN: mkdir %t
3+
// RUN: %clang_analyze_cc1 -analyzer-checker=core \
4+
// RUN: -analyzer-output=html -o %t -verify %s
5+
// RUN: cat %t/report-*.html | FileCheck %s
6+
7+
void bar(int);
8+
9+
void foo2() {
10+
int a;
11+
int b = 1;
12+
if (b)
13+
bar(a); // expected-warning{{1st function call argument is an uninitialized value}}
14+
}
15+
16+
// CHECK: <span class='variable'>b
17+
// CHECK-SAME: <table class='variable_popup'><tbody><tr>
18+
// CHECK-SAME: <td valign='top'>
19+
// CHECK-SAME: <div class='PathIndex PathIndexPopUp'>1.1</div>
20+
// CHECK-SAME: </td>
21+
// CHECK-SAME: <td>'b' is 1</td>
22+
// CHECK-SAME: </tr></tbody></table>
23+
// CHECK-SAME: </span>

0 commit comments

Comments
 (0)