public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Fix ICE with cast of division by zero (PR c/93348).
Date: Thu, 17 Sep 2020 16:36:18 +0000 (GMT)	[thread overview]
Message-ID: <20200917163618.A035E39878FD@sourceware.org> (raw)

https://gcc.gnu.org/g:cd15f22c73a21f002c8d379b6d7613810fd94e8c

commit cd15f22c73a21f002c8d379b6d7613810fd94e8c
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Jan 22 20:49:41 2020 +0000

    Fix ICE with cast of division by zero (PR c/93348).
    
    Bug 93348 reports an ICE on certain cases of casts of expressions that
    may appear only in unevaluated parts of integer constant expressions,
    arising from the generation of nested C_MAYBE_CONST_EXPRs.  This patch
    fixes it by adding a call to remove_c_maybe_const_expr in the
    integer-operands case, as is done in other similar cases.
    
    Bootstrapped with no regressions for x86_64-pc-linux-gnu.
    
            PR c/93348
    gcc/c:
            * c-typeck.c (build_c_cast): Call remove_c_maybe_const_expr on
            argument with integer operands.
    
    gcc/testsuite:
            * gcc.c-torture/compile/pr93348-1.c: New test.
    
    (cherry picked from commit ac68e287fc2e939ae6b45ba7ff04e493982b7f62)

Diff:
---
 gcc/c/ChangeLog                                 | 9 +++++++++
 gcc/c/c-typeck.c                                | 2 ++
 gcc/testsuite/ChangeLog                         | 8 ++++++++
 gcc/testsuite/gcc.c-torture/compile/pr93348-1.c | 5 +++++
 4 files changed, 24 insertions(+)

diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index d07af203e1a..50fb412634d 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,12 @@
+2020-01-22  Joseph Myers  <joseph@codesourcery.com>
+
+	Backport from mainline:
+	2020-01-22  Joseph Myers  <joseph@codesourcery.com>
+
+	PR c/93348
+	* c-typeck.c (build_c_cast): Call remove_c_maybe_const_expr on
+	argument with integer operands.
+
 2020-01-15  Joseph Myers  <joseph@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 00536d2a00b..8c4a1939f3d 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -5544,6 +5544,8 @@ build_c_cast (location_t loc, tree type, tree expr)
     expr = TREE_OPERAND (expr, 0);
 
   value = expr;
+  if (int_operands)
+    value = remove_c_maybe_const_expr (value);
 
   if (type == error_mark_node || expr == error_mark_node)
     return error_mark_node;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5e769101ff3..b943d22bf6f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-01-22  Joseph Myers  <joseph@codesourcery.com>
+
+	Backport from mainline:
+	2020-01-22  Joseph Myers  <joseph@codesourcery.com>
+
+	PR c/93348
+	* gcc.c-torture/compile/pr93348-1.c: New test.
+
 2020-01-15  Joseph Myers  <joseph@codesourcery.com>
 
 	Backport from mainline:
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr93348-1.c b/gcc/testsuite/gcc.c-torture/compile/pr93348-1.c
new file mode 100644
index 00000000000..d2edec565ee
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr93348-1.c
@@ -0,0 +1,5 @@
+int
+ya (void)
+{
+  return (long int) (1 / 0);
+}


                 reply	other threads:[~2020-09-17 16:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200917163618.A035E39878FD@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).