[Sema] Fix a miscompile by retaining array qualifiers when folding VLAs to constant...
authorErik Pilkington <erik.pilkington@gmail.com>
Tue, 15 Dec 2020 22:00:20 +0000 (17:00 -0500)
committerErik Pilkington <erik.pilkington@gmail.com>
Wed, 16 Dec 2020 15:01:24 +0000 (10:01 -0500)
rdar://72243125

Differential revision: https://reviews.llvm.org/D93247

clang/lib/Sema/SemaDecl.cpp
clang/test/SemaObjC/arc.m

index 0031f87..6c438f3 100644 (file)
@@ -5965,8 +5965,9 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
     return QualType();
   }
 
-  return Context.getConstantArrayType(ElemTy, Res, VLATy->getSizeExpr(),
-                                      ArrayType::Normal, 0);
+  QualType FoldedArrayType = Context.getConstantArrayType(
+      ElemTy, Res, VLATy->getSizeExpr(), ArrayType::Normal, 0);
+  return Qs.apply(Context, FoldedArrayType);
 }
 
 static void
index fe5db9c..bcd2f99 100644 (file)
@@ -839,3 +839,15 @@ void block_capture_autoreleasing(A * __autoreleasing *a,
     (void)*l;
   }();
 }
+
+void test_vla_fold_keeps_strong(void) {
+  const unsigned bounds = 1;
+
+  static id array[bounds]; // expected-warning {{variable length array folded to constant array as an extension}}
+  typedef __typeof__(array) array_type;
+  typedef id __strong array_type[1];
+
+  static id weak_array[bounds] __weak; // expected-warning {{variable length array folded to constant array as an extension}}
+  typedef __typeof__(weak_array) weak_array_type;
+  typedef id __weak weak_array_type[1];
+}