aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2023-11-28 13:02:35 -0500
committerAndrew MacLeod <amacleod@redhat.com>2023-11-29 11:43:53 -0500
commit634cf26c94de620e66aa124b8ec4d6c2be4b74b2 (patch)
tree72d2ca593e41e4f7fc6c111480ae536c57259157
parentea19de921b01a6ab470929f8da4dde526edb08f1 (diff)
downloadgcc-634cf26c94de620e66aa124b8ec4d6c2be4b74b2.zip
gcc-634cf26c94de620e66aa124b8ec4d6c2be4b74b2.tar.gz
gcc-634cf26c94de620e66aa124b8ec4d6c2be4b74b2.tar.bz2
Check operands before invoking fold_range.
Call check_operands_p before fold_range to make sure it is a valid operation. PR tree-optimization/111922 gcc/ * ipa-cp.cc (ipa_vr_operation_and_type_effects): Check the operands are valid before calling fold_range. gcc/testsuite/ * gcc.dg/pr111922.c: New.
-rw-r--r--gcc/ipa-cp.cc3
-rw-r--r--gcc/testsuite/gcc.dg/pr111922.c29
2 files changed, 31 insertions, 1 deletions
diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 34fae06..649ad53 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -1926,7 +1926,8 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr,
Value_Range varying (dst_type);
varying.set_varying (dst_type);
- return (handler.fold_range (dst_vr, dst_type, src_vr, varying)
+ return (handler.operand_check_p (dst_type, src_type, dst_type)
+ && handler.fold_range (dst_vr, dst_type, src_vr, varying)
&& !dst_vr.varying_p ()
&& !dst_vr.undefined_p ());
}
diff --git a/gcc/testsuite/gcc.dg/pr111922.c b/gcc/testsuite/gcc.dg/pr111922.c
new file mode 100644
index 0000000..4f429d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111922.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-fre" } */
+
+void f2 (void);
+void f4 (int, int, int);
+struct A { int a; };
+struct B { struct A *b; int c; } v;
+
+static int
+f1 (x, y)
+ struct C *x;
+ struct A *y;
+{
+ (v.c = v.b->a) || (v.c = v.b->a);
+ f2 ();
+}
+
+static void
+f3 (int x, int y)
+{
+ int b = f1 (0, ~x);
+ f4 (0, 0, v.c);
+}
+
+void
+f5 (void)
+{
+ f3 (0, 0);
+}