From 25fe7e3d8b1d614dc09ee33436ada6dcd4047282 Mon Sep 17 00:00:00 2001 From: rguenth Date: Tue, 11 Jan 2011 17:01:37 +0000 Subject: [PATCH] 2011-01-11 Richard Guenther PR tree-optimization/46076 * tree-ssa.c (useless_type_conversion_p): Conversions from unprototyped to empty argument list function types are useless. * gcc.dg/tree-ssa/pr46076.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168665 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr46076.c | 27 +++++++++++++++++++++++++++ gcc/tree-ssa.c | 5 +++++ 4 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr46076.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35b4a696a28..9724eee777d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2011-01-11 Richard Guenther + PR tree-optimization/46076 + * tree-ssa.c (useless_type_conversion_p): Conversions from + unprototyped to empty argument list function types are useless. + +2011-01-11 Richard Guenther + PR middle-end/45235 * emit-rtl.c (set_mem_attributes_minus_bitpos): Do not mark volatile MEMs as MEM_READONLY_P. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 710431c8424..adb6740e58a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-01-11 Richard Guenther + + PR tree-optimization/46076 + * gcc.dg/tree-ssa/pr46076.c: New testcase. + 2011-01-11 Jeff Law * PR tree-optimization/47086 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr46076.c b/gcc/testsuite/gcc.dg/tree-ssa/pr46076.c new file mode 100644 index 00000000000..a2777a604b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr46076.c @@ -0,0 +1,27 @@ +/* { dg-do link } */ +/* { dg-options "-O2" } */ + +extern void link_error (void); + +typedef unsigned char(*Calculable)(void); + +static unsigned char one() { return 1; } +static unsigned char two() { return 2; } + +static int +print(Calculable calculate) +{ + return calculate() + calculate() + 1; +} + +int +main() +{ + /* Make sure we perform indirect inlining of one and two and optimize + the result to a constant. */ + if (print(one) != 3) + link_error (); + if (print(two) != 5) + link_error (); + return 0; +} diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 7bd01f8d4db..aa797e22bec 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1410,6 +1410,11 @@ useless_type_conversion_p (tree outer_type, tree inner_type) if (!prototype_p (outer_type)) return true; + /* A conversion between unprototyped and empty argument list is ok. */ + if (TYPE_ARG_TYPES (outer_type) == void_list_node + && !prototype_p (inner_type)) + return true; + /* If the unqualified argument types are compatible the conversion is useless. */ if (TYPE_ARG_TYPES (outer_type) == TYPE_ARG_TYPES (inner_type)) -- 2.11.0