[clang] [ObjC] Fix Assertion failure when merging declarations with different lifetime qualifiers (PR #203272)

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 17 12:49:49 PDT 2026


Hendrik =?utf-8?q?Hübner?= <hhuebner at MacBookPro.localdomain>,
Hendrik =?utf-8?q?Hübner?= <hhuebner at MacBookPro.lan>,
Hendrik =?utf-8?q?Hübner?= <hhuebner at MacBookPro.localdomain>,
Hendrik =?utf-8?q?Hübner?= <hhuebner at MacBookPro.localdomain>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/203272 at github.com>


================
@@ -12353,20 +12353,20 @@ QualType ASTContext::mergeObjCGCQualifiers(QualType LHS, QualType RHS) {
   // If the qualifiers are different, the types can still be merged.
   Qualifiers LQuals = LHSCan.getLocalQualifiers();
   Qualifiers RQuals = RHSCan.getLocalQualifiers();
-  if (LQuals != RQuals) {
-    // If any of these qualifiers are different, we have a type mismatch.
-    if (LQuals.getCVRQualifiers() != RQuals.getCVRQualifiers() ||
-        LQuals.getAddressSpace() != RQuals.getAddressSpace())
-      return {};
 
+  if (LQuals.withoutObjCGCAttr() != RQuals.withoutObjCGCAttr()) {
+    // Reject immediately, if anything but the GC qualifiers is different.
+    return {};
+  }
+
+  if (LQuals != RQuals) {
     // Exactly one GC qualifier difference is allowed: __strong is
     // okay if the other type has no GC qualifier but is an Objective
     // C object pointer (i.e. implicitly strong by default).  We fix
     // this by pretending that the unqualified type was actually
     // qualified __strong.
     Qualifiers::GC GC_L = LQuals.getObjCGCAttr();
     Qualifiers::GC GC_R = RQuals.getObjCGCAttr();
-    assert((GC_L != GC_R) && "unequal qualifier sets had only equal elements");
----------------
ahatanak wrote:

I think we want to keep this assert, unless there's a reason to remove it.

https://github.com/llvm/llvm-project/pull/203272


More information about the cfe-commits mailing list