aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2006-05-18 18:22:12 +0000
committerMike Stump <mrs@gcc.gnu.org>2006-05-18 18:22:12 +0000
commit52ffd86eb62d0320ccf64138e5d7d37ab7a6f7c5 (patch)
tree3393aa88e335ad0c151ee642c9e17e8807ed52e9 /gcc/testsuite/gcc.dg
parent4f9533c7722fa07511a94d005227961f4a4dec23 (diff)
downloadgcc-52ffd86eb62d0320ccf64138e5d7d37ab7a6f7c5.zip
gcc-52ffd86eb62d0320ccf64138e5d7d37ab7a6f7c5.tar.gz
gcc-52ffd86eb62d0320ccf64138e5d7d37ab7a6f7c5.tar.bz2
Fix up vla, vm and [*] sematics.
PR c/18740 PR c/7948 PR c/25802 * c-tree.h (struct c_arg_info): Add had_vla_unspec. (c_vla_unspec_p): Add. (c_vla_type_p): Add. * c-decl.c (struct c_scope): Add had_vla_unspec. (build_array_declarator): Add support for [*]. (grokdeclarator): Likewise. (grokparms): Likewise. (get_parm_info): Likewise. * c-objc-common.c (c_vla_unspec_p): Likewise. * c-objc-common.h (LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P): Likewise. * c-parser.c (c_parser_typeof_specifier): Evaluate arguments to typeof when argument is a variably modified type not inside sizeof or alignof. (c_parser_direct_declarator_inner): Propagate errors. (c_parser_sizeof_expression): Add support for [*]. * c-typeck.c (c_vla_type_p): Add. (composite_type): Add support for vla compositing. (comptypes_internal): Add support for vla compatibility. (c_expr_sizeof_expr): Evaluate vla arguments. * tree.c (variably_modified_type_p): Update comment for [*]. testsuite: * gcc.dg/c90-arraydecl-1.c: Update for vla, vm [*] fixups. * gcc.dg/vla-4.c: Add. * gcc.dg/vla-5.c: Add. * gcc.dg/vla-6.c: Add. From-SVN: r113888
Diffstat (limited to 'gcc/testsuite/gcc.dg')
-rw-r--r--gcc/testsuite/gcc.dg/c90-arraydecl-1.c13
-rw-r--r--gcc/testsuite/gcc.dg/vla-4.c48
-rw-r--r--gcc/testsuite/gcc.dg/vla-5.c24
-rw-r--r--gcc/testsuite/gcc.dg/vla-6.c26
4 files changed, 104 insertions, 7 deletions
diff --git a/gcc/testsuite/gcc.dg/c90-arraydecl-1.c b/gcc/testsuite/gcc.dg/c90-arraydecl-1.c
index 47334b9..97dc1ee 100644
--- a/gcc/testsuite/gcc.dg/c90-arraydecl-1.c
+++ b/gcc/testsuite/gcc.dg/c90-arraydecl-1.c
@@ -9,23 +9,22 @@
that we get just one error and no warnings. */
void foo0 (int a, int b[*]); /* { dg-error "ISO C90" "\[*\] not in C90" } */
-/* { dg-warning "implement" "\[*\] not implemented" { target *-*-* } 11 } */
void foo1 (int, int [*]); /* { dg-error "ISO C90" "\[*\] not in C90" } */
-/* { dg-warning "implement" "\[*\] not implemented" { target *-*-* } 13 } */
+/* { dg-error "allowed" "\'\[*\]\' not allowed in other than a declaration" { target *-*-* } 12 } */
/* Use of static and type qualifiers (not allowed with abstract declarators)
is a C99 feature. */
void bar0 (int a[const]); /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "ISO C90" "\[quals\] not in C90" { target *-*-* } 19 } */
+/* { dg-error "ISO C90" "\[quals\] not in C90" { target *-*-* } 18 } */
void bar1 (int a[const 2]); /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "ISO C90" "\[quals expr\] not in C90" { target *-*-* } 21 } */
+/* { dg-error "ISO C90" "\[quals expr\] not in C90" { target *-*-* } 20 } */
void bar2 (int a[static 2]); /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "ISO C90" "\[static expr\] not in C90" { target *-*-* } 23 } */
+/* { dg-error "ISO C90" "\[static expr\] not in C90" { target *-*-* } 22 } */
void bar3 (int a[static const 2]); /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "ISO C90" "\[static quals expr\] not in C90" { target *-*-* } 25 } */
+/* { dg-error "ISO C90" "\[static quals expr\] not in C90" { target *-*-* } 24 } */
void bar4 (int a[const static 2]); /* { dg-bogus "warning" "warning in place of error" } */
-/* { dg-error "ISO C90" "\[quals static expr\] not in C90" { target *-*-* } 27 } */
+/* { dg-error "ISO C90" "\[quals static expr\] not in C90" { target *-*-* } 26 } */
/* Because [*] isn't properly implemented and so warns, we don't test here
for [const *] yet. */
diff --git a/gcc/testsuite/gcc.dg/vla-4.c b/gcc/testsuite/gcc.dg/vla-4.c
new file mode 100644
index 0000000..7ffbfb3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-4.c
@@ -0,0 +1,48 @@
+/* { dg-do run } */
+/* { dg-options "-std=c99 -pedantic-errors" } */
+/* PR c/18740 */
+
+static int i;
+
+int foo(int n)
+{
+ int (*t)[n];
+ i = 0;
+ int j = 0;
+ char b[1][n+3]; /* Variable length array. */
+ int d[3][n]; /* Variable length array. */
+ sizeof (b[i++ + sizeof(j++)]); /* Outer sizeof is evaluated for vla, but not the inner one. */
+ if (i != 1 || j != 0)
+ return 1;
+ __typeof__(b[i++]) c1; /* typeof is evauluated when given a vm */
+ if (i != 2)
+ return 1;
+ __typeof__(t + (i++,0)) c2; /* typeof is evauluated when given a vm */
+ if (i != 3)
+ return 1;
+ __typeof__(i + (i++,0)) c3; /* typeof is not evauluated when not given a vm */
+ if (i != 3)
+ return 1;
+ sizeof (d[i++]); /* sizeof is evaluated for vla. */
+ if (i != 4)
+ return 1;
+ __alignof__(__typeof__(t + (i++,0))); /* typeof is not evauluated when given a vm inside alignof*/
+ if (i != 4)
+ return 1;
+ sizeof(__typeof__(t + (i++,0))); /* typeof is not evauluated when given a vm inside sizeof*/
+ if (i != 4)
+ return 1;
+ return 0;
+}
+
+int foo6(int a, int b[a][a], int (*c)[sizeof(*b)]) {
+ return sizeof (*c);
+}
+
+int main() {
+ int b[10][10];
+ int (*c)[sizeof(int)*10];
+ if (foo6(10, b, c) != 10*sizeof(int)*sizeof(int))
+ return 1;
+ return foo(10);
+}
diff --git a/gcc/testsuite/gcc.dg/vla-5.c b/gcc/testsuite/gcc.dg/vla-5.c
new file mode 100644
index 0000000..f5256c4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-5.c
@@ -0,0 +1,24 @@
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+void foo1(int (*o)(int p[*])) { }
+
+void foo2(int o[*]);
+void foo3(int o[4][*]);
+
+void foo4(int j, int a[j]);
+void foo4(int, int a[*]);
+void foo4(int, int a[]);
+void foo4(int j, int a[j]) {
+}
+
+int foo5(int a, int b[*][*], int c[static sizeof(*b)]);
+int foo5(int a, int b[10][10], int c[400]) {
+ return sizeof (c);
+}
+
+int foo6(int a, int b[*][*], int c[static sizeof(*b)]);
+int foo6(int a, int b[a][a], int c[sizeof(*b)]) {
+ return sizeof (c);
+}
+
+void foo7(__typeof__ (int (*)(int o[*])) i);
diff --git a/gcc/testsuite/gcc.dg/vla-6.c b/gcc/testsuite/gcc.dg/vla-6.c
new file mode 100644
index 0000000..b7bdb31
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vla-6.c
@@ -0,0 +1,26 @@
+/* { dg-options "-std=c99 -pedantic-errors" } */
+
+int a[*]; /* { dg-error "not allowed in other than function prototype scope" } */
+void foo1() { int a[*]; } /* { dg-error "not allowed in other than function prototype scope" } */
+void foo2() { int a[*]; } /* { dg-error "not allowed in other than function prototype scope" } */
+int foo3(int i)[*]; /* { dg-error "not allowed in other than function prototype scope" } */
+void foo4(int o[*][4]) { } /* { dg-error "not allowed in other than function prototype scope" } */
+void foo5(int o[4][*]) { } /* { dg-error "not allowed in other than function prototype scope" } */
+
+/* [*] can't be used in a type that's not a declaration */
+void foo11(int x[sizeof(int (*)[*])]); /* { dg-error "not allowed in other than a declaration" } */
+void foo12(int [*]); /* { dg-error "not allowed in other than a declaration" } */
+
+extern int n;
+int B[100];
+void foo10(int m) {
+ typedef int (*vla)[m];
+ struct tag {
+ vla x; /* { dg-error "a member of a structure or union cannot have a variably modified type" } */
+ /* PR c/7948 */
+ int (*y)[n]; /* { dg-error "a member of a structure or union cannot have a variably modified type" } */
+ int z[n]; /* { dg-error "a member of a structure or union cannot have a variably modified type" } */
+ };
+ /* PR c/25802 */
+ extern int (*r)[m]; /* { dg-error "variably modified type must have no linkage" } */
+}