This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix postincrement before switch
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Ulrich Drepper <drepper at redhat dot com>, Roland McGrath <roland at redhat dot com>
- Date: Thu, 13 Mar 2003 19:30:39 +0100
- Subject: Re: [PATCH] Fix postincrement before switch
- References: <20030313165003.Q1717@sunsite.ms.mff.cuni.cz>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Thu, Mar 13, 2003 at 04:50:03PM +0100, Jakub Jelinek wrote:
> Hi!
>
> The following testcase is miscompiled at -O1 and higher on
> at least IA-32 and x86-64.
> The problem is that the b++ postincrement queued instructions
> are emitted right after case 2 in the bar function (when expand_builtin
> (when expanding call to abort ()) calls emit_queue).
> Is expand_start_case the right place for the emit_queue () call?
Oops, mailed incomplete testcase.
Here is one which defines foo function.
2003-03-13 Jakub Jelinek <jakub at redhat dot com>
* stmt.c (expand_start_case): Call emit_queue ().
* gcc.c-torture/execute/20030313-1.c: New test.
--- gcc/stmt.c.jj 2003-03-10 04:37:44.000000000 -0500
+++ gcc/stmt.c 2003-03-13 10:35:54.000000000 -0500
@@ -4428,6 +4428,7 @@ expand_start_case (exit_flag, expr, type
nesting_stack = thiscase;
do_pending_stack_adjust ();
+ emit_queue ();
/* Make sure case_stmt.start points to something that won't
need any transformation before expand_end_case. */
--- gcc/testsuite/gcc.c-torture/execute/20030313-1.c.jj 2003-03-13 10:37:38.000000000 -0500
+++ gcc/testsuite/gcc.c-torture/execute/20030313-1.c 2003-03-13 08:43:23.000000000 -0500
@@ -0,0 +1,68 @@
+struct A
+{
+ unsigned long p, q, r, s;
+} x = { 13, 14, 15, 16 };
+
+extern void abort (void);
+extern void exit (int);
+
+static inline struct A *
+bar (void)
+{
+ struct A *r;
+
+ switch (8)
+ {
+ case 2:
+ abort ();
+ break;
+ case 8:
+ r = &x;
+ break;
+ default:
+ abort ();
+ break;
+ }
+ return r;
+}
+
+void
+foo (unsigned long *x, int y)
+{
+ if (y != 12)
+ abort ();
+ if (x[0] != 1 || x[1] != 11)
+ abort ();
+ if (x[2] != 2 || x[3] != 12)
+ abort ();
+ if (x[4] != 3 || x[5] != 13)
+ abort ();
+ if (x[6] != 4 || x[7] != 14)
+ abort ();
+ if (x[8] != 5 || x[9] != 15)
+ abort ();
+ if (x[10] != 6 || x[11] != 16)
+ abort ();
+}
+
+int
+main (void)
+{
+ unsigned long a[40];
+ int b = 0;
+
+ a[b++] = 1;
+ a[b++] = 11;
+ a[b++] = 2;
+ a[b++] = 12;
+ a[b++] = 3;
+ a[b++] = bar()->p;
+ a[b++] = 4;
+ a[b++] = bar()->q;
+ a[b++] = 5;
+ a[b++] = bar()->r;
+ a[b++] = 6;
+ a[b++] = bar()->s;
+ foo (a, b);
+ exit (0);
+}
Jakub