Fix ICE with cast of division by zero (PR c/93348).
authorJoseph Myers <joseph@codesourcery.com>
Wed, 22 Jan 2020 01:23:42 +0000 (01:23 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Wed, 22 Jan 2020 01:23:42 +0000 (01:23 +0000)
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.

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr93348-1.c [new file with mode: 0644]

index c6387560b40f4b059efe2b503a0eecce72b46eb0..9497365a5696e609707a49c294fb2e700f8fd1c6 100644 (file)
@@ -1,3 +1,9 @@
+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-16  Kerem Kat  <keremkat@gmail.com>
 
        PR c/92833
index 9866c83faf22cf34eccd538133fde7cb5ef845cf..8df0849bd8b41f44ac80571c63b59c122acd2e3d 100644 (file)
@@ -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;
index 968145362c212e1e8030a7fa8bcbec940789e3f5..f72c98797284014be98d20bcb2c7e640d531b4ae 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-22  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/93348
+       * gcc.c-torture/compile/pr93348-1.c: New test.
+
 2020-01-21  David Malcolm  <dmalcolm@redhat.com>
 
        PR analyzer/93352
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 (file)
index 0000000..d2edec5
--- /dev/null
@@ -0,0 +1,5 @@
+int
+ya (void)
+{
+  return (long int) (1 / 0);
+}