GCC Middle and Back End API Reference
convert.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "tree.h"
#include "diagnostic-core.h"
#include "fold-const.h"
#include "stor-layout.h"
#include "convert.h"
#include "langhooks.h"
#include "builtins.h"
#include "ubsan.h"
#include "stringpool.h"
#include "attribs.h"
#include "asan.h"
#include "selftest.h"
Include dependency graph for convert.cc:

Macros

#define maybe_fold_build1_loc(FOLD_P, LOC, CODE, TYPE, EXPR)
#define maybe_fold_build2_loc(FOLD_P, LOC, CODE, TYPE, EXPR1, EXPR2)
#define CASE_MATHFN(FN)

Functions

static tree convert_to_pointer_1 (tree type, tree expr, bool fold_p)
tree preserve_any_location_wrapper (tree result, tree orig_expr)
tree convert_to_pointer (tree type, tree expr)
tree convert_to_pointer_maybe_fold (tree type, tree expr, bool dofold)
static tree convert_to_real_1 (tree type, tree expr, bool fold_p)
tree convert_to_real (tree type, tree expr)
tree convert_to_real_maybe_fold (tree type, tree expr, bool dofold)
static tree do_narrow (location_t loc, enum tree_code ex_form, tree type, tree arg0, tree arg1, tree expr, unsigned inprec, unsigned outprec, bool dofold)
static tree convert_to_integer_1 (tree type, tree expr, bool dofold)
tree convert_to_integer (tree type, tree expr)
tree convert_to_integer_maybe_fold (tree type, tree expr, bool dofold)
static tree convert_to_complex_1 (tree type, tree expr, bool fold_p)
tree convert_to_complex (tree type, tree expr)
tree convert_to_complex_maybe_fold (tree type, tree expr, bool dofold)
tree convert_to_vector (tree type, tree expr)
tree convert_to_fixed (tree type, tree expr)

Macro Definition Documentation

◆ CASE_MATHFN

#define CASE_MATHFN ( FN)
Value:
case BUILT_IN_##FN: case BUILT_IN_##FN##L:

Referenced by convert_to_real_1().

◆ maybe_fold_build1_loc

#define maybe_fold_build1_loc ( FOLD_P,
LOC,
CODE,
TYPE,
EXPR )
Value:
((FOLD_P) ? fold_build1_loc (LOC, CODE, TYPE, EXPR) \
: build1_loc (LOC, CODE, TYPE, EXPR))
tree fold_build1_loc(location_t loc, enum tree_code code, tree type, tree op0 MEM_STAT_DECL)
Definition fold-const.cc:13892
tree build1_loc(location_t loc, enum tree_code code, tree type, tree arg1 CXX_MEM_STAT_INFO)
Definition tree.h:4836
Utility routines for data type conversion for GCC. Copyright (C) 1987-2025 Free Software Foundation, Inc. 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/>.
These routines are somewhat language-independent utility function intended to be called by the language-specific convert () functions.

Referenced by convert_to_complex_1(), convert_to_integer_1(), convert_to_pointer_1(), and convert_to_real_1().

◆ maybe_fold_build2_loc

#define maybe_fold_build2_loc ( FOLD_P,
LOC,
CODE,
TYPE,
EXPR1,
EXPR2 )
Value:
((FOLD_P) ? fold_build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2) \
: build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2))
tree fold_build2_loc(location_t loc, enum tree_code code, tree type, tree op0, tree op1 MEM_STAT_DECL)
Definition fold-const.cc:13929
tree build2_loc(location_t loc, enum tree_code code, tree type, tree arg0, tree arg1 CXX_MEM_STAT_INFO)
Definition tree.h:4846

Referenced by convert_to_complex_1(), convert_to_integer_1(), and do_narrow().

Function Documentation

◆ convert_to_complex()

tree convert_to_complex ( tree type,
tree expr )
A wrapper around convert_to_complex_1 that always folds the expression.

References convert_to_complex_1().

◆ convert_to_complex_1()

tree convert_to_complex_1 ( tree type,
tree expr,
bool fold_p )
static

◆ convert_to_complex_maybe_fold()

tree convert_to_complex_maybe_fold ( tree type,
tree expr,
bool dofold )
A wrapper around convert_to_complex_1 that only folds the expression if DOFOLD, or if it is CONSTANT_CLASS_OR_WRAPPER_P.

References CONSTANT_CLASS_OR_WRAPPER_P, convert_to_complex_1(), and preserve_any_location_wrapper().

Referenced by convert_to_complex_nofold().

◆ convert_to_fixed()

tree convert_to_fixed ( tree type,
tree expr )
Convert EXPR to some fixed-point type TYPE. EXPR must be fixed-point, float, integer, or enumeral; in other cases error is called.

References ALL_SCALAR_ACCUM_MODE_P, build1(), build_fixed(), convert(), error(), error_mark_node, FCONST0, FCONST1, fold_build1, integer_onep(), integer_zerop(), TREE_CODE, TREE_TYPE, and TYPE_MODE.

◆ convert_to_integer()

tree convert_to_integer ( tree type,
tree expr )
Convert EXPR to some integer (or enum) type TYPE. EXPR must be pointer, integer, discrete (enum, char, or bool), float, fixed-point or vector; in other cases error is called. The result of this is always supposed to be a newly created tree node not in use in any existing structure.

References convert_to_integer_1().

◆ convert_to_integer_1()

tree convert_to_integer_1 ( tree type,
tree expr,
bool dofold )
static
Convert EXPR to some integer (or enum) type TYPE. EXPR must be pointer, integer, discrete (enum, char, or bool), float, fixed-point or vector; in other cases error is called. If DOFOLD is TRUE, we try to simplify newly-created patterns by folding. The result of this is always supposed to be a newly created tree node not in use in any existing structure.

