This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

New C parser tests, batch 1


This first batch of parser tests covers various diagnostics from the
parser not exercised in the current testsuite, and a couple of syntax
error cases where earlier versions of my new C parser wrongly accepted
the code.

These tests aren't intended to set in stone that particular constructs
must be accepted syntactically and then handled in precisely a
particular way; simply to ensure that the new parser does not
accidentally change how these constructs are handled but any such
change is instead considered separately.

Many more such tests for diagnostics from or closely related to the
parser, and a large set of tests for syntax errors covering every
token type in every parser context, will be needed before the new
parser can be considered for mainline.

These tests pass on mainline.  Applied to mainline.  (I intend all
tests in this series - and contributions of new testcases for features
or compiler code not adequately covered are always welcome - to go
straight onto mainline.)

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-11-04  Joseph S. Myers  <joseph@codesourcery.com>

	* gcc.dg/asm-qual-1.c, gcc.dg/declspec-15.c, gcc.dg/declspec-16.c,
	gcc.dg/declspec-17.c, gcc.dg/empty-source-1.c,
	gcc.dg/empty-source-2.c, gcc.dg/empty-source-3.c,
	gcc.dg/extra-semi-1.c, gcc.dg/extra-semi-2.c,
	gcc.dg/extra-semi-3.c, gcc.dg/gnu-cond-expr-1.c,
	gcc.dg/gnu-cond-expr-2.c, gcc.dg/gnu-cond-expr-3.c,
	gcc.dg/init-empty-1.c, gcc.dg/init-empty-2.c,
	gcc.dg/init-empty-3.c, gcc.dg/noncompile/old-style-parm-1.c,
	gcc.dg/noncompile/old-style-parm-2.c, gcc.dg/stmt-expr-1.c,
	gcc.dg/stmt-expr-2.c, gcc.dg/stmt-expr-3.c: New tests.

