[clang] [Clang] Introduce OverflowBehaviorType for fine-grained overflow control (PR #148914)
Justin Stitt via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 25 15:54:44 PDT 2025
================
@@ -5776,6 +5826,51 @@ QualType ASTContext::getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
return QualType(Ty, 0);
}
+QualType ASTContext::getOverflowBehaviorType(const OverflowBehaviorAttr *Attr,
+ QualType Underlying) const {
+ IdentifierInfo *II = Attr->getBehaviorKind();
+ StringRef IdentName = II->getName();
+ OverflowBehaviorType::OverflowBehaviorKind Kind;
+ if (IdentName == "wrap") {
+ Kind = OverflowBehaviorType::OverflowBehaviorKind::Wrap;
+ } else if (IdentName == "no_wrap") {
+ Kind = OverflowBehaviorType::OverflowBehaviorKind::NoWrap;
+ } else {
+ return Underlying;
+ }
+
+ return getOverflowBehaviorType(Kind, Underlying);
+}
+
+QualType ASTContext::getOverflowBehaviorType(
+ OverflowBehaviorType::OverflowBehaviorKind Kind,
+ QualType Underlying) const {
+ llvm::FoldingSetNodeID ID;
+ OverflowBehaviorType::Profile(ID, Underlying, Kind);
+ void *InsertPos = nullptr;
+
+ if (OverflowBehaviorType *OBT =
+ OverflowBehaviorTypes.FindNodeOrInsertPos(ID, InsertPos)) {
+ return QualType(OBT, 0);
+ }
+
+ QualType Canonical;
+ if (!Underlying.isCanonical()) {
+ Canonical = getOverflowBehaviorType(Kind, getCanonicalType(Underlying));
+ OverflowBehaviorType *NewOBT =
+ OverflowBehaviorTypes.FindNodeOrInsertPos(ID, InsertPos);
+ assert(!NewOBT && "Shouldn't be in the map!");
+ (void)NewOBT;
----------------
JustinStitt wrote:
fixed in fixed with [`04af8bf`](https://github.com/llvm/llvm-project/pull/148914/commits/04af8bf6e9620c71673a435d3b2eebccd7db3682)
https://github.com/llvm/llvm-project/pull/148914
More information about the cfe-commits
mailing list