Suggested expression parser tests

Neil Booth NeilB@earthling.net
Sat Apr 1 20:45:00 GMT 2000


Zack Weinberg wrote:-
 
> This works pretty well:
> 
> make clean [if necessary]
> make LANGUAGES=c
> runtest --tool gcc gcc.dg/dg.exp

OK, here is what I'd propose.  The problem is, I can't get the tests
to run properly, so I don't know if they actually work.  I build gcc
from a different directory to the sources.

If I do what you suggest above, with a cd to the testsuite directory
before running runtest, or a runtest --srcdir=, I get

"ERROR: couldn't compile regular expression pattern: parentheses () not
balanced"

for cpp-missingop.c.  The other thing is that make LANGUAGES=c and
running the test files through xgcc does not seem to use cppmain as
its preprocessor.  As you can tell, I'm a bit confused as to what uses
what <g>.

Neil.

Index: cpp-cond.c
===================================================================
RCS file: cpp-cond.c
diff -N cpp-cond.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-cond.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,13 @@
+/* { dg-do preprocess } */
+
+/* Test the ? : opearator, for precedence and both true and false.  */
+
+#if  1 ? 1 ? 2 : 0 : 0
+#error OK	/* { dg-error "OK" "nested ? :" } */
+#endif
+
+#if  ((0) ? (1) ? (2) : (3) : (4) ? (5): (6)) == 5
+#error OK	/* { dg-error "OK" "nested ? : with parens" } */
+#endif
+
+
Index: cpp-ifparen.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/testsuite/gcc.dg/cpp-ifparen.c,v
retrieving revision 1.2
diff -u -p -r1.2 cpp-ifparen.c
--- cpp-ifparen.c	2000/04/01 22:45:01	1.2
+++ cpp-ifparen.c	2000/04/02 04:37:59
@@ -1,9 +1,29 @@
 /* { dg-do preprocess } */
 
-#if 2048 < (16 * (40) + 192)
-#error			/* { dg-bogus "error" "with paren" } */
+/* These now use "!=" rather than "<" to increase chance of failure.  */
+#if 16 * (1) + 4 != 20
+#error		/* { dg-bogus "error" "with paren" } */
 #endif
 
-#if 2048 < (16 * 40 + 192)
-#error			/* { dg-bogus "error" "without paren" } */
+#if 16 * 1 + 4 != 20
+#error		/* { dg-bogus "error" "without paren" } */
+#endif
+
+#if ()	        /* { dg-error "expression between" "empty paren" } */
+#endif
+
+#if (1) == 1
+#error		/* { dg-error "error" "simple parens no. 1" } */
+#endif
+
+#if (2)
+#error		/* { dg-error "error" "simple parens no. 2" } */
+#endif
+
+#if 3 == (3)
+#error		/* { dg-error "error" "simple parens no. 3" } */
+#endif
+
+#if (((-1) + 8)) == ((+2) * ((3)) - -1)
+#error		/* { dg-error "error" "nested parentheses" } */
 #endif
Index: cpp-missingop.c
===================================================================
RCS file: cpp-missingop.c
diff -N cpp-missingop.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-missingop.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,21 @@
+/* { dg-do preprocess } */
+
+/* Various illegal expressions with missing components.  */
+
+#if		/* { dg-error "expression between" "empty #if" } */
+#endif
+
+#if ~		/* { dg-error "no right op" "no unary operand" } */
+#endif
+
+#if 3 + * 6 + 4  /* { dg-error "no right op" "no right operand" } */
+#endif
+
+#if 2 ~2	/* { dg-error "missing bin" "no binary operator" } */
+#endif
+
+#if 1 + 2 (3)   /* { dg-error "missing bin" "immediate then open paren" } */
+#endif
+
+#if (2) 4 * 2  /* { dg-error "missing bin" "close paren then immediate" } */
+#endif
Index: cpp-missingparen.c
===================================================================
RCS file: cpp-missingparen.c
diff -N cpp-missingparen.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-missingparen.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,27 @@
+/* Test various combinations of missing parentheses give the correct
+   missing parenthesis message.  */
+
+/* { dg-do preprocess } */
+
+#if (1
+#endif
+
+#if 2 * (3 + 4
+#endif
+
+#if (2))
+#endif
+
+#if )
+#endif
+
+#if 4)
+#endif
+
+/* { dg-error "missing ')'" "missing ')' no. 1"  { target *-*-* } 6 } */
+/* { dg-error "missing ')'" "missing ')' no. 2"  { target *-*-* } 9 } */
+/* { dg-error "missing '('" "missing '(' no. 1"  { target *-*-* } 12 } */
+/* { dg-error "missing '('" "missing '(' no. 2"  { target *-*-* } 15 } */
+/* { dg-error "missing '('" "missing '(' no. 3"  { target *-*-* } 18 } */
+
+
Index: cpp-shift.c
===================================================================
RCS file: cpp-shift.c
diff -N cpp-shift.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-shift.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,20 @@
+/* { dg-do preprocess } */
+
+/* Test shift operators.  */
+
+#if 1 << 4 != 16
+#error		/* { dg-bogus "error" "<< +ve shift" } */
+#endif
+
+#if 19 >> 2 != 4
+#error		/* { dg-bogus "error" ">> +ve shift" } */
+#endif
+
+#if 17 << -2 != 17 >> 2
+#error		/* { dg-bogus "error" "<< -ve shift" } */
+#endif
+
+#if 25 >> -2 != 25 << 2
+#error		/* { dg-bogus "error" ">> -ve shift" } */
+#endif
+
Index: cpp-shortcircuit.c
===================================================================
RCS file: cpp-shortcircuit.c
diff -N cpp-shortcircuit.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-shortcircuit.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,24 @@
+/* { dg-do preprocess } */
+
+/* Test that all operators correctly short circuit.  */
+
+#if 2 || 3 / 0 != 1
+#error		/* { dg-bogus "error" "|| short circuit" } */
+#endif
+
+#if 0 && 3 / 0
+#error		/* { dg-bogus "error" "&& short circuit" } */
+#endif
+
+#if 1 ? 0 : 3 / 0
+#error		/* { dg-bogus "error" "? : right short circuit" } */
+#endif
+
+#if 0 ? 3 / 0 : 2
+#else
+#error		/* { dg-bogus "error" "? : left short circuit" } */
+#endif
+
+#if -1 ? 0 && 3 / 0 : 3 / 0 + 5 == 5
+#error		/* { dg-bogus "error" "nested short circuiting" } */
+#endif
Index: cpp-unary.c
===================================================================
RCS file: cpp-unary.c
diff -N cpp-unary.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ cpp-unary.c	Sat Apr  1 20:37:59 2000
@@ -0,0 +1,30 @@
+/* { dg-do preprocess } */
+
+/* Test the various unary operators.  */
+
+#if 1 + + + 1   /* allow multiple unary sign operators :) */
+#endif
+
+#if 8 - +3 != +4 + +1
+#error		/* { dg-bogus "error" "unary +" } */
+#endif
+
+#if -2 - -1 != -1
+#error		/* { dg-bogus "error" "unary -" } */
+#endif
+
+#if ~0 != -1
+#error		/* { dg-bogus "error" "unary ~" } */
+#endif
+
+#if !0 && (!1 == 0) && !!1 != 1
+#error		/* { dg-bogus "error" "unary !" } */
+#endif
+
+#if ~~8 != 8
+#error		/* { dg-bogus "error" "double unary ~" } */
+#endif
+
+#if 5 + +!-4 != 5
+#error		/* { dg-bogus "error" "compound unary +, !, -" } */
+#endif



More information about the Gcc-patches mailing list