References build1(), build2(), build2_loc(), build_call_expr(), build_int_cst(), builtin_mathfn_code(), CALL_EXPR_ARG, call_expr_nargs, CASE_CONVERT, CASE_FLT_FN, CASE_FLT_FN_FLOATN_NX, COMPLETE_TYPE_P, convert(), CONVERT_EXPR_P, convert_to_integer_1(), copy_node(), current_function_decl, do_narrow(), element_precision(), error(), error_mark_node, EXPR_LOCATION, fold_build1, fold_build3, fold_convert, function_c99_misc, gcc_fallthrough, GET_MODE_PRECISION(), GET_MODE_SIZE(), get_unwidened(), integer_all_onesp(), integer_type_node, integer_zerop(), long_integer_type_node, long_long_integer_type_node, mathfn_built_in(), maybe_fold_build1_loc, maybe_fold_build2_loc, NULL_TREE, POINTER_TYPE_P, sanitize_flags_p(), SANITIZE_FLOAT_CAST, SANITIZE_SI_OVERFLOW, save_expr(), SCALAR_FLOAT_TYPE_P, strip_float_extensions(), targetm, tcc_comparison, wi::to_widest(), TREE_CODE, TREE_CODE_CLASS, tree_int_cst_equal(), tree_int_cst_sgn(), TREE_OPERAND, TREE_OVERFLOW, TREE_SIDE_EFFECTS, tree_strip_any_location_wrapper(), TREE_TYPE, lang_hooks_for_types::type_for_mode, lang_hooks_for_types::type_for_size, type_has_mode_precision_p(), TYPE_MODE, TYPE_PRECISION, TYPE_SIZE, TYPE_UNSIGNED, lang_hooks::types, ubsan_instrument_float_cast(), unsigned_type_for(), and VOID_TYPE_P.

Referenced by convert_to_integer(), convert_to_integer_1(), and convert_to_integer_maybe_fold().

◆ convert_to_integer_maybe_fold()

tree convert_to_integer_maybe_fold ( tree type,
tree expr,
bool dofold )
A wrapper around convert_to_complex_1 that only folds the expression if DOFOLD, or if it is CONSTANT_CLASS_OR_WRAPPER_P.

References CONSTANT_CLASS_OR_WRAPPER_P, convert_to_integer_1(), and preserve_any_location_wrapper().

Referenced by convert_to_integer_nofold().

◆ convert_to_pointer()

tree convert_to_pointer ( tree type,
tree expr )
A wrapper around convert_to_pointer_1 that always folds the expression.

References convert_to_pointer_1().

Referenced by oacc_rewrite_var_decl().

◆ convert_to_pointer_1()

tree convert_to_pointer_1 ( tree type,
tree expr,
bool fold_p )
static
Convert EXPR to some pointer or reference type TYPE. EXPR must be pointer, reference, integer, enumeral, or literal zero; in other cases error is called. If FOLD_P is true, try to fold the expression.

References error(), error_mark_node, EXPR_LOCATION, maybe_fold_build1_loc, TREE_CODE, TREE_TYPE, TYPE_ADDR_SPACE, lang_hooks_for_types::type_for_size, TYPE_PRECISION, and lang_hooks::types.

Referenced by convert_to_pointer(), and convert_to_pointer_maybe_fold().

◆ convert_to_pointer_maybe_fold()

tree convert_to_pointer_maybe_fold ( tree type,
tree expr,
bool dofold )
A wrapper around convert_to_pointer_1 that only folds the expression if DOFOLD, or if it is CONSTANT_CLASS_OR_WRAPPER_P.

References CONSTANT_CLASS_OR_WRAPPER_P, convert_to_pointer_1(), and preserve_any_location_wrapper().

Referenced by convert_to_pointer_nofold().

◆ convert_to_real()

tree convert_to_real ( tree type,
tree expr )
A wrapper around convert_to_real_1 that always folds the expression.

References convert_to_real_1().

◆ convert_to_real_1()

◆ convert_to_real_maybe_fold()

tree convert_to_real_maybe_fold ( tree type,
tree expr,
bool dofold )
A wrapper around convert_to_real_1 that only folds the expression if DOFOLD, or if it is CONSTANT_CLASS_OR_WRAPPER_P.

References CONSTANT_CLASS_OR_WRAPPER_P, convert_to_real_1(), and preserve_any_location_wrapper().

Referenced by convert_to_real_nofold().

◆ convert_to_vector()

tree convert_to_vector ( tree type,
tree expr )
Convert EXPR to the vector type TYPE in the usual ways.

References build1(), error(), error_mark_node, TREE_CODE, tree_int_cst_equal(), TREE_TYPE, and TYPE_SIZE.

◆ do_narrow()

tree do_narrow ( location_t loc,
enum tree_code ex_form,
tree type,
tree arg0,
tree arg1,
tree expr,
unsigned inprec,
unsigned outprec,
bool dofold )
static

◆ preserve_any_location_wrapper()

tree preserve_any_location_wrapper ( tree result,
tree orig_expr )
Subroutine of the various convert_to_*_maybe_fold routines. If a location wrapper has been folded to a constant (presumably of a different type), re-wrap the new constant with a location wrapper.

References CONSTANT_CLASS_P, EXPR_LOCATION, location_wrapper_p(), maybe_wrap_with_location(), and TREE_OPERAND.

Referenced by convert_to_complex_maybe_fold(), convert_to_integer_maybe_fold(), convert_to_pointer_maybe_fold(), and convert_to_real_maybe_fold().