]> granicus.if.org Git - clang/commitdiff
Disallow capturing vlas inside blocks.
authorMike Stump <mrs@apple.com>
Tue, 5 Jan 2010 02:56:35 +0000 (02:56 +0000)
committerMike Stump <mrs@apple.com>
Tue, 5 Jan 2010 02:56:35 +0000 (02:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92676 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/block-misc.c

index 14271c8d90723347d17c320ab038a75b65da716f..1f8934e076a2f29f21bd3c402c590ffbe47f6edb 100644 (file)
@@ -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<
index d291cbb394a53e5d4f3bef007b409cbedcb863e8..f0d39dde9f458caecb8eac6fbcfc78d17b0ac0de 100644 (file)
@@ -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.
index 9f1bc4025fac689da7d20f7c7372e5a3126aa8a2..bc30552302e5d6351c6093f11aeb1ca83f9dc5c7 100644 (file)
@@ -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}}
+  }();
+}