From: Jan Hubicka Date: Thu, 29 Nov 2007 21:57:38 +0000 (+0100) Subject: re PR tree-optimization/33434 (inlining miscompilation) X-Git-Tag: releases/gcc-4.3.0~1270 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6f2da7df7acc7f6a9b7425c9e7ad8c304940299;p=thirdparty%2Fgcc.git re PR tree-optimization/33434 (inlining miscompilation) PR tree-optimization/33434 * tree-inline.c (setup_one_parameter): If the value passed to a parameter is never used, don't set it up. * gcc.dg/pr33434-1.c: New test. * gcc.dg/pr33434-2.c: New test. * gcc.dg/pr33434-3.c: New test. * gcc.dg/pr33434-4.c: New test. From-SVN: r130521 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 376994a196ae..438d303ada7b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-11-29 Jan Hubicka + Jakub Jelinek + + PR tree-optimization/33434 + * tree-inline.c (setup_one_parameter): If the value passed to + a parameter is never used, don't set it up. + 2007-11-29 Jakub Jelinek PR target/32130 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1a4021168722..93e772d19482 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2007-11-29 Jakub Jelinek + PR tree-optimization/33434 + * gcc.dg/pr33434-1.c: New test. + * gcc.dg/pr33434-2.c: New test. + * gcc.dg/pr33434-3.c: New test. + * gcc.dg/pr33434-4.c: New test. + PR c++/34270 * g++.dg/template/cond7.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr33434-1.c b/gcc/testsuite/gcc.dg/pr33434-1.c new file mode 100644 index 000000000000..d646ff74d227 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33434-1.c @@ -0,0 +1,25 @@ +/* PR tree-optimization/33434 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int k; + +void f1 (int a, int b) +{ + a = 1; + b = 1; + if (a) + while (b --) + k = 1; + else + if (b != 1) + __builtin_abort (); +} + +int main (void) +{ + f1 (1, 1); + if (k != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr33434-2.c b/gcc/testsuite/gcc.dg/pr33434-2.c new file mode 100644 index 000000000000..7dd614c0af6b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33434-2.c @@ -0,0 +1,26 @@ +/* PR tree-optimization/33434 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +int k; + +void f1 (int a) +{ + int b; + a = 1; + b = 1; + if (a) + while (b --) + k = 1; + else + if (b != 1) + __builtin_abort (); +} + +int main (void) +{ + f1 (1); + if (k != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr33434-3.c b/gcc/testsuite/gcc.dg/pr33434-3.c new file mode 100644 index 000000000000..3e99451fb29c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33434-3.c @@ -0,0 +1,31 @@ +/* PR tree-optimization/33434 */ +/* { dg-do run } */ +/* { dg-options "-O3" } */ + +int k; + +void __attribute__((noinline)) f2 (int b) +{ + k = b - 1; +} + +void f1 (int a, int b) +{ + f2 (b); + a = 1; + b = 1; + if (a) + while (b --) + k = 1; + else + if (b != 1) + __builtin_abort (); +} + +int main (void) +{ + f1 (1, 1); + if (k != 1) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr33434-4.c b/gcc/testsuite/gcc.dg/pr33434-4.c new file mode 100644 index 000000000000..d34675fe4e22 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr33434-4.c @@ -0,0 +1,18 @@ +/* PR tree-optimization/33434 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void *baz (void); + +static void * +bar (void *x) +{ + x = baz (); + return x; +} + +void * +foo (void *x) +{ + return bar (x); +} diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index e7fba9129ebf..1efc0edc2ed1 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1508,6 +1508,14 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, return; } + /* If the value of argument is never used, don't care about initializing + it. */ + if (gimple_in_ssa_p (cfun) && !def && is_gimple_reg (p)) + { + gcc_assert (!value || !TREE_SIDE_EFFECTS (value)); + return; + } + /* Initialize this VAR_DECL from the equivalent argument. Convert the argument to the proper type in case it was promoted. */ if (value)