Author: Akira Hatanaka
Date: 2026-09-18T06:56:46-07:00
New Revision: c4b7e08e60f5b0918795d246dc39ae834d492009

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

LOG: Call FileID::getOpaqueValue() instead of getHashValue() for file identity 
(#224510)

The HTML diagnostics and rewriter code calls FileID::getHashValue() to
get a numeric identifier for each file.

#223794 changes getHashValue() so that it is no longer the identity
function, which breaks tests in clang/test/Analysis/html_diagnostics.

Call getOpaqueValue(), which is equivalent to the current implementation
of getHashValue(), from the HTML diagnostics/rewriter code instead. This
is a no-op today; it only matters once #223794 is reapplied.

Added: 
    

Modified: 
    clang/include/clang/Basic/SourceLocation.h
    clang/lib/Rewrite/HTMLRewrite.cpp
    clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/SourceLocation.h 
b/clang/include/clang/Basic/SourceLocation.h
index b42b7e78622c6..d13b309e56cc6 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -55,6 +55,9 @@ class FileID {
   static FileID getSentinel() { return get(-1); }
   unsigned getHashValue() const { return static_cast<unsigned>(ID); }
 
+  /// Returns the raw integer representation of this FileID.
+  int getOpaqueValue() const { return ID; }
+
 private:
   friend class ASTWriter;
   friend class ASTReader;
@@ -66,8 +69,6 @@ class FileID {
     F.ID = V;
     return F;
   }
-
-  int getOpaqueValue() const { return ID; }
 };
 
 using FileIDAndOffset = std::pair<FileID, unsigned>;

diff  --git a/clang/lib/Rewrite/HTMLRewrite.cpp 
b/clang/lib/Rewrite/HTMLRewrite.cpp
index 37fea7118c91f..1ec89e38bd1e3 100644
--- a/clang/lib/Rewrite/HTMLRewrite.cpp
+++ b/clang/lib/Rewrite/HTMLRewrite.cpp
@@ -293,7 +293,8 @@ void html::AddLineNumbers(Rewriter& R, FileID FID) {
   // Add one big table tag that surrounds all of the code.
   std::string s;
   llvm::raw_string_ostream os(s);
-  os << "<table class=\"code\" data-fileid=\"" << FID.getHashValue() << 
"\">\n";
+  os << "<table class=\"code\" data-fileid=\"" << FID.getOpaqueValue()
+     << "\">\n";
   RB.InsertTextBefore(0, os.str());
   RB.InsertTextAfter(FileEnd - FileBeg, "</table>");
 }

diff  --git a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
index 93f65ec497429..fe9386322a639 100644
--- a/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
@@ -406,11 +406,11 @@ std::string HTMLDiagnostics::GenerateHTML(const 
PathDiagnostic& D, Rewriter &R,
       if (I != FileIDs.begin())
         os << "<hr class=divider>\n";
 
-      os << "<div id=File" << I->getHashValue() << ">\n";
+      os << "<div id=File" << I->getOpaqueValue() << ">\n";
 
       // Left nav arrow
       if (I != FileIDs.begin())
-        os << "<div class=FileNav><a href=\"#File" << (I - 1)->getHashValue()
+        os << "<div class=FileNav><a href=\"#File" << (I - 1)->getOpaqueValue()
            << "\">&#x2190;</a></div>";
 
       os << "<h4 class=FileName>" << SMgr.getFileEntryRefForID(*I)->getName()
@@ -418,7 +418,7 @@ std::string HTMLDiagnostics::GenerateHTML(const 
PathDiagnostic& D, Rewriter &R,
 
       // Right nav arrow
       if (I + 1 != E)
-        os << "<div class=FileNav><a href=\"#File" << (I + 1)->getHashValue()
+        os << "<div class=FileNav><a href=\"#File" << (I + 1)->getOpaqueValue()
            << "\">&#x2192;</a></div>";
 
       os << "</div>\n";
@@ -470,7 +470,7 @@ void HTMLDiagnostics::dumpCoverageData(
     if (I != ExecutedLines.begin())
       os << ", ";
 
-    os << "\"" << I->first.getHashValue() << "\": {";
+    os << "\"" << I->first.getOpaqueValue() << "\": {";
     for (unsigned LineNo : I->second) {
       if (LineNo != *(I->second.begin()))
         os << ", ";


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to