ahatanak created this revision.
ahatanak added reviewers: mizvekov, arphaman, fahad.
ahatanak added a project: clang.
Herald added a project: All.
ahatanak requested review of this revision.

An assertion in `Qualifiers::addObjCLifetime` fails when the ObjC lifetime bits 
are already set.

Instead of calling `operator+=`, call `addConsistentQualifiers`, which allows 
the lifetime bits to be set again as long the new value doesn't conflict with 
the old value.

This fixes https://github.com/llvm/llvm-project/issues/61419.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147263

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaObjCXX/arc-objc-lifetime.mm


Index: clang/test/SemaObjCXX/arc-objc-lifetime.mm
===================================================================
--- clang/test/SemaObjCXX/arc-objc-lifetime.mm
+++ clang/test/SemaObjCXX/arc-objc-lifetime.mm
@@ -66,3 +66,14 @@
 - 
(void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment
 error:(__autoreleasing NSError*&)error {}
 @end
 
+// See https://github.com/llvm/llvm-project/issues/61419
+
+template <class T0, class T1> struct pair {
+  T0 first;
+  T1 second;
+};
+
+NSString *p0, *p1;
+const pair<NSString *, NSString *> p = {p0, p1};
+bool b;
+NSString *t = b ? p.first : p.second;
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -13179,7 +13179,7 @@
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector<SplitQualType, 8> R;
   while (true) {
-    QTotal += T.Quals;
+    QTotal.addConsistentQualifiers(T.Quals);
     QualType NT = T.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
     if (NT == QualType(T.Ty, 0))
       break;


Index: clang/test/SemaObjCXX/arc-objc-lifetime.mm
===================================================================
--- clang/test/SemaObjCXX/arc-objc-lifetime.mm
+++ clang/test/SemaObjCXX/arc-objc-lifetime.mm
@@ -66,3 +66,14 @@
 - (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError*&)error {}
 @end
 
+// See https://github.com/llvm/llvm-project/issues/61419
+
+template <class T0, class T1> struct pair {
+  T0 first;
+  T1 second;
+};
+
+NSString *p0, *p1;
+const pair<NSString *, NSString *> p = {p0, p1};
+bool b;
+NSString *t = b ? p.first : p.second;
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -13179,7 +13179,7 @@
 static auto unwrapSugar(SplitQualType &T, Qualifiers &QTotal) {
   SmallVector<SplitQualType, 8> R;
   while (true) {
-    QTotal += T.Quals;
+    QTotal.addConsistentQualifiers(T.Quals);
     QualType NT = T.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
     if (NT == QualType(T.Ty, 0))
       break;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to