]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/89520 (ICE tree check: accessed operand 4 of call_expr with 3 opera...
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Aug 2019 12:11:06 +0000 (14:11 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 12:11:06 +0000 (14:11 +0200)
Backported from mainline
2019-02-28  Jakub Jelinek  <jakub@redhat.com>

PR c/89520
* convert.c (convert_to_real_1, convert_to_integer_1): Punt for
builtins if they don't have a single scalar floating point argument.
Formatting fixes.

* gcc.dg/pr89520-1.c: New test.
* gcc.dg/pr89520-2.c: New test.

From-SVN: r275120

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr89520-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr89520-2.c [new file with mode: 0644]

index e8ef679c84d10e798fae0c8517a9966b896c63d9..29a1f92b12698acdb43cef66efa38da8f013a349 100644 (file)
@@ -1,6 +1,13 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/89520
+       * convert.c (convert_to_real_1, convert_to_integer_1): Punt for
+       builtins if they don't have a single scalar floating point argument.
+       Formatting fixes.
+
        2019-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/89412
index 8737f4d39656f1c6f28cb1f4f00738718c016bcc..3a1a80f8150a47921faa33879a05cbd417e26679 100644 (file)
@@ -190,12 +190,15 @@ convert_to_real_1 (tree type, tree expr, bool fold_p)
          CASE_MATHFN (FABS)
          CASE_MATHFN (LOGB)
 #undef CASE_MATHFN
+           if (call_expr_nargs (expr) != 1
+               || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (expr, 0))))
+             break;
            {
              tree arg0 = strip_float_extensions (CALL_EXPR_ARG (expr, 0));
              tree newtype = type;
 
-             /* We have (outertype)sqrt((innertype)x).  Choose the wider mode from
-                the both as the safe type for operation.  */
+             /* We have (outertype)sqrt((innertype)x).  Choose the wider mode
+                from the both as the safe type for operation.  */
              if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type))
                newtype = TREE_TYPE (arg0);
 
@@ -579,7 +582,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
 
        CASE_FLT_FN (BUILT_IN_ROUND):
          /* Only convert in ISO C99 mode and with -fno-math-errno.  */
-         if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
+         if (!targetm.libc_has_function (function_c99_misc)
+             || flag_errno_math)
            break;
          if (outprec < TYPE_PRECISION (integer_type_node)
              || (outprec == TYPE_PRECISION (integer_type_node)
@@ -600,7 +604,8 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
          gcc_fallthrough ();
        CASE_FLT_FN (BUILT_IN_RINT):
          /* Only convert in ISO C99 mode and with -fno-math-errno.  */
-         if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
+         if (!targetm.libc_has_function (function_c99_misc)
+             || flag_errno_math)
            break;
          if (outprec < TYPE_PRECISION (integer_type_node)
              || (outprec == TYPE_PRECISION (integer_type_node)
@@ -615,13 +620,19 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
          break;
 
        CASE_FLT_FN (BUILT_IN_TRUNC):
-         return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0), dofold);
+         if (call_expr_nargs (s_expr) != 1
+             || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
+           break;
+         return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0),
+                                      dofold);
 
        default:
          break;
        }
 
-      if (fn)
+      if (fn
+         && call_expr_nargs (s_expr) == 1
+         && SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
         {
          tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
          return convert_to_integer_1 (type, newexpr, dofold);
@@ -652,7 +663,9 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
          break;
        }
 
-      if (fn)
+      if (fn
+         && call_expr_nargs (s_expr) == 1
+         && SCALAR_FLOAT_TYPE_P (TREE_TYPE (CALL_EXPR_ARG (s_expr, 0))))
         {
          tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
          return convert_to_integer_1 (type, newexpr, dofold);
index 481d42a7a9b2959173ccde9f162647884061148e..d6e5983fc98d0ffa1c4b6442e96377aa84bfe780 100644 (file)
@@ -1,6 +1,12 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-02-28  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/89520
+       * gcc.dg/pr89520-1.c: New test.
+       * gcc.dg/pr89520-2.c: New test.
+
        2019-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/89403
diff --git a/gcc/testsuite/gcc.dg/pr89520-1.c b/gcc/testsuite/gcc.dg/pr89520-1.c
new file mode 100644 (file)
index 0000000..128e835
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c/89520 */
+/* { dg-do compile } */
+/* { dg-options "-Ofast -w" } */
+
+#define A(name) __typeof (__builtin_##name (0)) name (); long name##1 () { return name (); }
+#define B(name) A(name) A(name##f) A(name##l)
+B (ceil)
+B (floor)
+B (round)
+B (trunc)
+B (nearbyint)
+B (rint)
+B (logb)
diff --git a/gcc/testsuite/gcc.dg/pr89520-2.c b/gcc/testsuite/gcc.dg/pr89520-2.c
new file mode 100644 (file)
index 0000000..8edafa7
--- /dev/null
@@ -0,0 +1,42 @@
+/* PR c/89520 */
+/* { dg-do compile } */
+/* { dg-options "-Ofast -w" } */
+
+#define A(name) __typeof (__builtin_##name (0)) name (); \
+  float name##1 () { return name (); } \
+  double name##2 () { return name (); }
+#define B(name) A(name) A(name##l)
+B (cosh)
+B (exp)
+B (exp10)
+B (exp2)
+B (expm1)
+B (gamma)
+B (j0)
+B (j1)
+B (lgamma)
+B (pow10)
+B (sinh)
+B (tgamma)
+B (y0)
+B (y1)
+B (acos)
+B (acosh)
+B (asin)
+B (asinh)
+B (atan)
+B (atanh)
+B (cbrt)
+B (cos)
+B (erf)
+B (erfc)
+B (log)
+B (log10)
+B (log2)
+B (log1p)
+B (sin)
+B (tan)
+B (tanh)
+B (sqrt)
+B (fabs)
+B (logb)