diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2022-10-06 19:11:08 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2022-10-06 22:40:50 +0200 |
commit | 49b9a8c8cc498b1ed2f566bee858e651e14ba37b (patch) | |
tree | ba30488673d752d265d0924ff18e6ffd79818a3c /gcc | |
parent | 629b4813e91aba0a8fc9b18434ec1808776a4b3d (diff) | |
download | gcc-49b9a8c8cc498b1ed2f566bee858e651e14ba37b.zip gcc-49b9a8c8cc498b1ed2f566bee858e651e14ba37b.tar.gz gcc-49b9a8c8cc498b1ed2f566bee858e651e14ba37b.tar.bz2 |
[PR107170] Avoid copying incompatible types in legacy VRP.
Legacy VRP is calling ranger deep inside the bowels, and then trying to
copy an incompatible type. My previous patch in this area assumed that
the only possibility out of vr_values::get_value_range for an
unsupported type was VARYING, but UNDEFINED can also be returned.
PR tree-optimization/107170
gcc/ChangeLog:
* vr-values.cc (vr_values::range_of_expr): Do not die on
unsupported types.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr107170.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr107170.c | 8 | ||||
-rw-r--r-- | gcc/vr-values.cc | 24 |
2 files changed, 21 insertions, 11 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c new file mode 100644 index 0000000..7a5a4a3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107170.c @@ -0,0 +1,8 @@ +// { dg-do compile } +// { dg-options "-O2" } + +int main() { + double a; + if (__builtin_signbit(a)) + __builtin_abort(); +} diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index 626a918..71fed1e 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -184,21 +184,23 @@ vr_values::range_of_expr (vrange &r, tree expr, gimple *stmt) if (const value_range *vr = get_value_range (expr, stmt)) { + if (!vr->supports_type_p (TREE_TYPE (expr))) + { + // vr_values::extract_range_basic() use of ranger's + // fold_range() can create a situation where we are asked + // for the range of an unsupported legacy type. Since + // get_value_range() above will return varying or undefined + // for such types, avoid copying incompatible range types. + if (vr->undefined_p ()) + r.set_undefined (); + else + r.set_varying (TREE_TYPE (expr)); + return true; + } if (vr->undefined_p () || vr->constant_p ()) r = *vr; else { - if (!vr->supports_type_p (TREE_TYPE (expr))) - { - // vr_values::extract_range_basic() use of ranger's - // fold_range() can create a situation where we are - // asked for the range of an unsupported legacy type. - // Since get_value_range() above will return varying for - // such types, avoid copying incompatible range types. - gcc_checking_assert (vr->varying_p ()); - r.set_varying (TREE_TYPE (expr)); - return true; - } value_range tmp = *vr; tmp.normalize_symbolics (); r = tmp; |