[PATCH] D147263: Fix an assertion failure in unwrapSugar

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 30 13:19:02 PDT 2023


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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147263.509793.patch
Type: text/x-patch
Size: 1125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230330/5bbf1354/attachment.bin>


More information about the cfe-commits mailing list