public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9422] c: Fix ICE with -fexcess-precision=standard [PR99136]
@ 2021-04-20 23:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-20 23:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:884f790b8414e377665706f51254e8bd49a72f0b

commit r9-9422-g884f790b8414e377665706f51254e8bd49a72f0b
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Thu Feb 18 22:17:52 2021 +0100

    c: Fix ICE with -fexcess-precision=standard [PR99136]
    
    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.
    
    (cherry picked from commit 3d7ce7ce6c03165ca1041b38e02428c925254968)

Diff:
---
 gcc/c/c-typeck.c               | 4 +++-
 gcc/testsuite/gcc.dg/pr99136.c | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 24106c126cd..e946abee6d5 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10532,7 +10532,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
index 00000000000..1bd8446811b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr99136.c
@@ -0,0 +1,9 @@
+/* PR c/99136 */
+/* { dg-do compile } */
+/* { dg-options "-w -fexcess-precision=standard" } */
+
+void
+foo (double x)
+{
+  return 1.0 / x;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-20 23:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 23:32 [gcc r9-9422] c: Fix ICE with -fexcess-precision=standard [PR99136] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).