[llvm] [DebugInfo] Make DISubprogram's hashing always produce the same result (PR #90770)
Augusto Noronha via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 11:01:07 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))
----------------
augusto2112 wrote:
The `isa_and_nonnull` is there to respect the comment above.
```
// 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().
```
Otherwise we'd use the earlier hash for every declaration.
I guess I could check if `ScopeLinkageName` is set instead, could a composite type have no linkage name?
https://github.com/llvm/llvm-project/pull/90770
More information about the llvm-commits
mailing list