diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2022-09-20 18:48:05 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2022-09-22 14:48:29 -0400 |
commit | b6f670ff706e35dc51a62db4206cb241dcac4963 (patch) | |
tree | e75faf9b622687f0b916cf05cd949874f7489cbc /gcc/gimple-range-op.cc | |
parent | f7e62b09300b6935bceaffb4c42f6edab80f52dc (diff) | |
download | gcc-b6f670ff706e35dc51a62db4206cb241dcac4963.zip gcc-b6f670ff706e35dc51a62db4206cb241dcac4963.tar.gz gcc-b6f670ff706e35dc51a62db4206cb241dcac4963.tar.bz2 |
Convert CFN_BUILT_IN_UBSAN_CHECK_* to range-ops.
* gimple-range-fold.cc (range_of_builtin_ubsan_call): Delete.
(range_of_builtin_int_call): Remove cases for
CFN_BUILT_IN_UBSAN_CHECK.
* gimple-range-op.cc (class cfn_ubsan): New.
(gimple_range_op_handler::maybe_builtin_call): Set arguments.
Diffstat (limited to 'gcc/gimple-range-op.cc')
-rw-r--r-- | gcc/gimple-range-op.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index bee2254..09b7dd2 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -576,6 +576,41 @@ public: } } op_cfn_clrsb; + +// Implement range operator for CFN_BUILT_IN_ +class cfn_ubsan : public range_operator +{ +public: + cfn_ubsan (enum tree_code code) { m_code = code; } + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &rh, relation_kind rel) const + { + range_op_handler handler (m_code, type); + gcc_checking_assert (handler); + + bool saved_flag_wrapv = flag_wrapv; + // Pretend the arithmetic is wrapping. If there is any overflow, + // we'll complain, but will actually do wrapping operation. + flag_wrapv = 1; + bool result = handler.fold_range (r, type, lh, rh, rel); + flag_wrapv = saved_flag_wrapv; + + // If for both arguments vrp_valueize returned non-NULL, this should + // have been already folded and if not, it wasn't folded because of + // overflow. Avoid removing the UBSAN_CHECK_* calls in that case. + if (result && r.singleton_p ()) + r.set_varying (type); + return result; + } +private: + enum tree_code m_code; +}; + +cfn_ubsan op_cfn_ubsan_add (PLUS_EXPR); +cfn_ubsan op_cfn_ubsan_sub (MINUS_EXPR); +cfn_ubsan op_cfn_ubsan_mul (MULT_EXPR); + // Set up a gimple_range_op_handler for any built in function which can be // supported via range-ops. @@ -655,6 +690,27 @@ gimple_range_op_handler::maybe_builtin_call () m_int = &op_cfn_clrsb; break; + case CFN_UBSAN_CHECK_ADD: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_add; + break; + + case CFN_UBSAN_CHECK_SUB: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_sub; + break; + + case CFN_UBSAN_CHECK_MUL: + m_op1 = gimple_call_arg (call, 0); + m_op2 = gimple_call_arg (call, 1); + m_valid = true; + m_int = &op_cfn_ubsan_mul; + break; + default: break; } |