aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2010-01-05 02:56:35 +0000
committerMike Stump <mrs@apple.com>2010-01-05 02:56:35 +0000
commit0d6fd570e52f5d7fc637c9f41382992a97b94b4c (patch)
tree60629d860f461ff7d9387b0b7d9f0cd1489d4dfe
parentde0d26310191215a6d1d189dc419f87af18ce6be (diff)
Disallow capturing vlas inside blocks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92676 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaExpr.cpp6
-rw-r--r--test/Sema/block-misc.c12
3 files changed, 19 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 14271c8d90..1f8934e076 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1721,6 +1721,8 @@ def warn_printf_nonliteral : Warning<
def err_unexpected_interface : Error<
"unexpected interface name %0: expected expression">;
def err_ref_non_value : Error<"%0 does not refer to a value">;
+def err_ref_vm_type : Error<
+ "cannot refer to declaration with a variably modified type inside block">;
def err_property_not_found : Error<
"property %0 not found on object of type %1">;
def err_duplicate_property : Error<
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d291cbb394..f0d39dde9f 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1531,6 +1531,12 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS,
// as they do not get snapshotted.
//
if (CurBlock && ShouldSnapshotBlockValueReference(CurBlock, VD)) {
+ if (VD->getType().getTypePtr()->isVariablyModifiedType()) {
+ Diag(Loc, diag::err_ref_vm_type);
+ Diag(D->getLocation(), diag::note_declared_at);
+ return ExprError();
+ }
+
MarkDeclarationReferenced(Loc, VD);
QualType ExprTy = VD->getType().getNonReferenceType();
// The BlocksAttr indicates the variable is bound by-reference.
diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c
index 9f1bc4025f..bc30552302 100644
--- a/test/Sema/block-misc.c
+++ b/test/Sema/block-misc.c
@@ -197,4 +197,14 @@ L0:
return x;
}
-
+// radr://7438948
+void test20() {
+ int n = 7;
+ int vla[n]; // expected-note {{declared at}}
+ int (*vm)[n] = 0; // expected-note {{declared at}}
+ vla[1] = 4341;
+ ^{
+ (void)vla[1]; // expected-error {{cannot refer to declaration with a variably modified type inside block}}
+ (void)(vm+1); // expected-error {{cannot refer to declaration with a variably modified type inside block}}
+ }();
+}