re PR rtl-optimization/36017 (Miscompilation of tail call sqrt)
authorJakub Jelinek <jakub@redhat.com>
Tue, 22 Apr 2008 22:33:48 +0000 (00:33 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 22 Apr 2008 22:33:48 +0000 (00:33 +0200)
PR rtl-optimization/36017
* builtins.c (expand_errno_check): Clear CALL_EXPR_TAILCALL before
expanding the library call.

* gcc.dg/pr36017.c: New test.

From-SVN: r134569

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr36017.c [new file with mode: 0644]

index 6132b7fdd09516189512fb621feb53e0638d7c0e..9a057f3f9c0050beb81aed3c44e4685c8a1f02fd 100644 (file)
@@ -1,3 +1,9 @@
+2008-04-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/36017
+       * builtins.c (expand_errno_check): Clear CALL_EXPR_TAILCALL before
+       expanding the library call.
+
 2008-04-22  Ian Lance Taylor  <iant@google.com>
 
        * fold-const.c (pointer_may_wrap_p): Call int_size_in_bytes rather
index d5c4f9222c92a10396f1cc36658c8556311a25ae..761a658bc712abfe3d4cd663e9212e47f58b1cef 100644 (file)
@@ -1804,6 +1804,9 @@ expand_errno_check (tree exp, rtx target)
     }
 #endif
 
+  /* Make sure the library call isn't expanded as a tail call.  */
+  CALL_EXPR_TAILCALL (exp) = 0;
+
   /* We can't set errno=EDOM directly; let the library call do it.
      Pop the arguments right away in case the call gets deleted.  */
   NO_DEFER_POP;
index cf689a4129f324fd30fa53b66691614819c706b9..435f0814dcae3b03eccaf161243d583bec3a49e2 100644 (file)
@@ -1,3 +1,8 @@
+2008-04-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/36017
+       * gcc.dg/pr36017.c: New test.
+
 2008-04-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/35747
diff --git a/gcc/testsuite/gcc.dg/pr36017.c b/gcc/testsuite/gcc.dg/pr36017.c
new file mode 100644 (file)
index 0000000..fa36927
--- /dev/null
@@ -0,0 +1,29 @@
+/* PR rtl-optimization/36017 */
+/* { dg-do run { target i?86-*-linux* x86_64-*-linux* } } */
+/* { dg-options "-O2 -lm" } */
+
+extern double sqrt (double);
+extern void abort (void);
+
+__attribute__((noinline)) double
+foo (double a)
+{
+  double b, c, d = 0.7;
+  if (a <= d)
+    b = sqrt (d * a);
+  else
+    {
+      c = (1.0 - d) * (1.0 - a);
+      b = c > 0 ? 1.0 - sqrt (c) : 1.0;
+    }
+  return b;
+}
+
+int
+main (void)
+{
+  double c = foo (0.5);
+  if (c > 0.5917)
+    abort ();
+  return 0;
+}