From dab3cc758a1319c64736da0a04fdf4bd74f2498e Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 22 Jan 2008 14:45:56 +0000 Subject: [PATCH] Backport PRs 28796, 34070, 34739, 34768 2008-01-22 Richard Guenther PR middle-end/34739 Backport from mainline 2008-01-16 Richard Guenther PR c/34768 * c-typeck.c (common_pointer_type): Do not merge inconsistent type qualifiers for function types. 2007-11-12 Richard Guenther PR middle-end/34070 * fold-const.c (fold_binary): If testing for non-negative operands with tree_expr_nonnegative_warnv_p make sure to use op0 which has all (sign) conversions retained. 2006-10-24 Richard Guenther PR middle-end/28796 * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS for deciding optimizations in consistency with fold-const.c (fold_builtin_unordered_cmp): Likewise. From-SVN: r131723 --- gcc/ChangeLog | 25 +++++++++++++++++ gcc/builtins.c | 14 +++++----- gcc/c-typeck.c | 14 +++++++--- gcc/fold-const.c | 4 +-- gcc/testsuite/ChangeLog | 22 +++++++++++++++ .../gcc.c-torture/execute/pr34070-1.c | 13 +++++++++ .../gcc.c-torture/execute/pr34070-2.c | 13 +++++++++ .../gcc.c-torture/execute/pr34768-1.c | 26 +++++++++++++++++ .../gcc.c-torture/execute/pr34768-2.c | 28 +++++++++++++++++++ gcc/testsuite/gcc.dg/pr28796-1.c | 17 +++++++++++ gcc/testsuite/gcc.dg/pr28796-2.c | 21 ++++++++++++++ 11 files changed, 184 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr34070-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr34070-2.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr34768-1.c create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr34768-2.c create mode 100644 gcc/testsuite/gcc.dg/pr28796-1.c create mode 100644 gcc/testsuite/gcc.dg/pr28796-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e7e74a8faa44..4c52209fc4d5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,28 @@ +2008-01-22 Richard Guenther + + PR middle-end/34739 + Backport from mainline + 2008-01-16 Richard Guenther + + PR c/34768 + * c-typeck.c (common_pointer_type): Do not merge inconsistent + type qualifiers for function types. + + 2007-11-12 Richard Guenther + + PR middle-end/34070 + * fold-const.c (fold_binary): If testing for non-negative + operands with tree_expr_nonnegative_warnv_p make sure to + use op0 which has all (sign) conversions retained. + + 2006-10-24 Richard Guenther + + PR middle-end/28796 + * builtins.c (fold_builtin_classify): Use HONOR_INFINITIES + and HONOR_NANS instead of MODE_HAS_INFINITIES and MODE_HAS_NANS + for deciding optimizations in consistency with fold-const.c + (fold_builtin_unordered_cmp): Likewise. + 2008-01-17 Eric Botcazou Backport from mainline: diff --git a/gcc/builtins.c b/gcc/builtins.c index 3273586333cc..87867c6f51ba 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -8720,7 +8720,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) switch (builtin_index) { case BUILT_IN_ISINF: - if (!MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8736,8 +8736,8 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_FINITE: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg))) - && !MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg))) + && !HONOR_INFINITIES (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8750,7 +8750,7 @@ fold_builtin_classify (tree fndecl, tree arglist, int builtin_index) return NULL_TREE; case BUILT_IN_ISNAN: - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg)))) return omit_one_operand (type, integer_zero_node, arg); if (TREE_CODE (arg) == REAL_CST) @@ -8833,13 +8833,13 @@ fold_builtin_unordered_cmp (tree fndecl, tree arglist, if (unordered_code == UNORDERED_EXPR) { - if (!MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0)))) + if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))) return omit_two_operands (type, integer_zero_node, arg0, arg1); return fold_build2 (UNORDERED_EXPR, type, arg0, arg1); } - code = MODE_HAS_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code - : ordered_code; + code = HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) ? unordered_code + : ordered_code; return fold_build1 (TRUTH_NOT_EXPR, type, fold_build2 (code, type, arg0, arg1)); } diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index c843acfd79a7..9646bd6e4360 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -530,6 +530,7 @@ common_pointer_type (tree t1, tree t2) tree pointed_to_1, mv1; tree pointed_to_2, mv2; tree target; + unsigned target_quals; /* Save time if the two types are the same. */ @@ -557,10 +558,15 @@ common_pointer_type (tree t1, tree t2) if (TREE_CODE (mv2) != ARRAY_TYPE) mv2 = TYPE_MAIN_VARIANT (pointed_to_2); target = composite_type (mv1, mv2); - t1 = build_pointer_type (c_build_qualified_type - (target, - TYPE_QUALS (pointed_to_1) | - TYPE_QUALS (pointed_to_2))); + + /* For function types do not merge const qualifiers, but drop them + if used inconsistently. The middle-end uses these to mark const + and noreturn functions. */ + if (TREE_CODE (pointed_to_1) == FUNCTION_TYPE) + target_quals = TYPE_QUALS (pointed_to_1) & TYPE_QUALS (pointed_to_2); + else + target_quals = TYPE_QUALS (pointed_to_1) | TYPE_QUALS (pointed_to_2); + t1 = build_pointer_type (c_build_qualified_type (target, target_quals)); return build_type_attribute_variant (t1, attributes); } diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 81b1d4f84cd8..782a30200ce9 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -10035,7 +10035,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) strict_overflow_p = false; if (TREE_CODE (arg1) == LSHIFT_EXPR && (TYPE_UNSIGNED (type) - || tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))) + || tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p))) { tree sval = TREE_OPERAND (arg1, 0); if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0) @@ -10152,7 +10152,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) strict_overflow_p = false; if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR) && (TYPE_UNSIGNED (type) - || tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p))) + || tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p))) { tree c = arg1; /* Also optimize A % (C << N) where C is a power of 2, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 09e72beadf24..18befa98f2c3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,25 @@ +2008-01-22 Richard Guenther + + PR middle-end/34739 + Backport from mainline + 2008-01-16 Richard Guenther + + PR c/34768 + * gcc.c-torture/execute/pr34768-1.c: New testcase. + * gcc.c-torture/execute/pr34768-2.c: Likewise. + + 2007-11-12 Richard Guenther + + PR middle-end/34070 + * gcc.c-torture/execute/pr34070-1.c: New testcase. + * gcc.c-torture/execute/pr34070-2.c: Likewise. + + 2006-10-24 Richard Guenther + + PR middle-end/28796 + * gcc.dg/pr28796-1.c: New testcase. + * gcc.dg/pr28796-2.c: Likewise. + 2008-01-19 John David Anglin * g++.dg/eh/ia64-2.C: Place "dg-do run" statement before diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c b/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c new file mode 100644 index 000000000000..6589bb0c0958 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c @@ -0,0 +1,13 @@ +extern void abort (void); + +int f(unsigned int x) +{ + return ((int)x) % 4; +} + +int main() +{ + if (f(-1) != -1) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c b/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c new file mode 100644 index 000000000000..4c1ce7b0231f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c @@ -0,0 +1,13 @@ +extern void abort (void); + +int f(unsigned int x, int n) +{ + return ((int)x) / (1 << n); +} + +int main() +{ + if (f(-1, 1) != 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c b/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c new file mode 100644 index 000000000000..eb16adbf1f35 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr34768-1.c @@ -0,0 +1,26 @@ +int x; + +void __attribute__((noinline)) foo (void) +{ + x = -x; +} +void __attribute__((const,noinline)) bar (void) +{ +} + +int __attribute__((noinline)) +test (int c) +{ + int tmp = x; + (c ? foo : bar) (); + return tmp + x; +} + +extern void abort (void); +int main() +{ + x = 1; + if (test (1) != 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c b/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c new file mode 100644 index 000000000000..917bf9e2b6f9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr34768-2.c @@ -0,0 +1,28 @@ +int x; + +int __attribute__((noinline)) foo (void) +{ + x = -x; + return 0; +} +int __attribute__((const,noinline)) bar (void) +{ + return 0; +} + +int __attribute__((noinline)) +test (int c) +{ + int tmp = x; + int res = (c ? foo : bar) (); + return tmp + x + res; +} + +extern void abort (void); +int main() +{ + x = 1; + if (test (1) != 0) + abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr28796-1.c b/gcc/testsuite/gcc.dg/pr28796-1.c new file mode 100644 index 000000000000..a762becdafb3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28796-1.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ +/* { dg-options "-ffinite-math-only" } */ + +float f; + +int main() +{ + if (__builtin_isunordered (f, f) != 0) + link_error (); + if (__builtin_isnan (f) != 0) + link_error (); + if (__builtin_finite (f) != 1) + link_error (); + if (f != f) + link_error (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr28796-2.c b/gcc/testsuite/gcc.dg/pr28796-2.c new file mode 100644 index 000000000000..8847d78df3b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr28796-2.c @@ -0,0 +1,21 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -funsafe-math-optimizations" } */ + +extern void abort (void); + +void foo(float f) +{ + if (__builtin_isunordered (f, f) != 1) + abort (); + if (__builtin_isnan (f) != 1) + abort (); + if (__builtin_finite (f) != 0) + abort (); +} + +int main() +{ + float f = __builtin_nanf(""); + foo(f); + return 0; +} -- 2.47.2