GCC Middle and Back End API Reference
sanopt.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "ssa.h"
#include "tree-pass.h"
#include "tree-ssa-operands.h"
#include "gimple-pretty-print.h"
#include "fold-const.h"
#include "gimple-iterator.h"
#include "stringpool.h"
#include "attribs.h"
#include "asan.h"
#include "ubsan.h"
#include "tree-hash-traits.h"
#include "gimple-ssa.h"
#include "tree-phinodes.h"
#include "ssa-iterators.h"
#include "gimplify.h"
#include "gimple-walk.h"
#include "cfghooks.h"
#include "tree-dfa.h"
#include "tree-ssa.h"
#include "varasm.h"
Include dependency graph for sanopt.cc:

Data Structures

struct  sanopt_info
struct  sanopt_tree_triplet
struct  sanopt_tree_triplet_hash
struct  sanopt_tree_couple
struct  sanopt_tree_couple_hash
class  sanopt_ctx


static gimplemaybe_get_single_definition (tree t)
static bool imm_dom_path_with_freeing_call (basic_block bb, basic_block dom)
static gimplemaybe_get_dominating_check (auto_vec< gimple * > &v)
static bool maybe_optimize_ubsan_null_ifn (class sanopt_ctx *ctx, gimple *stmt)
static bool has_dominating_ubsan_ptr_check (sanopt_ctx *ctx, tree ptr, offset_int &cur_offset)
static void record_ubsan_ptr_check_stmt (sanopt_ctx *ctx, gimple *stmt, tree ptr, const offset_int &offset)
static bool maybe_optimize_ubsan_ptr_ifn (sanopt_ctx *ctx, gimple *stmt)
static bool maybe_optimize_ubsan_vptr_ifn (class sanopt_ctx *ctx, gimple *stmt)
static bool same_value_p (gimple *check, gimple *use, tree t)
static bool can_remove_asan_check (auto_vec< gimple * > &v, tree len, basic_block bb, gimple *base_stmt, tree base_addr)
static bool maybe_optimize_asan_check_ifn (class sanopt_ctx *ctx, gimple *stmt)
static void sanopt_optimize_walker (basic_block bb, class sanopt_ctx *ctx)
static int sanopt_optimize (function *fun, bool *contains_asan_mark)
gimple_opt_passmake_pass_sanopt (gcc::context *ctxt)

Function Documentation

◆ can_remove_asan_check()

static bool can_remove_asan_check ( auto_vec< gimple * > & v,
tree len,
basic_block bb,
gimple * base_stmt,
tree base_addr )

◆ has_dominating_ubsan_ptr_check()

static bool has_dominating_ubsan_ptr_check ( sanopt_ctx * ctx,
tree ptr,
offset_int & cur_offset )

◆ imm_dom_path_with_freeing_call()

◆ make_pass_sanopt()

gimple_opt_pass * make_pass_sanopt ( gcc::context * ctxt)

◆ maybe_get_dominating_check()

static gimple * maybe_get_dominating_check ( auto_vec< gimple * > & v)
Get the first dominating check from the list of stored checks.
Non-dominating checks are silently dropped.   

References basic_block_def::aux, g, gimple_bb(), NULL, and si.

Referenced by has_dominating_ubsan_ptr_check(), maybe_optimize_asan_check_ifn(), maybe_optimize_ubsan_null_ifn(), and maybe_optimize_ubsan_vptr_ifn().

◆ maybe_get_single_definition()

static gimple * maybe_get_single_definition ( tree t)
If T has a single definition of form T = T2, return T2.   

References g, gimple_assign_single_p(), NULL, SSA_NAME_DEF_STMT, and TREE_CODE.

Referenced by maybe_optimize_asan_check_ifn().

◆ maybe_optimize_asan_check_ifn()

◆ maybe_optimize_ubsan_null_ifn()

◆ maybe_optimize_ubsan_ptr_ifn()

◆ maybe_optimize_ubsan_vptr_ifn()

static bool maybe_optimize_ubsan_vptr_ifn ( class sanopt_ctx * ctx,
gimple * stmt )
Optimize away redundant UBSAN_VPTR calls.  The second argument
is the value loaded from the virtual table, so rely on FRE to find out
when we can actually optimize.   

References g, gcc_assert, hash_map< KeyId, Value, Traits >::get_or_insert(), gimple_call_arg(), gimple_call_num_args(), maybe_get_dominating_check(), sanopt_tree_triplet::t1, sanopt_tree_triplet::t2, sanopt_tree_triplet::t3, and sanopt_ctx::vptr_check_map.

Referenced by sanopt_optimize_walker().

◆ record_ubsan_ptr_check_stmt()

static void record_ubsan_ptr_check_stmt ( sanopt_ctx * ctx,
gimple * stmt,
tree ptr,
const offset_int & offset )
Record UBSAN_PTR check of given context CTX.  Register pointer PTR on
a given OFFSET that it's handled by GIMPLE STMT.   

References hash_map< KeyId, Value, Traits >::get_or_insert(), wi::neg_p(), offset, sanopt_tree_couple::pos_p, sanopt_tree_couple::ptr, and sanopt_ctx::ptr_check_map.

Referenced by maybe_optimize_ubsan_ptr_ifn().

◆ same_value_p()

static bool same_value_p ( gimple * check,
gimple * use,
tree t )
Checks whether value of T in CHECK and USE is the same.   

References gimple_vuse(), is_gimple_min_invariant(), and TREE_CODE.

Referenced by can_remove_asan_check().

◆ sanopt_optimize()

static int sanopt_optimize ( function * fun,
bool * contains_asan_mark )

◆ sanopt_optimize_walker()

static void sanopt_optimize_walker ( basic_block bb,
class sanopt_ctx * ctx )
Try to optimize away redundant UBSAN_NULL and ASAN_CHECK calls.

We walk blocks in the CFG via a depth first search of the dominator
tree; we push unique UBSAN_NULL or ASAN_CHECK statements into a vector
in the NULL_CHECK_MAP or ASAN_CHECK_MAP hash maps as we enter the
blocks.  When leaving a block, we mark the block as visited; then
when checking the statements in the vector, we ignore statements that
are coming from already visited blocks, because these cannot dominate
anything anymore.  CTX is a sanopt context.   

References sanopt_ctx::asan_num_accesses, basic_block_def::aux, CDI_DOMINATORS, sanopt_ctx::contains_asan_mark, dump_file, dump_flags, dyn_cast(), first_dom_son(), sanopt_info::freeing_call_events, gcc_assert, gimple_asm_clobbers_memory_p(), gimple_asm_volatile_p(), gimple_call_builtin_p(), gimple_call_internal_fn(), gimple_call_internal_p(), gimple_vdef(), gsi_end_p(), gsi_for_stmt(), gsi_next(), gsi_remove(), gsi_start_bb(), gsi_stmt(), sanopt_info::has_freeing_call_computed_p, sanopt_info::has_freeing_call_p, hwasan_sanitize_p(), is_gimple_call(), maybe_optimize_asan_check_ifn(), maybe_optimize_ubsan_null_ifn(), maybe_optimize_ubsan_ptr_ifn(), maybe_optimize_ubsan_vptr_ifn(), next_dom_son(), nonfreeing_call_p(), print_gimple_stmt(), SANITIZE_ADDRESS, SANITIZE_HWADDRESS, sanopt_optimize_walker(), single_imm_use(), TDF_DETAILS, unlink_stmt_vdef(), and sanopt_info::visited_p.

Referenced by sanopt_optimize(), and sanopt_optimize_walker().