Good catch. Probably not a common case as usually we're already in
supported type contexts when we get around to check range_compatible..
I guess it wouldn't hurt to put a gcc_checking_assert in
range_compatible_p to confirm that they are supported types before
returning true.
Certainly ok.
thanks
Andrew
On 10/15/24 04:27, Richard Biener wrote:
The range folding code of COND_EXPRs missed a check whether the
comparison operand type is supported.
Bootstrap and regtest in progress on x86_64-unknown-linux-gnu. I'll
push if that succeeds. There might be other places missing such
a check, not sure.
Richard.
PR tree-optimization/117138
* gimple-range-fold.cc (fold_using_range::condexpr_adjust):
Check if the comparison operand type is supported.
* gcc.dg/torture/pr117138.c: New testcase.
---
gcc/gimple-range-fold.cc | 3 ++-
gcc/testsuite/gcc.dg/torture/pr117138.c | 13 +++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/torture/pr117138.c
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc
index 65d31adde54..dcd0cae0351 100644
--- a/gcc/gimple-range-fold.cc
+++ b/gcc/gimple-range-fold.cc
@@ -1139,7 +1139,8 @@ fold_using_range::condexpr_adjust (vrange &r1, vrange
&r2, gimple *, tree cond,
|| TREE_CODE_CLASS (gimple_assign_rhs_code (cond_def)) !=
tcc_comparison)
return false;
tree type = TREE_TYPE (gimple_assign_rhs1 (cond_def));
- if (!range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def))))
+ if (!value_range::supports_type_p (type)
+ || !range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def))))
return false;
range_op_handler hand (gimple_assign_rhs_code (cond_def));
if (!hand)
diff --git a/gcc/testsuite/gcc.dg/torture/pr117138.c
b/gcc/testsuite/gcc.dg/torture/pr117138.c
new file mode 100644
index 00000000000..b32585d3a56
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr117138.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-msse4" { target { x86_64-*-* i?86-*-* } } } */
+
+int a, b;
+_Complex long c;
+
+void
+foo ()
+{
+ do
+ b = c || a;
+ while (a);
+}