summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-08 23:17:51 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-08 23:17:51 +0000
commita716a345276c5868d966707b8c23c325be769d19 (patch)
treebc08e0dd6d258a92f026dc1a0116ca16e19562d5 /clang
parent6047163a244dc8c2ac7aebe96a84cf7d8e98cc71 (diff)
downloadbcm5719-llvm-a716a345276c5868d966707b8c23c325be769d19.tar.gz
bcm5719-llvm-a716a345276c5868d966707b8c23c325be769d19.zip
objectiveC blocks: It is impractical to capture
struct variables with flexiable array members in blocks (and lambdas). Issue error instead of crashing in IRGen. // rdar://12655829 llvm-svn: 171912
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td6
-rw-r--r--clang/lib/Sema/SemaExpr.cpp17
-rw-r--r--clang/test/SemaObjCXX/capturing-flexible-array-in-block.mm9
3 files changed, 31 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 494ddfd0902..4d8f2670983 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4224,6 +4224,9 @@ def err_unexpected_interface : Error<
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_ref_flexarray_type : Error<
+ "cannot refer to declaration of structure variable with flexible array member "
+ "inside block">;
def err_ref_array_type : Error<
"cannot refer to declaration with an array type inside block">;
def err_property_not_found : Error<
@@ -4609,6 +4612,9 @@ let CategoryName = "Lambda Issue" in {
def err_lambda_capture_vm_type : Error<
"variable %0 with variably modified type cannot be captured in "
"a lambda expression">;
+ def err_lambda_capture_flexarray_type : Error<
+ "variable %0 with flexible array member cannot be captured in "
+ "a lambda expression">;
def err_lambda_impcap : Error<
"variable %0 cannot be implicitly captured in a lambda with no "
"capture-default specified">;
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 1704de6e95e..b5630ecb121 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10759,7 +10759,22 @@ bool Sema::tryCaptureVariable(VarDecl *Var, SourceLocation Loc,
}
return true;
}
-
+ // Prohibit prohibit structs with flexisble array members too.
+ // We cannot capture what is in the tail end of the struct.
+ if (const RecordType *VTTy = Var->getType()->getAs<RecordType>()) {
+ if (VTTy->getDecl()->hasFlexibleArrayMember()) {
+ if (BuildAndDiagnose) {
+ if (IsBlock)
+ Diag(Loc, diag::err_ref_flexarray_type);
+ else
+ Diag(Loc, diag::err_lambda_capture_flexarray_type)
+ << Var->getDeclName();
+ Diag(Var->getLocation(), diag::note_previous_decl)
+ << Var->getDeclName();
+ }
+ return true;
+ }
+ }
// Lambdas are not allowed to capture __block variables; they don't
// support the expected semantics.
if (IsLambda && HasBlocksAttr) {
diff --git a/clang/test/SemaObjCXX/capturing-flexible-array-in-block.mm b/clang/test/SemaObjCXX/capturing-flexible-array-in-block.mm
new file mode 100644
index 00000000000..4899c4653a6
--- /dev/null
+++ b/clang/test/SemaObjCXX/capturing-flexible-array-in-block.mm
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -fblocks -verify -std=c++11 %s
+// rdar://12655829
+
+void f() {
+ struct { int x; int y[]; } a; // expected-note 2 {{'a' declared here}}
+ ^{return a.x;}(); // expected-error {{cannot refer to declaration of structure variable with flexible array member inside block}}
+
+ [] {return a.x;}(); // expected-error {{variable 'a' with flexible array member cannot be captured in a lambda expression}}
+}
OpenPOWER on IntegriCloud