================
@@ -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;
----------------
mizvekov wrote:

If the RHS and LHS underlying types are the same type, this should use 
`ASTContext::getCommonSugaredType`.
If the merged type is not the same, I don't think it makes sense to arbitrarily 
pick the typedefs of one side or the other.

For example, if one side is `pid_t`, the other side is `clockid_t`, I don't 
think picking either one as the result is sensible.



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