[clang] 2ba8844 - Fix an assertion failure in unwrapSugar

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 12 16:48:34 PDT 2023


Author: Akira Hatanaka
Date: 2023-04-12T16:45:56-07:00
New Revision: 2ba88443b31a437a3e80ac4bb6d8ca1675828d1b

URL: https://github.com/llvm/llvm-project/commit/2ba88443b31a437a3e80ac4bb6d8ca1675828d1b
DIFF: https://github.com/llvm/llvm-project/commit/2ba88443b31a437a3e80ac4bb6d8ca1675828d1b.diff

LOG: Fix an assertion failure in unwrapSugar

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.

Differential Revision: https://reviews.llvm.org/D147263

Added: 
    

Modified: 
    clang/lib/AST/ASTContext.cpp
    clang/test/SemaCXX/sugar-common-types.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 6f36b056c7bb9..87c908ae5f561 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13082,7 +13082,7 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
 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;

diff  --git a/clang/test/SemaCXX/sugar-common-types.cpp b/clang/test/SemaCXX/sugar-common-types.cpp
index 1932ccd9c7250..f4e545bb9bceb 100644
--- a/clang/test/SemaCXX/sugar-common-types.cpp
+++ b/clang/test/SemaCXX/sugar-common-types.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -fenable-matrix -triple i686-pc-win32
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++20 -x objective-c++ -fobjc-arc -fenable-matrix -triple i686-pc-win32
 
 enum class N {};
 
@@ -131,3 +131,14 @@ using UPY1 = C::type1;
 auto t32 = 0 ? (UPX1){} : (UPY1){};
 N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
 N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+// See https://github.com/llvm/llvm-project/issues/61419
+namespace PR61419 {
+  template <class T0, class T1> struct pair {
+    T0 first;
+    T1 second;
+  };
+
+  extern const pair<id, id> p;
+  id t = false ? p.first : p.second;
+} // namespace PR61419


        


More information about the cfe-commits mailing list