[llvm] [DebugInfo] Make DISubprogram's hashing always produce the same result (PR #90770)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 09:43:53 PDT 2024
================
@@ -825,19 +825,26 @@ template <> struct MDNodeKeyImpl<DISubprogram> {
bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
unsigned getHashValue() const {
+ // Use the Scope's linkage name instead of using the scope directly, as the
+ // scope may be a temporary one which can replaced, which would produce a
+ // different hash for the same DISubprogram.
+ llvm::StringRef ScopeLinkageName;
+ if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
+ if (auto *ID = CT->getRawIdentifier())
+ ScopeLinkageName = ID->getString();
+
// If this is a declaration inside an ODR type, only hash the type and the
// name. Otherwise the hash will be stronger than
// MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
- if (!isDefinition() && LinkageName)
- if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
- if (CT->getRawIdentifier())
- return hash_combine(LinkageName, Scope);
+ if (!isDefinition() && LinkageName &&
+ isa_and_nonnull<DICompositeType>(Scope))
----------------
adrian-prantl wrote:
This check is now redundant.
https://github.com/llvm/llvm-project/pull/90770
More information about the llvm-commits
mailing list