GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "backend.h"
#include "tree.h"
#include "gimple.h"
#include "tree-pass.h"
#include "ssa.h"
#include "gimple-pretty-print.h"
#include "diagnostic-core.h"
#include "fold-const.h"
#include "gimple-iterator.h"
#include "tree-ssa.h"
#include "tree-cfg.h"
#include "cfghooks.h"
#include "attribs.h"
#include "builtins.h"
#include "calls.h"
#include "gimple-range.h"
#include "gimple-predicate-analysis.h"
#include "domwalk.h"
#include "tree-ssa-sccvn.h"
#include "cfganal.h"
#include "gcc-urlifier.h"
Data Structures | |
struct | check_defs_data |
struct | wlimits |
struct | uninit_undef_val_t |
Macros | |
#define | INCLUDE_STRING |
#define | MASK_FIRST_SET_BIT(mask) |
Variables | |
static hash_set< tree > * | possibly_undefined_names |
static hash_map< gphi *, uninit_analysis::func_t::phi_arg_set_t > * | defined_args |
#define INCLUDE_STRING |
Predicate aware uninitialized variable warning. Copyright (C) 2001-2025 Free Software Foundation, Inc. Contributed by Xinliang David Li <davidxl@google.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/>.
#define MASK_FIRST_SET_BIT | ( | mask | ) |
Referenced by warn_uninitialized_phi().
Return true if STMT is a call to built-in function all of whose by-reference arguments are const-qualified (i.e., the function can be assumed not to modify them).
References BUILT_IN_NORMAL, FOREACH_FUNCTION_ARGS, gimple_call_arg(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_call_num_args(), POINTER_TYPE_P, TREE_TYPE, TYPE_READONLY, and VOID_TYPE_P.
Referenced by check_defs().
Checks if the operand OPND of PHI is defined by another phi with one operand defined by this PHI, but the rest operands are all defined. If yes, returns true to skip this operand as being redundant. Can be enhanced to be more general.
References gimple_phi_arg_def(), gimple_phi_num_args(), gimple_phi_result(), i, SSA_NAME_DEF_STMT, TREE_CODE, and uninit_undefined_value_p().
Referenced by compute_uninit_opnds_pos().
|
static |
Callback for walk_aliased_vdefs.
References BUILT_IN_NORMAL, builtin_call_nomodifying_p(), DECL_BUILT_IN_CLASS, DECL_FUNCTION_CODE(), gimple_assign_rhs1(), gimple_assign_rhs_code(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_call_internal_fn(), gimple_call_internal_p(), gimple_clobber_p(), is_gimple_assign(), is_gimple_call(), SSA_NAME_DEF_STMT, and stmt_kills_ref_p().
|
static |
Return a bitset holding the positions of arguments in PHI with empty (or possibly empty) definitions.
References can_skip_redundant_opnd(), cfun, defined_args, gimple_phi_arg_def(), gimple_phi_num_args(), i, MASK_SET_BIT, uninit_analysis::func_t::max_phi_args, SSA_NAME_OCCURS_IN_ABNORMAL_PHI, TREE_CODE, and uninit_undefined_value_p().
Referenced by uninit_undef_val_t::phi_arg_set(), and warn_uninitialized_phi().
|
static |
Searches through all uses of a potentially uninitialized variable defined by PHI and returns a use statement if the use is not properly guarded. It returns NULL if all uses are guarded. UNINIT_OPNDS is a bitvector holding the position(s) of uninit PHI operands.
References hash_set< KeyId, Lazy, Traits >::add(), cand_cmp(), defined_args, dump_file, dump_flags, dyn_cast(), FOR_EACH_IMM_USE_FAST, gimple_assign_lhs(), gimple_assign_ssa_name_copy_p(), gimple_bb(), gimple_phi_arg_edge(), gimple_phi_result(), basic_block_def::index, is_gimple_debug(), uninit_analysis::is_use_guarded(), MASK_SET_BIT, uninit_analysis::func_t::max_phi_args, NULL, PHI_ARG_INDEX_FROM_USE, possibly_undefined_names, print_gimple_stmt(), single_imm_use(), TDF_DETAILS, USE_FROM_PTR, and USE_STMT.
Referenced by warn_uninitialized_phi().
|
static |
|
static |
Returns the first bit position (starting from LSB) in mask that is non zero. Returns -1 if the mask is empty.
Return true if EXPR should suppress either uninitialized warning.
References warning_suppressed_p().
Referenced by maybe_warn_operand(), maybe_warn_read_write_only(), uninit_undefined_value_p(), and warn_uninit().
Return true if T, an SSA_NAME, has an undefined value.
References hash_set< KeyId, Lazy, Traits >::contains(), possibly_undefined_names, and ssa_undefined_value_p().
Referenced by uninit_undefined_value_p(), and warn_uninit().
gimple_opt_pass * make_pass_early_warn_uninitialized | ( | gcc::context * | ctxt | ) |
gimple_opt_pass * make_pass_late_warn_uninitialized | ( | gcc::context * | ctxt | ) |
|
static |
Determine if REF references an uninitialized operand and diagnose it if so. STMS is the referencing statement. LHS is the result of the access and may be null. RHS is the variable referenced by the access; it may not be null.
References wlimits::always_executed, ao_ref_base(), cfun, check_defs(), DECL_FUNCTION_CODE(), DECL_HARD_REGISTER, DECL_P, DECL_SIZE, dyn_cast(), EXPR_P, FOR_EACH_IMM_USE_FAST, get_base_address(), get_no_uninit_warning(), gimple_assign_rhs1(), gimple_assign_rhs1_ptr(), gimple_assign_rhs_code(), gimple_call_builtin_p(), gimple_call_fndecl(), gimple_location(), gimple_vuse(), is_empty_type(), is_gimple_assign(), is_gimple_call(), is_global_var(), known_eq, known_ge, known_le, wlimits::limit, ao_ref::max_size, maybe_warn_read_write_only(), NULL, NULL_TREE, ao_ref::offset, wlimits::oracle_cnt, POINTER_TYPE_P, poly_int_tree_p(), set_no_uninit_warning(), ao_ref::size, SSA_NAME_DEF_STMT, SSA_NAME_VAR, TREE_CODE, TREE_OPERAND, TREE_TYPE, ssa_use_operand_t::use, USE_STMT, VAR_P, wlimits::vdef_cnt, walk_aliased_vdefs(), warning_at(), and wlimits::wmaybe_uninit.
Referenced by maybe_warn_pass_by_reference(), and warn_uninitialized_vars().
Diagnose passing addresses of uninitialized objects to either const pointer arguments to functions, or to functions declared with attribute access implying read access to those objects.
References access_deferred, access_none, access_read_only, access_write_only, wlimits::always_executed, ao_ref_init_from_ptr_and_size(), BUILT_IN_LAST, BUILT_IN_NORMAL, DECL_FUNCTION_CODE(), DECL_P, DECL_SOURCE_LOCATION, EAF_NO_DIRECT_READ, EAF_UNUSED, ECF_CONST, FOREACH_FUNCTION_ARGS, hash_map< KeyId, Value, Traits >::get(), gimple_call_arg(), gimple_call_arg_flags(), gimple_call_builtin_p(), gimple_call_flags(), gimple_call_fndecl(), gimple_call_fntype(), gimple_call_num_args(), gimple_location(), inform(), init_attr_rdwr_indices(), maybe_warn_operand(), NULL_TREE, POINTER_TYPE_P, TREE_STRING_POINTER, TREE_TYPE, TYPE_ATTRIBUTES, TYPE_READONLY, and wlimits::wmaybe_uninit.
Referenced by warn_uninitialized_vars().
If ARG is a FNDECL parameter declared with attribute access none or write_only issue a warning for its read access via PTR.
References access_none, access_write_only, DECL_ARGUMENTS, DECL_SOURCE_LOCATION, hash_map< KeyId, Value, Traits >::get(), get_no_uninit_warning(), gimple_location(), inform(), init_attr_rdwr_indices(), suppress_warning(), TREE_CHAIN, TREE_STRING_POINTER, TREE_TYPE, TYPE_ATTRIBUTES, and warning_at().
Referenced by maybe_warn_operand().
|
inlinestatic |
Suppress both uninitialized warnings for EXPR.
References suppress_warning().
Referenced by maybe_warn_operand().
Like has_undefined_value_p, but don't return true if the no-warning bit is set on SSA_NAME_VAR for either uninit warning.
References get_no_uninit_warning(), has_undefined_value_p(), and SSA_NAME_VAR.
Referenced by can_skip_redundant_opnd(), and compute_uninit_opnds_pos().
|
static |
Emit warnings for uninitialized variables. This is done in two passes. The first pass notices real uses of SSA names with undefined values. Such uses are unconditionally uninitialized, and we can be certain that such a use is a mistake. This pass is run before most optimizations, so that we catch as many as we can. The second pass follows PHI nodes to find uses that are potentially uninitialized. In this case we can't necessarily prove that the use is really uninitialized. This pass is run after most optimizations, so that we thread as many jumps and possible, and delete as much dead code as possible, in order to reduce false positives. We also look again for plain uninitialized variables, since optimization may have changed conditionally uninitialized to unconditionally uninitialized.
Emit warning OPT for variable VAR at the point in the program where the SSA_NAME T is being used uninitialized. The warning text is in MSGID and STMT is the statement that does the uninitialized read. PHI_ARG_LOC is the location of the PHI argument if T and VAR are one, or UNKNOWN_LOCATION otherwise.
References DECL_NAME, DECL_SOURCE_LOCATION, DECL_UID, dyn_cast(), gcc_assert, get_no_uninit_warning(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_single_p(), gimple_call_arg(), gimple_call_internal_p(), gimple_has_location(), gimple_location(), has_undefined_value_p(), HOST_BITS_PER_INT, IDENTIFIER_POINTER, inform(), is_gimple_assign(), NULL, NULL_TREE, SSA_NAME_DEF_STMT, SSA_NAME_VAR, suppress_warning(), TREE_CODE, TREE_OPERAND, TREE_STRING_POINTER, UNKNOWN_LOCATION, VAR_P, warning_at(), warning_suppressed_p(), and zerop().
Referenced by warn_uninit_phi_uses(), warn_uninitialized_phi(), and warn_uninitialized_vars().
|
static |
Warn about an uninitialized PHI argument on the fallthru path to an always executed block BB.
References CDI_DOMINATORS, CDI_POST_DOMINATORS, cfun, dominated_by_p(), ENTRY_BLOCK_PTR_FOR_FN, FOR_EACH_EDGE, FOR_EACH_IMM_USE_FAST, gimple_bb(), gimple_location(), gimple_phi_result(), gsi_end_p(), gsi_next(), gsi_start_phis(), NULL, PHI_ARG_DEF_FROM_EDGE, basic_block_def::preds, si, single_succ(), SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VAR, TREE_CODE, UNKNOWN_LOCATION, USE_STMT, virtual_operand_p(), and warn_uninit().
Referenced by warn_uninitialized_vars().
|
static |
Look for inputs to PHI that are SSA_NAMEs that have empty definitions and gives warning if there exists a runtime path from the entry to a use of the PHI def that does not contain a definition. In other words, the warning is on the real use. The more dead paths that can be pruned by the compiler, the fewer false positives the warning is.
References compute_uninit_opnds_pos(), dump_file, dump_flags, dyn_cast(), find_uninit_use(), gimple_phi_arg_def(), gimple_phi_arg_has_location(), gimple_phi_arg_location(), gimple_phi_num_args(), MASK_FIRST_SET_BIT, print_gimple_stmt(), SSA_NAME_DEF_STMT, SSA_NAME_VAR, TDF_DETAILS, TREE_CODE, UNKNOWN_LOCATION, and warn_uninit().
|
static |
Issue warnings about reads of uninitialized variables. WMAYBE_UNINIT is true to issue -Wmaybe-uninitialized, otherwise -Wuninitialized.
References wlimits::always_executed, ao_ref_init(), CDI_POST_DOMINATORS, cfun, DECL_P, DECL_SOURCE_LOCATION, dyn_cast(), ENTRY_BLOCK_PTR_FOR_FN, EXIT_BLOCK, find_fallthru_edge(), basic_block_def::flags, FOR_EACH_BB_FN, FOR_EACH_EDGE, FOR_EACH_SSA_USE_OPERAND, get_immediate_dominator(), gimple_assign_lhs(), gimple_assign_load_p(), gimple_assign_rhs1(), gimple_assign_rhs1_ptr(), gimple_assign_rhs_code(), gimple_call_internal_p(), gimple_has_location(), gimple_vdef(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), basic_block_def::index, inform(), is_gimple_debug(), maybe_warn_operand(), maybe_warn_pass_by_reference(), NULL, basic_block_def::preds, single_succ(), SSA_NAME_VAR, SSA_OP_USE, basic_block_def::succs, ssa_use_operand_t::use, USE_FROM_PTR, wlimits::vdef_cnt, warn_uninit(), warn_uninit_phi_uses(), and wlimits::wmaybe_uninit.
Referenced by execute_early_warn_uninitialized().
|
static |
Referenced by compute_uninit_opnds_pos(), and find_uninit_use().
This implements the pass that does predicate aware warning on uses of possibly uninitialized variables. The pass first collects the set of possibly uninitialized SSA names. For each such name, it walks through all its immediate uses. For each immediate use, it rebuilds the condition expression (the predicate) that guards the use. The predicate is then examined to see if the variable is always defined under that same condition. This is done either by pruning the unrealizable paths that lead to the default definitions or by checking if the predicate set that guards the defining paths is a superset of the use predicate.
Pointer set of potentially undefined ssa names, i.e., ssa names that are defined by phi with operands that are not defined or potentially undefined.
Referenced by find_uninit_use(), and has_undefined_value_p().