diff mbox series

c: Fix ICE with -fexcess-precision=standard [PR99136]

Message ID 20210218083446.GZ4020736@tucnak
State New
Headers show
Series c: Fix ICE with -fexcess-precision=standard [PR99136] | expand

Commit Message

Jakub Jelinek Feb. 18, 2021, 8:34 a.m. UTC
Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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.


	Jakub

Comments

Joseph Myers Feb. 18, 2021, 8:15 p.m. UTC | #1
On Thu, 18 Feb 2021, Jakub Jelinek via Gcc-patches wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.
diff mbox series

Patch

--- gcc/c/c-typeck.c.jj	2021-02-04 23:41:24.200308485 +0100
+++ gcc/c/c-typeck.c	2021-02-17 19:43:30.348054337 +0100
@@ -10740,7 +10740,9 @@  c_finish_return (location_t loc, tree re
 	  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);
     }
 
--- gcc/testsuite/gcc.dg/pr99136.c.jj	2021-02-17 19:42:17.253844514 +0100
+++ gcc/testsuite/gcc.dg/pr99136.c	2021-02-17 19:42:09.684926337 +0100
@@ -0,0 +1,9 @@ 
+/* PR c/99136 */
+/* { dg-do compile } */
+/* { dg-options "-w -fexcess-precision=standard" } */
+
+void
+foo (double x)
+{
+  return 1.0 / x;
+}