From: Jakub Jelinek Date: Tue, 22 Apr 2008 22:33:48 +0000 (+0200) Subject: re PR rtl-optimization/36017 (Miscompilation of tail call sqrt) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=63cb92c1ee60811725c0f0b2512e7edcded5c7d4;p=gcc.git re PR rtl-optimization/36017 (Miscompilation of tail call sqrt) 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6132b7fdd09..9a057f3f9c0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-04-23 Jakub Jelinek + + PR rtl-optimization/36017 + * builtins.c (expand_errno_check): Clear CALL_EXPR_TAILCALL before + expanding the library call. + 2008-04-22 Ian Lance Taylor * fold-const.c (pointer_may_wrap_p): Call int_size_in_bytes rather diff --git a/gcc/builtins.c b/gcc/builtins.c index d5c4f9222c9..761a658bc71 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cf689a4129f..435f0814dca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-04-23 Jakub Jelinek + + PR rtl-optimization/36017 + * gcc.dg/pr36017.c: New test. + 2008-04-22 Jakub Jelinek PR c++/35747 diff --git a/gcc/testsuite/gcc.dg/pr36017.c b/gcc/testsuite/gcc.dg/pr36017.c new file mode 100644 index 00000000000..fa36927333d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr36017.c @@ -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; +}