diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2021-07-15 11:07:12 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2021-07-15 15:58:11 -0400 |
commit | 478cc962ad174bfc64c573152a0658935651fce3 (patch) | |
tree | 092b98b66e17b719def4a96973fcfb7851187538 /gcc/gimple-range-fold.h | |
parent | f0500db3692276f60e0562c17c87a0cb03e34398 (diff) | |
download | gcc-478cc962ad174bfc64c573152a0658935651fce3.zip gcc-478cc962ad174bfc64c573152a0658935651fce3.tar.gz gcc-478cc962ad174bfc64c573152a0658935651fce3.tar.bz2 |
Add gimple_range_type for statements.
The existing mechanisms for picking up the type of a statement are
inconsistent with the needs of ranger. Encapsulate all the bits
required to pick up the return type of a statement in one place, and check
whether the type is supported.
* gimple-range-fold.cc (adjust_pointer_diff_expr): Use
gimple_range_type.
(fold_using_range::fold_stmt): Ditto.
(fold_using_range::range_of_range_op): Ditto.
(fold_using_range::range_of_phi): Ditto.
(fold_using_range::range_of_call): Ditto.
(fold_using_range::range_of_builtin_ubsan_call): Ditto.
(fold_using_range::range_of_builtin_call): Ditto.
(fold_using_range::range_of_cond_expr): Ditto.
* gimple-range-fold.h (gimple_range_type): New.
Diffstat (limited to 'gcc/gimple-range-fold.h')
-rw-r--r-- | gcc/gimple-range-fold.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index dc1b28f..ceed7ba 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -56,6 +56,36 @@ gimple_range_handler (const gimple *s) return NULL; } +// Return the type of range which statement S calculates. If the type is +// unsupported or no type can be determined, return NULL_TREE. + +static inline tree +gimple_range_type (const gimple *s) +{ + tree lhs = gimple_get_lhs (s); + tree type = NULL_TREE; + if (lhs) + type = TREE_TYPE (lhs); + else + { + enum gimple_code code = gimple_code (s); + if (code == GIMPLE_COND) + type = boolean_type_node; + else if (code == GIMPLE_PHI) + type = TREE_TYPE (gimple_phi_result (s)); + else if (code == GIMPLE_CALL) + { + type = gimple_call_fntype (s); + // If it has a type, get the return type. + if (type) + type = TREE_TYPE (type); + } + } + if (irange::supports_type_p (type)) + return type; + return NULL_TREE; +} + // Return EXP if it is an SSA_NAME with a type supported by gimple ranges. static inline tree |