c: Fix ICE with -fexcess-precision=standard [PR99136]
authorJakub Jelinek <jakub@redhat.com>
Thu, 18 Feb 2021 21:17:52 +0000 (22:17 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 18 Feb 2021 21:17:52 +0000 (22:17 +0100)
The following testcase ICEs on i686-linux, because c_finish_return wraps
c_fully_folded retval back into EXCESS_PRECISION_EXPR, but when the function
return type is void, we don't call convert_for_assignment on it that would
then be fully folded again, but just put the retval into RETURN_EXPR's
operand, so nothing removes it anymore and during gimplification we
ICE as EXCESS_PRECISION_EXPR is not handled.

This patch fixes it by not adding that EXCESS_PRECISION_EXPR in functions
returning void, the return value is ignored and all we need is evaluate any
side-effects of the expression.

2021-02-18  Jakub Jelinek  <jakub@redhat.com>

PR c/99136
* c-typeck.c (c_finish_return): Don't wrap retval into
EXCESS_PRECISION_EXPR in functions that return void.

* gcc.dg/pr99136.c: New test.

gcc/c/c-typeck.c
gcc/testsuite/gcc.dg/pr99136.c [new file with mode: 0644]

index 725dc510dc727e6e80acc83ac3e41267e3c54a1a..4e6d369c4c9c2555d78cd51addbf227516074a87 100644 (file)
@@ -10740,7 +10740,9 @@ c_finish_return (location_t loc, tree retval, tree origtype)
          retval = TREE_OPERAND (retval, 0);
        }
       retval = c_fully_fold (retval, false, NULL);
-      if (semantic_type)
+      if (semantic_type
+         && valtype != NULL_TREE
+         && TREE_CODE (valtype) != VOID_TYPE)
        retval = build1 (EXCESS_PRECISION_EXPR, semantic_type, retval);
     }
 
diff --git a/gcc/testsuite/gcc.dg/pr99136.c b/gcc/testsuite/gcc.dg/pr99136.c
new file mode 100644 (file)
index 0000000..1bd8446
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR c/99136 */
+/* { dg-do compile } */
+/* { dg-options "-w -fexcess-precision=standard" } */
+
+void
+foo (double x)
+{
+  return 1.0 / x;
+}