[clang] e73ae74 - [analyzer] Fix incorrect link to "note" diagnostics in HTML output

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 3 02:44:36 PDT 2023


Author: Guruprasad Hegde
Date: 2023-08-03T11:44:05+02:00
New Revision: e73ae745b0d660d3974c04b2281575f325971338

URL: https://github.com/llvm/llvm-project/commit/e73ae745b0d660d3974c04b2281575f325971338
DIFF: https://github.com/llvm/llvm-project/commit/e73ae745b0d660d3974c04b2281575f325971338.diff

LOG: [analyzer] Fix incorrect link to "note" diagnostics in HTML output

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 https://github.com/llvm/llvm-project/issues/64054

Differential Revision: https://reviews.llvm.org/D156724

Added: 
    clang/test/Analysis/html_diagnostics/notes-links.cpp

Modified: 
    clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 0fe0c93dc01653..f91a51cc5f8f6a 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -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;
       }
     }
 

diff  --git a/clang/test/Analysis/html_diagnostics/notes-links.cpp b/clang/test/Analysis/html_diagnostics/notes-links.cpp
new file mode 100644
index 00000000000000..856cc5f41ef6ed
--- /dev/null
+++ b/clang/test/Analysis/html_diagnostics/notes-links.cpp
@@ -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>


        


More information about the cfe-commits mailing list