]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/117138 - fix ICE with vector comparison in COND_EXPR
authorRichard Biener <rguenther@suse.de>
Tue, 15 Oct 2024 08:23:06 +0000 (10:23 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 15 Oct 2024 09:15:25 +0000 (11:15 +0200)
The range folding code of COND_EXPRs missed a check whether the
comparison operand type is supported.

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
gcc/testsuite/gcc.dg/torture/pr117138.c [new file with mode: 0644]

index 65d31adde54c43613aed379748d5fc98c986ce5a..dcd0cae035171c995711e49b35fa529b8dc9d72e 100644 (file)
@@ -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 (file)
index 0000000..b32585d
--- /dev/null
@@ -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);
+}