================
@@ -11710,6 +11809,48 @@ QualType ASTContext::mergeTagDefinitions(QualType LHS, 
QualType RHS) {
   return Ctx.IsEquivalent(LHS, RHS) ? LHS : QualType{};
 }
 
+std::optional<QualType> ASTContext::tryMergeOverflowBehaviorTypes(
+    QualType LHS, QualType RHS, bool OfBlockPointer, bool Unqualified,
+    bool BlockReturnType, bool IsConditionalOperator) {
+  const auto *LHSOBT = LHS->getAs<OverflowBehaviorType>();
+  const auto *RHSOBT = RHS->getAs<OverflowBehaviorType>();
+
+  if (!LHSOBT && !RHSOBT)
+    return std::nullopt;
+
+  if (LHSOBT) {
+    if (RHSOBT) {
+      // Both are OverflowBehaviorTypes.
+      if (LHSOBT->getBehaviorKind() != RHSOBT->getBehaviorKind())
+        return QualType(); // Incompatible if behaviors differ.
+
+      QualType MergedUnderlying = mergeTypes(
+          LHSOBT->getUnderlyingType(), RHSOBT->getUnderlyingType(),
+          OfBlockPointer, Unqualified, BlockReturnType, IsConditionalOperator);
+
+      if (MergedUnderlying.isNull())
+        return QualType();
+
+      // If the merged underlying type is the same as one of the original
+      // underlying types, we can return the original OBT to preserve typedefs.
+      if (getCanonicalType(MergedUnderlying) ==
+          getCanonicalType(LHSOBT->getUnderlyingType()))
+        return LHS;
+      if (getCanonicalType(MergedUnderlying) ==
+          getCanonicalType(RHSOBT->getUnderlyingType()))
+        return RHS;
----------------
JustinStitt wrote:

I agree, I am no longer choosing an arbitrary typedef if the canonical types 
match. There is more nuanced merging introduced by fixed with 
[`04af8bf`](https://github.com/llvm/llvm-project/pull/148914/commits/04af8bf6e9620c71673a435d3b2eebccd7db3682)
 which includes tests.

https://github.com/llvm/llvm-project/pull/148914
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to