[clang] [clang] Unique OverflowBehaviorTypes with a UniquingSet (NFC) (PR #223939)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 16 00:54:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch migrates OverflowBehaviorTypes in ASTContext from
llvm::FoldingSet to llvm::UniquingSet.
OverflowBehaviorType keys on a pair of QualType and
OverflowBehaviorKind. Switching to UniquingSet allows us to look up
types with a typed key, eliminating FoldingSetNodeID serialization at
lookup sites and removing OverflowBehaviorType::Profile.
Assisted-by: Antigravity
---
Full diff: https://github.com/llvm/llvm-project/pull/223939.diff
3 Files Affected:
- (modified) clang/include/clang/AST/ASTContext.h (+1-1)
- (modified) clang/include/clang/AST/TypeBase.h (+2-8)
- (modified) clang/lib/AST/ASTContext.cpp (+3-5)
``````````diff
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index 8d48c2b7c2cba..2f7d39599c477 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -315,7 +315,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
DependentBitIntTypes;
mutable llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
- mutable llvm::FoldingSet<OverflowBehaviorType> OverflowBehaviorTypes;
+ mutable llvm::UniquingSet<OverflowBehaviorType> OverflowBehaviorTypes;
mutable llvm::ContextualFoldingSet<HLSLAttributedResourceType, ASTContext &>
HLSLAttributedResourceTypes;
llvm::FoldingSet<HLSLInlineSpirvType> HLSLInlineSpirvTypes;
diff --git a/clang/include/clang/AST/TypeBase.h b/clang/include/clang/AST/TypeBase.h
index 3967f076112de..424a2afee84da 100644
--- a/clang/include/clang/AST/TypeBase.h
+++ b/clang/include/clang/AST/TypeBase.h
@@ -6822,14 +6822,8 @@ class OverflowBehaviorType : public Type, public llvm::FoldingSetNode {
SplitQualType getSplitUnqualifiedType() const;
- void Profile(llvm::FoldingSetNodeID &ID) {
- Profile(ID, UnderlyingType, BehaviorKind);
- }
-
- static void Profile(llvm::FoldingSetNodeID &ID, QualType Underlying,
- OverflowBehaviorKind Kind) {
- ID.AddPointer(Underlying.getAsOpaquePtr());
- ID.AddInteger((int)Kind);
+ std::pair<QualType, OverflowBehaviorKind> getKey() const {
+ return {UnderlyingType, BehaviorKind};
}
static bool classof(const Type *T) {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 1e48613491943..ef3e6e87ec1fe 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5811,11 +5811,9 @@ QualType ASTContext::getOverflowBehaviorType(
assert(!Underlying->isOverflowBehaviorType() &&
"Cannot have underlying types that are themselves OBTs");
- llvm::FoldingSetNodeID ID;
- OverflowBehaviorType::Profile(ID, Underlying, Kind);
llvm::FoldingSetInsertToken Token;
-
- if (OverflowBehaviorType *OBT = OverflowBehaviorTypes.lookup(ID, Token)) {
+ if (OverflowBehaviorType *OBT =
+ OverflowBehaviorTypes.lookup({Underlying, Kind}, Token)) {
return QualType(OBT, 0);
}
@@ -5824,7 +5822,7 @@ QualType ASTContext::getOverflowBehaviorType(
SplitQualType canonSplit = getCanonicalType(Underlying).split();
Canonical = getOverflowBehaviorType(Kind, QualType(canonSplit.Ty, 0));
Canonical = getQualifiedType(Canonical, canonSplit.Quals);
- assert(!OverflowBehaviorTypes.lookup(ID, Token) &&
+ assert(!OverflowBehaviorTypes.lookup({Underlying, Kind}, Token) &&
"Shouldn't be in the map");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/223939
More information about the cfe-commits
mailing list