diff -rupN GCC.orig/gcc/testsuite/gcc.dg/asm-qual-1.c GCC/gcc/testsuite/gcc.dg/asm-qual-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/asm-qual-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/asm-qual-1.c	2004-11-04 13:19:25.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test that qualifiers other than volatile are ignored on asm.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+void
+f (void)
+{
+  asm volatile ("");
+  asm const (""); /* { dg-warning "warning: const qualifier ignored on asm" } */
+  asm restrict (""); /* { dg-warning "warning: restrict qualifier ignored on asm" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/declspec-15.c GCC/gcc/testsuite/gcc.dg/declspec-15.c
--- GCC.orig/gcc/testsuite/gcc.dg/declspec-15.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/declspec-15.c	2004-11-04 13:37:06.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test diagnostic for empty declarations in old-style parameter
+   declarations.  Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89" } */
+
+void
+f (a, b)
+     int; /* { dg-warning "warning: empty declaration" } */
+     register; /* { dg-warning "warning: empty declaration" } */
+{
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/declspec-16.c GCC/gcc/testsuite/gcc.dg/declspec-16.c
--- GCC.orig/gcc/testsuite/gcc.dg/declspec-16.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/declspec-16.c	2004-11-04 13:37:29.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test diagnostic for empty declarations in old-style parameter
+   declarations.  Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89 -pedantic" } */
+
+void
+f (a, b)
+     int; /* { dg-warning "warning: empty declaration" } */
+     register; /* { dg-warning "warning: empty declaration" } */
+{
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/declspec-17.c GCC/gcc/testsuite/gcc.dg/declspec-17.c
--- GCC.orig/gcc/testsuite/gcc.dg/declspec-17.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/declspec-17.c	2004-11-04 13:38:27.000000000 +0000
@@ -0,0 +1,12 @@
+/* Test diagnostic for empty declarations in old-style parameter
+   declarations.  Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89 -pedantic-errors" } */
+
+void
+f (a, b)
+     int; /* { dg-error "error: empty declaration" } */
+     register; /* { dg-error "error: empty declaration" } */
+{
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/empty-source-1.c GCC/gcc/testsuite/gcc.dg/empty-source-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/empty-source-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/empty-source-1.c	2004-11-04 13:20:51.000000000 +0000
@@ -0,0 +1,5 @@
+/* Test diagnostic for an empty source file.  Test with no special
+   options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/empty-source-2.c GCC/gcc/testsuite/gcc.dg/empty-source-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/empty-source-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/empty-source-2.c	2004-11-04 13:21:59.000000000 +0000
@@ -0,0 +1,6 @@
+/* Test diagnostic for an empty source file.  Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+/* { dg-warning "warning: ISO C forbids an empty source file" "empty" { target *-*-* } 1 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/empty-source-3.c GCC/gcc/testsuite/gcc.dg/empty-source-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/empty-source-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/empty-source-3.c	2004-11-04 13:22:08.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostic for an empty source file.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+/* { dg-error "error: ISO C forbids an empty source file" "empty" { target *-*-* } 1 } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/extra-semi-1.c GCC/gcc/testsuite/gcc.dg/extra-semi-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/extra-semi-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/extra-semi-1.c	2004-11-04 13:24:23.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostic for extra semicolon outside a function.  Test with
+   no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+;
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/extra-semi-2.c GCC/gcc/testsuite/gcc.dg/extra-semi-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/extra-semi-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/extra-semi-2.c	2004-11-04 13:24:49.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostic for extra semicolon outside a function.  Test with
+   -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic" } */
+
+; /* { dg-warning "warning: ISO C does not allow extra ';' outside of a function" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/extra-semi-3.c GCC/gcc/testsuite/gcc.dg/extra-semi-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/extra-semi-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/extra-semi-3.c	2004-11-04 13:25:10.000000000 +0000
@@ -0,0 +1,7 @@
+/* Test diagnostic for extra semicolon outside a function.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-pedantic-errors" } */
+
+; /* { dg-error "error: ISO C does not allow extra ';' outside of a function" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-1.c GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-1.c	2004-11-04 13:28:19.000000000 +0000
@@ -0,0 +1,13 @@
+/* Test diagnostic for GNU extension: omitting middle term of
+   conditional expression.  Test with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+int a, b, c;
+
+void
+f (void)
+{
+  c = (++a ? : b);
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-2.c GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-2.c	2004-11-04 13:29:38.000000000 +0000
@@ -0,0 +1,13 @@
+/* Test diagnostic for GNU extension: omitting middle term of
+   conditional expression.  Test with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+
+int a, b, c;
+
+void
+f (void)
+{
+  c = (++a ? : b); /* { dg-warning "warning: ISO C forbids omitting the middle term of a \\?: expression" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-3.c GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/gnu-cond-expr-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/gnu-cond-expr-3.c	2004-11-04 13:30:00.000000000 +0000
@@ -0,0 +1,13 @@
+/* Test diagnostic for GNU extension: omitting middle term of
+   conditional expression.  Test with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+int a, b, c;
+
+void
+f (void)
+{
+  c = (++a ? : b); /* { dg-error "error: ISO C forbids omitting the middle term of a \\?: expression" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/init-empty-1.c GCC/gcc/testsuite/gcc.dg/init-empty-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-empty-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-empty-1.c	2004-11-04 13:39:58.000000000 +0000
@@ -0,0 +1,9 @@
+/* Test diagnostic for empty initializer braces.  Test with no special
+   options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+struct s { int a; } x = { };
+
+struct s *p = &(struct s){ };
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/init-empty-2.c GCC/gcc/testsuite/gcc.dg/init-empty-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-empty-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-empty-2.c	2004-11-04 13:40:52.000000000 +0000
@@ -0,0 +1,9 @@
+/* Test diagnostic for empty initializer braces.  Test with
+   -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+
+struct s { int a; } x = { }; /* { dg-warning "warning: ISO C forbids empty initializer braces" } */
+
+struct s *p = &(struct s){ }; /* { dg-warning "warning: ISO C forbids empty initializer braces" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/init-empty-3.c GCC/gcc/testsuite/gcc.dg/init-empty-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/init-empty-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/init-empty-3.c	2004-11-04 13:41:09.000000000 +0000
@@ -0,0 +1,9 @@
+/* Test diagnostic for empty initializer braces.  Test with
+   -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+struct s { int a; } x = { }; /* { dg-error "error: ISO C forbids empty initializer braces" } */
+
+struct s *p = &(struct s){ }; /* { dg-error "error: ISO C forbids empty initializer braces" } */
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/noncompile/old-style-parm-1.c GCC/gcc/testsuite/gcc.dg/noncompile/old-style-parm-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/noncompile/old-style-parm-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/noncompile/old-style-parm-1.c	2004-11-04 11:51:50.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test that stray semicolon in old-style parameters is not
+   accepted.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f(a)
+     int a;; /* { dg-error "parse error|syntax error|expected declaration specifiers" } */
+{
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/noncompile/old-style-parm-2.c GCC/gcc/testsuite/gcc.dg/noncompile/old-style-parm-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/noncompile/old-style-parm-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/noncompile/old-style-parm-2.c	2004-11-04 11:52:24.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test that parameter without declaration specifiers in old-style
+   parameters is not accepted.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void
+f(a)
+     a; /* { dg-error "parse error|syntax error|no type or storage class|expected declaration specifiers" } */
+{
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-1.c GCC/gcc/testsuite/gcc.dg/stmt-expr-1.c
--- GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-1.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/stmt-expr-1.c	2004-11-04 13:31:36.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test diagnostic for GNU extension: statement expressions.  Test
+   with no special options.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99" } */
+
+int
+f (void)
+{
+  return ({ 1; });
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-2.c GCC/gcc/testsuite/gcc.dg/stmt-expr-2.c
--- GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-2.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/stmt-expr-2.c	2004-11-04 13:32:19.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test diagnostic for GNU extension: statement expressions.  Test
+   with -pedantic.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic" } */
+
+int
+f (void)
+{
+  return ({ 1; }); /* { dg-warning "warning: ISO C forbids braced-groups within expressions" } */
+}
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-3.c GCC/gcc/testsuite/gcc.dg/stmt-expr-3.c
--- GCC.orig/gcc/testsuite/gcc.dg/stmt-expr-3.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/stmt-expr-3.c	2004-11-04 13:32:34.000000000 +0000
@@ -0,0 +1,11 @@
+/* Test diagnostic for GNU extension: statement expressions.  Test
+   with -pedantic-errors.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -pedantic-errors" } */
+
+int
+f (void)
+{
+  return ({ 1; }); /* { dg-error "error: ISO C forbids braced-groups within expressions" } */
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]