diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2022-05-13 13:11:18 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2022-05-13 14:38:50 -0400 |
commit | e97e99296505e6015bc9e281364818bb89ca8a49 (patch) | |
tree | 074f420c07e8ab9dc8c6b038b2627025d0689ab0 /gcc | |
parent | 70d624ff067920d6d57ce5064ddc2a2411377488 (diff) | |
download | gcc-e97e99296505e6015bc9e281364818bb89ca8a49.zip gcc-e97e99296505e6015bc9e281364818bb89ca8a49.tar.gz gcc-e97e99296505e6015bc9e281364818bb89ca8a49.tar.bz2 |
Check operand for type, not LHS.
When folding, the LHS has not been set, so we should be checking the type of
op1. We should also make sure op1 is not undefined.
PR tree-optimization/105597
gcc/
* range-op.cc (operator_minus::lhs_op1_relation): Use op1 instead
of the lhs and make sure it is not undefined.
gcc/testsuite/
* gcc.dg/pr105597.c: New.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/range-op.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr105597.c | 27 |
2 files changed, 29 insertions, 2 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc index e6b32e2..c88da8c 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1343,10 +1343,10 @@ operator_minus::wi_fold (irange &r, tree type, // OP1 and OP2. relation_kind -operator_minus::lhs_op1_relation (const irange &lhs, const irange &, +operator_minus::lhs_op1_relation (const irange &, const irange &op1, const irange &, relation_kind rel) const { - if (TYPE_SIGN (lhs.type ()) == UNSIGNED) + if (!op1.undefined_p () && TYPE_SIGN (op1.type ()) == UNSIGNED) switch (rel) { case VREL_GT: diff --git a/gcc/testsuite/gcc.dg/pr105597.c b/gcc/testsuite/gcc.dg/pr105597.c new file mode 100644 index 0000000..e463ec6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105597.c @@ -0,0 +1,27 @@ +/* PR tree-optimization/105597 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wno-int-conversion" } */ + +typedef struct { + int allocated; +} vvec; + +int vvneeds_want, mgpssort; + +void vvinit(vvec *v, int minelems) { v->allocated = -minelems; } + +void vvneeds(vvec *v, int needed) { + if (needed > v->allocated) + if (v->allocated < 0) + ; + else { + int next = v->allocated + (v->allocated >> 1); + vvneeds_want = next; + } +} + +void mgpssort_1() { + vvinit((vvec *) &mgpssort, mgpssort_1); + vvneeds((vvec *) &mgpssort, mgpssort_1); +} + |