Skip to content

Commit

Permalink
[Sema] Fix a miscompile by retaining array qualifiers when folding VL…
Browse files Browse the repository at this point in the history
…As to constant arrays

rdar://72243125

Differential revision: https://reviews.llvm.org/D93247
  • Loading branch information
epilk committed Dec 16, 2020
1 parent d61ccda commit 95b2dab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaObjC/arc.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

0 comments on commit 95b2dab

Please sign in to comment.