]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport PRs 28796, 34070, 34739, 34768
authorRichard Guenther <rguenther@suse.de>
Tue, 22 Jan 2008 14:45:56 +0000 (14:45 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 22 Jan 2008 14:45:56 +0000 (14:45 +0000)
2008-01-22  Richard Guenther  <rguenther@suse.de>

PR middle-end/34739
Backport from mainline
2008-01-16  Richard Guenther  <rguenther@suse.de>

PR c/34768
* c-typeck.c (common_pointer_type): Do not merge inconsistent
type qualifiers for function types.

2007-11-12  Richard Guenther  <rguenther@suse.de>

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  <rguenther@suse.de>

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
gcc/builtins.c
gcc/c-typeck.c
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr34070-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr34070-2.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr34768-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr34768-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr28796-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr28796-2.c [new file with mode: 0644]

index e7e74a8faa449b09a25d401cacd9355bf02a897a..4c52209fc4d538aa591a3e8ebc3835406866fd19 100644 (file)
@@ -1,3 +1,28 @@
+2008-01-22  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34739
+       Backport from mainline
+       2008-01-16  Richard Guenther  <rguenther@suse.de>
+
+       PR c/34768
+       * c-typeck.c (common_pointer_type): Do not merge inconsistent
+       type qualifiers for function types.
+
+       2007-11-12  Richard Guenther  <rguenther@suse.de>
+
+       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  <rguenther@suse.de>
+
+       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  <ebotcazou@adacore.com>
 
        Backport from mainline:
index 3273586333cc7085e6bbdf190ad2ab2681cffee0..87867c6f51bafcb4f2194d48638e4278efbe8e14 100644 (file)
@@ -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));
 }
index c843acfd79a7f01a26e08fefa422df502b6a8d18..9646bd6e4360c14fb239ba8c88b2f6b829ebf7e1 100644 (file)
@@ -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);
 }
 
index 81b1d4f84cd86bed5a75d70602535ff6b545a757..782a30200ce96ec257aca585b7ca9dbab341fdd7 100644 (file)
@@ -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,
index 09e72beadf24694fae1f5455036c777d0a0384fe..18befa98f2c349e9541d2f9699ba5cd8cc6b2de0 100644 (file)
@@ -1,3 +1,25 @@
+2008-01-22  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/34739
+       Backport from mainline
+       2008-01-16  Richard Guenther  <rguenther@suse.de>
+
+       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  <rguenther@suse.de>
+
+       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  <rguenther@suse.de>
+
+       PR middle-end/28796
+       * gcc.dg/pr28796-1.c: New testcase.
+       * gcc.dg/pr28796-2.c: Likewise.
+
 2008-01-19  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>
 
        * 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 (file)
index 0000000..6589bb0
--- /dev/null
@@ -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 (file)
index 0000000..4c1ce7b
--- /dev/null
@@ -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 (file)
index 0000000..eb16adb
--- /dev/null
@@ -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 (file)
index 0000000..917bf9e
--- /dev/null
@@ -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 (file)
index 0000000..a762bec
--- /dev/null
@@ -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 (file)
index 0000000..8847d78
--- /dev/null
@@ -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;
+}