GCC Middle and Back End API Reference
|
Go to the source code of this file.
Functions | |
bool | ubsan_expand_bounds_ifn (gimple_stmt_iterator *) |
bool | ubsan_expand_null_ifn (gimple_stmt_iterator *) |
bool | ubsan_expand_objsize_ifn (gimple_stmt_iterator *) |
bool | ubsan_expand_ptr_ifn (gimple_stmt_iterator *) |
bool | ubsan_expand_vptr_ifn (gimple_stmt_iterator *) |
bool | ubsan_instrument_unreachable (gimple_stmt_iterator *) |
tree | ubsan_create_data (const char *, int, const location_t *,...) |
tree | ubsan_type_descriptor (tree, ubsan_print_style=UBSAN_PRINT_NORMAL) |
tree | ubsan_encode_value (tree, ubsan_encode_value_phase=UBSAN_ENCODE_VALUE_GENERIC) |
bool | is_ubsan_builtin_p (tree) |
tree | ubsan_build_overflow_builtin (tree_code, location_t, tree, tree, tree, tree *) |
tree | ubsan_instrument_float_cast (location_t, tree, tree) |
tree | ubsan_get_source_location_type (void) |
tree | sanitize_unreachable_fn (tree *data, location_t loc) |
enum ubsan_null_ckind |
UndefinedBehaviorSanitizer, undefined behavior detector. Copyright (C) 2013-2025 Free Software Foundation, Inc. Contributed by Marek Polacek <polacek@redhat.com> This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>.
The various kinds of NULL pointer checks.
Enumerator | |
---|---|
UBSAN_LOAD_OF | |
UBSAN_STORE_OF | |
UBSAN_REF_BINDING | |
UBSAN_MEMBER_ACCESS | |
UBSAN_MEMBER_CALL | |
UBSAN_CTOR_CALL | |
UBSAN_DOWNCAST_POINTER | |
UBSAN_DOWNCAST_REFERENCE | |
UBSAN_UPCAST | |
UBSAN_CAST_TO_VBASE |
enum ubsan_print_style |
Return true if T is a call to a libubsan routine.
References BUILT_IN_NORMAL, DECL_NAME, fndecl_built_in_p(), IDENTIFIER_POINTER, and TREE_CODE.
Shared between *build_builtin_unreachable.
References build_fold_addr_expr_loc(), builtin_decl_explicit(), NULL_TREE, sanitize_flags_p(), SANITIZE_UNREACHABLE, and ubsan_create_data().
Referenced by build_builtin_unreachable(), and gimple_build_builtin_unreachable().
|
extern |
Build an ubsan builtin call for the signed-integer-overflow sanitization. CODE says what kind of builtin are we building, LOC is a location, LHSTYPE is the type of LHS, OP0 and OP1 are operands of the binary operation.
References build_call_expr_loc(), build_fold_addr_expr_loc(), builtin_decl_explicit(), gcc_unreachable, NULL_TREE, SANITIZE_SI_OVERFLOW, ubsan_create_data(), ubsan_encode_value(), UBSAN_ENCODE_VALUE_RTL, and ubsan_type_descriptor().
Referenced by expand_addsub_overflow(), expand_mul_overflow(), and expand_neg_overflow().
|
extern |
Create a structure for the ubsan library. NAME is a name of the new structure. LOCCNT is number of locations, PLOC points to array of locations. The arguments in ... are of __ubsan_type_descriptor type and there are at most two of them, followed by NULL_TREE, followed by optional extra arguments and another NULL_TREE.
References build_constructor(), build_decl(), build_pointer_type(), CONSTRUCTOR_APPEND_ELT, DECL_ARTIFICIAL, DECL_CHAIN, DECL_CONTEXT, DECL_EXTERNAL, DECL_IGNORED_P, DECL_INITIAL, fields, varpool_node::finalize_decl(), gcc_checking_assert, get_identifier(), i, initialize_sanitizer_builtins(), input_location, layout_type(), LOCATION_LOCUS, make_node(), NULL, NULL_TREE, TREE_CONSTANT, TREE_PUBLIC, TREE_STATIC, TREE_TYPE, TYPE_ARTIFICIAL, TYPE_FIELDS, TYPE_NAME, TYPE_STUB_DECL, ubsan_get_source_location_type(), ubsan_get_type_descriptor_type(), ubsan_ids, ubsan_source_location(), UNKNOWN_LOCATION, vec_alloc(), vec_safe_length(), and vec_safe_push().
Referenced by instrument_bool_enum_load(), instrument_builtin(), instrument_nonnull_arg(), instrument_nonnull_return(), sanitize_unreachable_fn(), ubsan_build_overflow_builtin(), ubsan_expand_bounds_ifn(), ubsan_expand_null_ifn(), ubsan_expand_objsize_ifn(), ubsan_expand_ptr_ifn(), ubsan_expand_vptr_ifn(), and ubsan_instrument_float_cast().
|
extern |
Helper routine, which encodes a value in the pointer_sized_int_node. Arguments with precision <= POINTER_SIZE are passed directly, the rest is passed by reference. T is a value we are to encode. PHASE determines when this function is called.
References assign_stack_temp_for_type(), build2(), build4(), build_fold_addr_expr, build_nonstandard_integer_type(), build_zero_cst(), create_tmp_var, create_tmp_var_raw(), current_function_decl, DECL_CONTEXT, DECL_P, expand_assignment(), fold_build1, fold_convert, gcc_unreachable, GET_MODE_BITSIZE(), GET_MODE_SIZE(), mark_addressable(), MAX_FIXED_MODE_SIZE, NULL_TREE, POINTER_SIZE, pointer_sized_int_node, SCALAR_TYPE_MODE, SET_DECL_RTL, TREE_ADDRESSABLE, TREE_CODE, TREE_TYPE, TYPE_PRECISION, TYPE_UNSIGNED, UBSAN_ENCODE_VALUE_GENERIC, UBSAN_ENCODE_VALUE_RTL, and void_type_node.
Referenced by instrument_bool_enum_load(), ubsan_build_overflow_builtin(), ubsan_expand_bounds_ifn(), and ubsan_instrument_float_cast().
|
extern |
Expand the UBSAN_BOUNDS special builtin function.
References build_fold_addr_expr_loc(), builtin_decl_explicit(), create_cond_insert_point(), fold_convert, force_gimple_operand_gsi(), g, gcc_assert, gimple_build_call(), gimple_build_cond(), gimple_call_arg(), gimple_call_num_args(), gimple_location(), gimple_set_location(), gsi_after_labels(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_remove(), GSI_SAME_STMT, gsi_start_bb(), gsi_stmt(), NULL_TREE, SANITIZE_BOUNDS, TREE_TYPE, ubsan_create_data(), ubsan_encode_value(), UBSAN_ENCODE_VALUE_GIMPLE, UBSAN_PRINT_ARRAY, ubsan_type_descriptor(), and unlink_stmt_vdef().
|
extern |
Expand UBSAN_NULL internal call. The type is kept on the ckind argument which is a constant, because the middle-end treats pointer conversions as useless and therefore the type of the first argument could be changed to any other pointer type.
References add_bb_to_loop(), ADDR_SPACE_GENERIC_P, build_fold_addr_expr_loc(), build_int_cst(), build_zero_cst(), builtin_decl_implicit(), CDI_DOMINATORS, compare_tree_int(), basic_block_def::count, create_empty_bb(), dom_info_available_p(), find_edge(), fold_convert, g, gcc_assert, get_pointer_alignment(), gimple_assign_lhs(), gimple_build_assign(), gimple_build_call(), gimple_build_cond(), gimple_call_arg(), gimple_call_num_args(), gimple_location(), gimple_set_location(), gsi_bb(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_remove(), gsi_replace(), GSI_SAME_STMT, gsi_start_bb(), gsi_stmt(), integer_zerop(), basic_block_def::loop_father, LOOPS_NEED_FIXUP, loops_state_set(), make_edge(), make_single_succ_edge(), make_ssa_name(), MAX, NULL_TREE, pointer_sized_int_node, POINTER_TYPE_P, SANITIZE_ALIGNMENT, sanitize_flags_p(), SANITIZE_NULL, set_immediate_dominator(), split_block(), targetm, tree_log2(), tree_to_uhwi(), TREE_TYPE, TYPE_ADDR_SPACE, ubsan_create_data(), UBSAN_PRINT_POINTER, ubsan_type_descriptor(), unlink_stmt_vdef(), unsigned_char_type_node, profile_probability::very_likely(), and profile_probability::very_unlikely().
|
extern |
Expand UBSAN_OBJECT_SIZE internal call.
References build_fold_addr_expr_loc(), build_zero_cst(), builtin_decl_explicit(), create_cond_insert_point(), g, gcc_assert, gimple_assign_lhs(), gimple_build_assign(), gimple_build_call(), gimple_build_cond(), gimple_call_arg(), gimple_call_num_args(), gimple_location(), gimple_set_location(), gsi_after_labels(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_remove(), GSI_SAME_STMT, gsi_start_bb(), gsi_stmt(), integer_all_onesp(), make_ssa_name(), NULL_TREE, OBJSZ_MAX_OFFSET, offset, pointer_sized_int_node, SANITIZE_OBJECT_SIZE, wi::to_widest(), TREE_CODE, TREE_TYPE, ubsan_create_data(), UBSAN_PRINT_POINTER, ubsan_type_descriptor(), unlink_stmt_vdef(), and unsigned_char_type_node.
|
extern |
Expand UBSAN_PTR internal call.
References add_bb_to_loop(), build_fold_addr_expr_loc(), builtin_decl_implicit(), CDI_DOMINATORS, basic_block_def::count, create_empty_bb(), dom_info_available_p(), profile_probability::even(), fold_build1, g, gcc_assert, get_range_pos_neg(), gimple_build(), gimple_build_assign(), gimple_build_call(), gimple_build_cond(), gimple_call_arg(), gimple_call_num_args(), gimple_location(), gimple_set_location(), gsi_bb(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_remove(), gsi_replace(), GSI_SAME_STMT, gsi_start_bb(), gsi_stmt(), integer_zerop(), basic_block_def::loop_father, LOOPS_NEED_FIXUP, loops_state_set(), make_edge(), make_single_succ_edge(), make_ssa_name(), wi::neg_p(), NULL, NULL_TREE, pointer_sized_int_node, SANITIZE_POINTER_OVERFLOW, set_immediate_dominator(), sizetype, split_block(), ssize_int, ssizetype, wi::to_wide(), TREE_CODE, ubsan_create_data(), unlink_stmt_vdef(), profile_probability::very_likely(), and profile_probability::very_unlikely().
|
extern |
Expand UBSAN_VPTR internal call. The type is kept on the ckind argument which is a constant, because the middle-end treats pointer conversions as useless and therefore the type of the first argument could be changed to any other pointer type.
References build4_loc(), build_array_type_nelts(), build_decl(), build_fold_addr_expr_loc(), build_int_cst(), build_zero_cst(), builtin_decl_explicit(), create_cond_insert_point(), DECL_ARTIFICIAL, DECL_EXTERNAL, DECL_IGNORED_P, DECL_VISIBILITY, DECL_VISIBILITY_SPECIFIED, varpool_node::finalize_decl(), g, gcc_assert, get_identifier(), gimple_assign_lhs(), gimple_build_assign(), gimple_build_call(), gimple_build_cond(), gimple_call_arg(), gimple_call_num_args(), gimple_location(), gimple_set_location(), gsi_after_labels(), gsi_insert_after(), gsi_insert_before(), GSI_NEW_STMT, gsi_remove(), GSI_SAME_STMT, gsi_start_bb(), gsi_stmt(), integer_type_node, make_ssa_name(), NULL, NULL_TREE, pointer_sized_int_node, SANITIZE_VPTR, TREE_PUBLIC, TREE_STATIC, tree_to_uhwi(), TREE_TYPE, ubsan_create_data(), UBSAN_DOWNCAST_POINTER, ubsan_type_descriptor(), ubsan_vptr_type_cache_decl, wi::uhwi(), UNKNOWN_LOCATION, unlink_stmt_vdef(), unsigned_char_type_node, useless_type_conversion_p(), VISIBILITY_DEFAULT, and wide_int_to_tree().
|
extern |
Build struct __ubsan_source_location { const char *__filename; unsigned int __line; unsigned int __column; } type.
References build_decl(), build_pointer_type(), build_qualified_type(), char_type_node, DECL_ARTIFICIAL, DECL_CHAIN, DECL_CONTEXT, DECL_IGNORED_P, fields, get_identifier(), i, input_location, layout_type(), make_node(), TYPE_ARTIFICIAL, TYPE_FIELDS, TYPE_NAME, TYPE_QUAL_CONST, TYPE_STUB_DECL, ubsan_source_location_type, UNKNOWN_LOCATION, and unsigned_type_node.
Referenced by asan_add_global(), asan_protect_global(), ubsan_create_data(), and ubsan_source_location().
Instrument float point-to-integer conversion. TYPE is an integer type of destination, EXPR is floating-point expression.
References b, boolean_type_node, build_call_expr_loc(), build_fold_addr_expr_loc(), build_minus_one_cst(), build_real(), builtin_decl_explicit(), dconst1, dconstm1, decimal_real_from_string(), fold_build2, fold_build3, gcc_assert, HONOR_NANS(), input_location, integer_zero_node, integer_zerop(), NULL, NULL_TREE, real_arithmetic(), real_compare(), real_convert(), REAL_EXP, real_isinf(), REAL_MODE_FORMAT, REAL_VALUE_TYPE, SANITIZE_FLOAT_CAST, SET_REAL_EXP, TREE_TYPE, TYPE_MODE, TYPE_PRECISION, TYPE_UNSIGNED, ubsan_create_data(), ubsan_encode_value(), ubsan_type_descriptor(), ubsan_use_new_style_p(), UNKNOWN_LOCATION, and void_type_node.
Referenced by convert_to_integer_1().
|
extern |
Rewrite a gcall to __builtin_unreachable for -fsanitize=unreachable. Called by the sanopt pass.
References g, gimple_build_builtin_unreachable(), gimple_location(), gsi_replace(), and gsi_stmt().
|
extern |
Helper routine that returns ADDR_EXPR of a VAR_DECL of a type descriptor. It first looks into the hash table; if not found, create the VAR_DECL, put it into the hash table and return the ADDR_EXPR of it. TYPE describes a particular type. PSTYLE is an enum controlling how we want to print the type.
References wi::add(), build_array_type_nelts(), build_constructor_va(), build_decl(), build_fold_addr_expr, build_int_cst(), build_nonstandard_integer_type(), build_qualified_type(), build_string(), char_type_node, DECL_ARTIFICIAL, DECL_EXTERNAL, decl_for_type_insert(), decl_for_type_lookup(), DECL_IGNORED_P, DECL_INITIAL, DECL_NAME, DECL_SIZE, DECL_SIZE_UNIT, double_type_node, varpool_node::finalize_decl(), float_type_node, gcc_assert, varpool_node::get(), get_identifier(), get_ubsan_type_info_for_type(), IDENTIFIER_POINTER, long_double_type_node, MAX_FIXED_MODE_SIZE, NULL, NULL_TREE, POINTER_TYPE_P, pp_formatted_text(), pp_left_bracket, pp_printf(), pp_quote, pp_right_bracket, pp_space, pp_star, pp_string(), pp_unsigned_wide_integer, pp_wide_int(), short_unsigned_type_node, size_binop, strip_array_types(), wi::to_widest(), TREE_CODE, TREE_CONSTANT, tree_fits_uhwi_p(), TREE_PUBLIC, TREE_READONLY, TREE_STATIC, tree_to_uhwi(), TREE_TYPE, type(), TYPE_ATOMIC, TYPE_DOMAIN, TYPE_MAIN_VARIANT, TYPE_MAX_VALUE, TYPE_METHOD_BASETYPE, TYPE_MODE, TYPE_NAME, TYPE_PRECISION, TYPE_QUAL_CONST, TYPE_READONLY, TYPE_RESTRICT, TYPE_SIGN, TYPE_SIZE, TYPE_SIZE_UNIT, TYPE_UNSIGNED, TYPE_VOLATILE, ubsan_get_type_descriptor_type(), ubsan_ids, UBSAN_PRINT_ARRAY, UBSAN_PRINT_FORCE_INT, UBSAN_PRINT_NORMAL, UBSAN_PRINT_POINTER, and UNKNOWN_LOCATION.
Referenced by instrument_bool_enum_load(), ubsan_build_overflow_builtin(), ubsan_expand_bounds_ifn(), ubsan_expand_null_ifn(), ubsan_expand_objsize_ifn(), ubsan_expand_vptr_ifn(), and ubsan_instrument_float_cast().