diff mbox series

[COMMITTED] PR tree-optimization/101497 - Check for undefined on COND_EXPR before querying type.

Message ID fe811159-363a-532e-ce9e-e01c470e5e07@redhat.com
State New
Headers show
Series [COMMITTED] PR tree-optimization/101497 - Check for undefined on COND_EXPR before querying type. | expand

Commit Message

Andrew MacLeod July 22, 2021, 12:54 p.m. UTC
Can't ask for the type of an UNDEFINED value.

Bootstrapped on x86_64 & powerpc64-unknown-linux-gnu with no 
regressions.  Pushed.

Andrew
diff mbox series

Patch

From ea789238b2c24eedf70b56257235adf3d33c5a0a Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 19 Jul 2021 15:16:25 -0400
Subject: [PATCH 2/3] Check for undefined on COND_EXPR before querying type.

	gcc/
	PR tree-optimization/101497
	* gimple-range-fold.cc (fold_using_range::range_of_cond_expr): Check
	for undefined.

	gcc/testsuite
	* gcc.dg/pr101497.c: New.
---
 gcc/gimple-range-fold.cc        |  3 ++-
 gcc/testsuite/gcc.dg/pr101497.c | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr101497.c

diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index f8578c013bc..f95af3d5866 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -1111,7 +1111,8 @@  fold_using_range::range_of_cond_expr  (irange &r, gassign *s, fur_source &src)
       r = range1;
       r.union_ (range2);
     }
-  gcc_checking_assert (range_compatible_p (r.type (), type));
+  gcc_checking_assert (r.undefined_p ()
+		       || range_compatible_p (r.type (), type));
   return true;
 }
 
diff --git a/gcc/testsuite/gcc.dg/pr101497.c b/gcc/testsuite/gcc.dg/pr101497.c
new file mode 100644
index 00000000000..fcfe0594f9b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr101497.c
@@ -0,0 +1,13 @@ 
+/* PR tree-optimization/101497 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wno-div-by-zero" } */
+
+char uc_1;
+int i_4, func_12_uli_6;
+void func_12() {
+  int *ptr_8 = &func_12_uli_6;
+  *ptr_8 = 0 >= 211 - uc_1 <= 0;
+  i_4 %= 0;
+  i_4 *= *ptr_8;
+}
+
-- 
2.17.2