public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix ICE with cast of division by zero (PR c/93348)
@ 2020-01-22  1:56 Joseph Myers
  0 siblings, 0 replies; only message in thread
From: Joseph Myers @ 2020-01-22  1:56 UTC (permalink / raw)
  To: gcc-patches

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.  Applied to 
mainline.  Will also backport to GCC 9 and 8 branches.

gcc/c:
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.

gcc/testsuite:
2020-01-22  Joseph Myers  <joseph@codesourcery.com>

	PR c/93348
	* gcc.c-torture/compile/pr93348-1.c: New test.

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 9866c83faf2..8df0849bd8b 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -5715,6 +5715,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/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);
+}

-- 
Joseph S. Myers
joseph@codesourcery.com

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

only message in thread, other threads:[~2020-01-22  1:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-22  1:56 Fix ICE with cast of division by zero (PR c/93348) Joseph Myers

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).