summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-28 21:54:33 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-28 21:54:33 +0000
commit347f7eabb9ae43482f04855cde43f9d164b7b6f0 (patch)
treeb167e4bf7fc08a2d9c09efd46cb7775daed2b521 /clang/test/Sema
parentc78320960513fe9f193104cbb07b0a5711c81ee0 (diff)
downloadbcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.tar.gz
bcm5719-llvm-347f7eabb9ae43482f04855cde43f9d164b7b6f0.zip
Code generation support for C99 designated initializers.
The approach I've taken in this patch is relatively straightforward, although the code itself is non-trivial. Essentially, as we process an initializer list we build up a fully-explicit representation of the initializer list, where each of the subobject initializations occurs in order. Designators serve to "fill in" subobject initializations in a non-linear way. The fully-explicit representation makes initializer lists (both with and without designators) easy to grok for codegen and later semantic analyses. We keep the syntactic form of the initializer list linked into the AST for those clients interested in exactly what the user wrote. Known limitations: - Designating a member of a union that isn't the first member may result in bogus initialization (we warn about this) - GNU array-range designators are not supported (we warn about this) llvm-svn: 63242
Diffstat (limited to 'clang/test/Sema')
-rw-r--r--clang/test/Sema/array-init.c28
-rw-r--r--clang/test/Sema/designated-initializers.c30
-rw-r--r--clang/test/Sema/vector-init.c12
3 files changed, 63 insertions, 7 deletions
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
index 9d2a942410a..3d2cf691274 100644
--- a/clang/test/Sema/array-init.c
+++ b/clang/test/Sema/array-init.c
@@ -1,4 +1,4 @@
-// RUN: clang -fsyntax-only -verify -pedantic %s
+// RUN: clang -fsyntax-only -pedantic -verify %s
extern int foof() = 1; // expected-error{{illegal initializer (only variables can be initialized)}}
@@ -101,6 +101,7 @@ void legal() {
{ 2, 3 },
{ 4, 5, 6 }
};
+ int q_sizecheck[(sizeof(q) / sizeof(short [3][2])) == 3? 1 : -1];
}
unsigned char asso_values[] = { 34 };
@@ -134,15 +135,19 @@ typedef int AryT[];
void testTypedef()
{
AryT a = { 1, 2 }, b = { 3, 4, 5 };
+ int a_sizecheck[(sizeof(a) / sizeof(int)) == 2? 1 : -1];
+ int b_sizecheck[(sizeof(b) / sizeof(int)) == 3? 1 : -1];
}
static char const xx[] = "test";
+int xx_sizecheck[(sizeof(xx) / sizeof(char)) == 5? 1 : -1];
static char const yy[5] = "test";
static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}}
void charArrays()
{
static char const test[] = "test";
+ int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1];
static char const test2[] = { "weird stuff" };
static char const test3[] = { "test", "excess stuff" }; // expected-error{{excess elements in char array initializer}}
@@ -171,6 +176,7 @@ void variableArrayInit() {
float r1[10] = {{7}}; //expected-warning{{braces around scalar initializer}}
float r2[] = {{8}}; //expected-warning{{braces around scalar initializer}}
char r3[][5] = {1,2,3,4,5,6};
+int r3_sizecheck[(sizeof(r3) / sizeof(char[5])) == 2? 1 : -1];
char r3_2[sizeof r3 == 10 ? 1 : -1];
float r4[1][2] = {1,{2},3,4}; //expected-warning{{braces around scalar initializer}} expected-warning{{excess elements in array initializer}}
char r5[][5] = {"aa", "bbb", "ccccc"};
@@ -195,7 +201,7 @@ int bar (void) {
return z.z;
}
struct s3 {void (*a)(void);} t5 = {autoStructTest};
-// GCC extension; flexible array init. Once this is implemented, the warning should be removed.
+// FIXME: GCC extension; flexible array init. Once this is implemented, the warning should be removed.
// Note that clang objc implementation depends on this extension.
struct {int a; int b[];} t6 = {1, {1, 2, 3}}; //expected-warning{{excess elements in array initializer}}
union {char a; int b;} t7[] = {1, 2, 3};
@@ -238,3 +244,21 @@ struct soft_segment_descriptor gdt_segs[] = {
static void sppp_ipv6cp_up();
const struct {} ipcp = { sppp_ipv6cp_up }; //expected-warning{{empty struct extension}} expected-warning{{excess elements in array initializer}}
+
+struct _Matrix { union { float m[4][4]; }; }; //expected-warning{{anonymous unions are a GNU extension in C}}
+typedef struct _Matrix Matrix;
+void test_matrix() {
+ const Matrix mat1 = {
+ { { 1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f } }
+ };
+
+ const Matrix mat2 = {
+ 1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f
+ };
+}
diff --git a/clang/test/Sema/designated-initializers.c b/clang/test/Sema/designated-initializers.c
index fd4873193cf..c9a0aa7f05b 100644
--- a/clang/test/Sema/designated-initializers.c
+++ b/clang/test/Sema/designated-initializers.c
@@ -18,7 +18,8 @@ int iarray2[10] = {
};
int iarray3[10] = {
- [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
+ [5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}\
+ // expected-warning{{GNU array-range designator extension is unsupported}}
};
struct point {
@@ -44,8 +45,8 @@ struct point array[10] = {
struct point array2[10] = {
[10].x = 2.0, // expected-error{{array designator index (10) exceeds array bounds (10)}}
- [4 ... 5].y = 2.0,
- [4 ... 6] = { .x = 3, .y = 4.0 }
+ [4 ... 5].y = 2.0, // expected-warning{{GNU array-range designator extension is unsupported}}
+ [4 ... 6] = { .x = 3, .y = 4.0 } // expected-warning{{GNU array-range designator extension is unsupported}}
};
struct point array3[10] = {
@@ -116,4 +117,25 @@ struct disklabel_ops disklabel64_ops = {
// PR clang/3378
int bitwidth[] = { [(long long int)1] = 5, [(short int)2] = 2 };
int a[]= { [sizeof(int)] = 0 };
-int a2[]= { [0 ... sizeof(int)] = 0 };
+int a2[]= { [0 ... sizeof(int)] = 0 }; // expected-warning{{GNU array-range designator extension is unsupported}}
+
+// Test warnings about initializers overriding previous initializers
+struct X {
+ int a, b, c;
+};
+
+int counter = 0;
+int get8() { ++counter; return 8; }
+
+void test() {
+ struct X xs[] = {
+ [0] = (struct X){1, 2}, // expected-note{{previous initialization is here}}
+ [0].c = 3, // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
+ (struct X) {4, 5, 6}, // expected-note{{previous initialization is here}}
+ [1].b = get8(), // expected-warning{{subobject initialization overrides initialization of other fields within its enclosing subobject}}
+ [0].b = 8
+ };
+}
+
+// FIXME: we need to
+union { char c; long l; } u1 = { .l = 0xFFFF }; // expected-warning{{designated initialization of union member is broken}}
diff --git a/clang/test/Sema/vector-init.c b/clang/test/Sema/vector-init.c
index 1e2ba012c8f..6913082228c 100644
--- a/clang/test/Sema/vector-init.c
+++ b/clang/test/Sema/vector-init.c
@@ -1,5 +1,15 @@
-// RUN: clang %s -verify -fsyntax-only
+// RUN: clang %s -fsyntax-only -verify
typedef __attribute__(( ext_vector_type(4) )) float float4;
+//typedef float float4 __attribute__((vector_size(16)));
float4 foo = (float4){ 1.0, 2.0, 3.0, 4.0 };
+
+float4 array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
+int array_sizecheck[(sizeof(array) / sizeof(float4)) == 3? 1 : -1];
+
+float4 array2[2] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0,
+ 9.0 }; // expected-warning {{excess elements in array initializer}}
+
+float4 array3[2] = { {1.0, 2.0, 3.0}, 5.0, 6.0, 7.0, 8.0,
+ 9.0 }; // expected-warning {{excess elements in array initializer}}
OpenPOWER on IntegriCloud