[clang] Call FileID::getOpaqueValue() instead of getHashValue() for file identity (PR #224510)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 21:56:51 PDT 2026
https://github.com/ahatanak updated https://github.com/llvm/llvm-project/pull/224510
>From 4a0ca0f01973a41469820d33c8a45721c57c80b1 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka <ahatanak at gmail.com>
Date: Thu, 17 Sep 2026 14:45:34 -0700
Subject: [PATCH] Call FileID::getOpaqueValue() instead of getHashValue() for
file identity
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.
---
clang/include/clang/Basic/SourceLocation.h | 5 +++--
clang/lib/Rewrite/HTMLRewrite.cpp | 3 ++-
clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp | 8 ++++----
3 files changed, 9 insertions(+), 7 deletions(-)
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()
<< "\">←</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()
<< "\">→</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 << ", ";
More information about the cfe-commits
mailing list