Author: Erik Pilkington Date: 2020-12-16T10:01:24-05:00 New Revision: 95b2dab199100f5a86d3f73a995afea879886d65
URL: https://github.com/llvm/llvm-project/commit/95b2dab199100f5a86d3f73a995afea879886d65 DIFF: https://github.com/llvm/llvm-project/commit/95b2dab199100f5a86d3f73a995afea879886d65.diff LOG: [Sema] Fix a miscompile by retaining array qualifiers when folding VLAs to constant arrays rdar://72243125 Differential revision: https://reviews.llvm.org/D93247 Added: Modified: clang/lib/Sema/SemaDecl.cpp clang/test/SemaObjC/arc.m Removed: ################################################################################ diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 0031f874c05a..6c438f319991 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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 diff --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m index fe5db9ce5384..bcd2f995622c 100644 --- a/clang/test/SemaObjC/arc.m +++ b/clang/test/SemaObjC/arc.m @@ -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]; +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits