]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/32285 (Miscompilation with pure _Complex returning call inside anoth...
authorJakub Jelinek <jakub@redhat.com>
Wed, 20 Jun 2007 06:50:23 +0000 (08:50 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 20 Jun 2007 06:50:23 +0000 (08:50 +0200)
PR middle-end/32285
* calls.c (precompute_arguments): Also precompute CALL_EXPR arguments
if ACCUMULATE_OUTGOING_ARGS.

* gcc.c-torture/execute/20070614-1.c: New test.

From-SVN: r125879

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20070614-1.c [new file with mode: 0644]

index 3ce3bc9b75662313bac504dd33a8bcfb9e94ace7..2044d730d5ecfb29039860b1fb795c2eef79ba4d 100644 (file)
@@ -1,3 +1,9 @@
+2007-06-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/32285
+       * calls.c (precompute_arguments): Also precompute CALL_EXPR arguments
+       if ACCUMULATE_OUTGOING_ARGS.
+
 2007-06-20  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR rtl-optimization/28011
index df6699a29bd0f33aa60164d2176940962b2058f7..45001c08ee75766e10f01d41f2c097b65dbeb9c5 100644 (file)
@@ -1239,13 +1239,25 @@ precompute_arguments (int flags, int num_actuals, struct arg_data *args)
 
   /* If this is a libcall, then precompute all arguments so that we do not
      get extraneous instructions emitted as part of the libcall sequence.  */
-  if ((flags & ECF_LIBCALL_BLOCK) == 0)
+
+  /* If we preallocated the stack space, and some arguments must be passed
+     on the stack, then we must precompute any parameter which contains a
+     function call which will store arguments on the stack.
+     Otherwise, evaluating the parameter may clobber previous parameters
+     which have already been stored into the stack.  (we have code to avoid
+     such case by saving the outgoing stack arguments, but it results in
+     worse code)  */
+  if ((flags & ECF_LIBCALL_BLOCK) == 0 && !ACCUMULATE_OUTGOING_ARGS)
     return;
 
   for (i = 0; i < num_actuals; i++)
     {
       enum machine_mode mode;
 
+      if ((flags & ECF_LIBCALL_BLOCK) == 0
+         && TREE_CODE (args[i].tree_value) != CALL_EXPR)
+       continue;
+
       /* If this is an addressable type, we cannot pre-evaluate it.  */
       gcc_assert (!TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)));
 
index 97efa9fe6820cf32354bc041944c4ac4655b5baa..7310ceadcc6b3142ad7bd103d676a40677b1579d 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/32285
+       * gcc.c-torture/execute/20070614-1.c: New test.
+
 2007-06-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/32353
diff --git a/gcc/testsuite/gcc.c-torture/execute/20070614-1.c b/gcc/testsuite/gcc.c-torture/execute/20070614-1.c
new file mode 100644 (file)
index 0000000..fa44f7f
--- /dev/null
@@ -0,0 +1,33 @@
+extern void abort (void);
+
+_Complex v = 3.0 + 1.0iF;
+
+void
+foo (_Complex z, int *x)
+{
+  if (z != v)
+    abort ();
+}
+
+_Complex bar (_Complex z) __attribute__ ((pure));
+_Complex
+bar (_Complex z)
+{
+  return v;
+}
+
+int
+baz (void)
+{
+  int a, i;
+  for (i = 0; i < 6; i++)
+    foo (bar (1.0iF * i), &a);
+  return 0;
+}
+
+int
+main ()
+{
+  baz ();
+  return 0;
+}