[PATCH] D93247: [Sema] Fix a miscompile by retaining array qualifiers when folding VLAs to constant arrays

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 16 07:02:30 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG95b2dab19910: [Sema] Fix a miscompile by retaining array qualifiers when folding VLAs to… (authored by erik.pilkington).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93247/new/

https://reviews.llvm.org/D93247

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


Index: clang/test/SemaObjC/arc.m
===================================================================
--- clang/test/SemaObjC/arc.m
+++ clang/test/SemaObjC/arc.m
@@ -839,3 +839,15 @@
     (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];
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5965,8 +5965,9 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93247.312201.patch
Type: text/x-patch
Size: 1246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201216/c519d4a4/attachment.bin>


More information about the cfe-commits mailing list