[cfe-commits] r67353 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaInit.cpp test/CodeGen/flexible-array-init.c test/Sema/array-init.c test/Sema/flexible-array-init.c
Douglas Gregor
dgregor at apple.com
Thu Mar 19 17:32:56 PDT 2009
Author: dgregor
Date: Thu Mar 19 19:32:56 2009
New Revision: 67353
URL: http://llvm.org/viewvc/llvm-project?rev=67353&view=rev
Log:
Allow flexible array initializers that are not surrounded by
braces. We now build the appropriate fully-structured initializer list
for such things. Per PR3618, verified that we're getting the right
code generation.
Added:
cfe/trunk/test/CodeGen/flexible-array-init.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/array-init.c
cfe/trunk/test/Sema/flexible-array-init.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67353&r1=67352&r2=67353&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 19 19:32:56 2009
@@ -66,6 +66,8 @@
"designator into flexible array member subobject">;
def note_flexible_array_member : Note<
"initialized flexible array member %0 is here">;
+def ext_flexible_array_init : Extension<
+ "flexible array initialization is a GNU extension">;
// Declarations.
def ext_vla : Extension<
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=67353&r1=67352&r2=67353&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Mar 19 19:32:56 2009
@@ -481,7 +481,8 @@
StructuredSubobjectInitIndex,
TopLevelObject);
unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
-
+ StructuredSubobjectInitList->setType(T);
+
// Update the structured sub-object initializer so that it's ending
// range corresponds with the end of the last initializer it used.
if (EndIndex < ParentIList->getNumInits()) {
@@ -995,23 +996,35 @@
}
if (Field == FieldEnd || !Field->getType()->isIncompleteArrayType() ||
- Index >= IList->getNumInits() ||
- !isa<InitListExpr>(IList->getInit(Index)))
+ Index >= IList->getNumInits())
return;
// Handle GNU flexible array initializers.
if (!TopLevelObject &&
- cast<InitListExpr>(IList->getInit(Index))->getNumInits() > 0) {
+ (!isa<InitListExpr>(IList->getInit(Index)) ||
+ cast<InitListExpr>(IList->getInit(Index))->getNumInits() > 0)) {
SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(),
diag::err_flexible_array_init_nonempty)
<< IList->getInit(Index)->getSourceRange().getBegin();
SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
<< *Field;
hadError = true;
+ ++Index;
+ return;
+ } else {
+ SemaRef.Diag(IList->getInit(Index)->getSourceRange().getBegin(),
+ diag::ext_flexible_array_init)
+ << IList->getInit(Index)->getSourceRange().getBegin();
+ SemaRef.Diag(Field->getLocation(), diag::note_flexible_array_member)
+ << *Field;
}
- CheckSubElementType(IList, Field->getType(), Index, StructuredList,
- StructuredIndex);
+ if (isa<InitListExpr>(IList->getInit(Index)))
+ CheckSubElementType(IList, Field->getType(), Index, StructuredList,
+ StructuredIndex);
+ else
+ CheckImplicitInitList(IList, Field->getType(), Index, StructuredList,
+ StructuredIndex);
}
/// @brief Check the well-formedness of a C99 designated initializer.
Added: cfe/trunk/test/CodeGen/flexible-array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/flexible-array-init.c?rev=67353&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/flexible-array-init.c (added)
+++ cfe/trunk/test/CodeGen/flexible-array-init.c Thu Mar 19 19:32:56 2009
@@ -0,0 +1,8 @@
+// RUN: clang -triple i386-unknown-unknown -emit-llvm -o - %s | grep 7 | count 1 &&
+// RUN: clang -triple i386-unknown-unknown -emit-llvm -o - %s | grep 11 | count 1 &&
+// RUN: clang -triple i386-unknown-unknown -emit-llvm -o - %s | grep 13 | count 1 &&
+// RUN: clang -triple i386-unknown-unknown -emit-llvm -o - %s | grep 15 | count 1
+
+struct { int x; int y[]; } a = { 1, 7, 11 };
+
+struct { int x; int y[]; } b = { 1, { 13, 15 } };
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=67353&r1=67352&r2=67353&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Thu Mar 19 19:32:56 2009
@@ -201,8 +201,8 @@
return z.z;
}
struct s3 {void (*a)(void);} t5 = {autoStructTest};
-// Note that clang objc implementation depends on this extension.
-struct {int a; int b[];} t6 = {1, {1, 2, 3}};
+struct {int a; int b[];} t6 = {1, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}} \
+// expected-note{{initialized flexible array member 'b' is here}}
union {char a; int b;} t7[] = {1, 2, 3};
int t8[sizeof t7 == (3*sizeof(int)) ? 1 : -1];
Modified: cfe/trunk/test/Sema/flexible-array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/flexible-array-init.c?rev=67353&r1=67352&r2=67353&view=diff
==============================================================================
--- cfe/trunk/test/Sema/flexible-array-init.c (original)
+++ cfe/trunk/test/Sema/flexible-array-init.c Thu Mar 19 19:32:56 2009
@@ -1,24 +1,24 @@
// RUN: clang -fsyntax-only -pedantic -verify %s
struct one {
int a;
- int values[];
-} x = {5, {1, 2, 3}};
+ int values[]; // expected-note 3{{initialized flexible array member 'values' is here}}
+} x = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
-struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{excess elements in struct initializer}}
+struct one x2 = { 5, 1, 2, 3 }; // expected-warning{{flexible array initialization is a GNU extension}}
void test() {
- struct one x3 = {5, {1, 2, 3}};
+ struct one x3 = {5, {1, 2, 3}}; // expected-warning{{flexible array initialization is a GNU extension}}
}
struct foo {
int x;
- int y[]; // expected-note 4 {{initialized flexible array member 'y' is here}}
+ int y[]; // expected-note 6 {{initialized flexible array member 'y' is here}}
};
struct bar { struct foo z; }; // expected-warning {{'z' may not be nested in a struct due to flexible array member}}
-struct foo a = { 1, { 2, 3, 4 } }; // Valid.
+struct foo a = { 1, { 2, 3, 4 } }; // expected-warning{{flexible array initialization is a GNU extension}}
struct bar b = { { 1, { 2, 3, 4 } } }; // expected-error{{non-empty initialization of flexible array member inside subobject}}
-struct bar c = { { 1, { } } }; // Valid. \
+struct bar c = { { 1, { } } }; // // expected-warning{{flexible array initialization is a GNU extension}} \
// expected-warning{{use of GNU empty initializer extension}} \
// expected-warning{{zero size arrays are an extension}}
struct foo d[1] = { { 1, { 2, 3, 4 } } }; // expected-warning{{'struct foo' may not be used as an array element due to flexible array member}} \
More information about the cfe-commits
mailing list