Skip to content

Commit

Permalink
[analyzer] Fix incorrect link to "note" diagnostics in HTML output
Browse files Browse the repository at this point in the history
IDs of the note list start from 1. Link generated for each note started
with index 0 i.e #Note0, #Note1 and so on.
As a result, first link ("#Note0") was invalid, subsequent links pointed
at wrong note.
Now, generated links to the notes start with index 1 i.e (#Note1, #Note2
and so on.

Patch by Guruprasad Hegde (gruuprasad)!

Fixes #64054

Differential Revision: https://reviews.llvm.org/D156724
  • Loading branch information
gruuprasad authored and steakhal committed Aug 3, 2023
1 parent a1f04b7 commit e73ae74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,11 @@ void HTMLDiagnostics::FinalizeHTML(const PathDiagnostic& D, Rewriter &R,
P->getLocation().asLocation().getExpansionLineNumber();
int ColumnNumber =
P->getLocation().asLocation().getExpansionColumnNumber();
++NumExtraPieces;
os << "<tr><td class=\"rowname\">Note:</td><td>"
<< "<a href=\"#Note" << NumExtraPieces << "\">line "
<< LineNumber << ", column " << ColumnNumber << "</a><br />"
<< P->getString() << "</td></tr>";
++NumExtraPieces;
}
}

Expand Down
22 changes: 22 additions & 0 deletions clang/test/Analysis/html_diagnostics/notes-links.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: rm -fR %t
// RUN: mkdir %t
// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.UninitializedObject \
// RUN: -analyzer-output=html -o %t -verify %s
// RUN: cat %t/report-*.html | FileCheck %s

struct A {
int *iptr;
int a; // expected-note{{uninitialized field 'this->a'}}
int b; // expected-note{{uninitialized field 'this->b'}}

A (int *iptr) : iptr(iptr) {} // expected-warning{{2 uninitialized fields at the end of the constructor call [optin.cplusplus.UninitializedObject]}}
};

void f() {
A a(0);
}

//CHECK: <tr><td class="rowname">Note:</td>
//CHECK-NOT: <a href="#Note0">
//CHECK-SAME: <a href="#Note1">line 9, column 7</a>
//CHECK-SAME: <a href="#Note2">line 10, column 7</a>

0 comments on commit e73ae74

Please sign in to comment.