GCC Middle and Back End API Reference
langhooks.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "rtl.h"
#include "tree.h"
#include "timevar.h"
#include "stringpool.h"
#include "diagnostic.h"
#include "intl.h"
#include "toplev.h"
#include "attribs.h"
#include "gimplify.h"
#include "langhooks.h"
#include "tree-diagnostic.h"
#include "output.h"
#include "stor-layout.h"
#include "cgraph.h"
#include "debug.h"
Include dependency graph for langhooks.cc:


void lhd_do_nothing (void)
void lhd_do_nothing_t (tree ARG_UNUSED(t))
tree lhd_pass_through_t (tree t)
tree lhd_do_nothing_iii_return_null_tree (int ARG_UNUSED(i), int ARG_UNUSED(j), int ARG_UNUSED(k))
void lhd_do_nothing_f (struct function *ARG_UNUSED(f))
tree lhd_return_null_tree (tree ARG_UNUSED(t))
tree lhd_return_null_const_tree (const_tree ARG_UNUSED(t))
bool lhd_post_options (const char **ARG_UNUSED(pfilename))
void lhd_print_tree_nothing (FILE *ARG_UNUSED(file), tree ARG_UNUSED(node), int ARG_UNUSED(indent))
bool lhd_warn_unused_global_decl (const_tree decl)
void lhd_set_decl_assembler_name (tree decl)
void lhd_overwrite_decl_assembler_name (tree decl, tree name)
tree lhd_type_promotes_to (tree ARG_UNUSED(type))
void lhd_register_builtin_type (tree ARG_UNUSED(type), const char *ARG_UNUSED(name))
void lhd_incomplete_type_error (location_t ARG_UNUSED(loc), const_tree ARG_UNUSED(value), const_tree type)
alias_set_type lhd_get_alias_set (tree ARG_UNUSED(t))
const charlhd_decl_printable_name (tree decl, int ARG_UNUSED(verbosity))
const charlhd_dwarf_name (tree t, int verbosity)
int lhd_types_compatible_p (tree x, tree y)
bool lhd_tree_dump_dump_tree (void *di, tree t)
int lhd_tree_dump_type_quals (const_tree t)
int lhd_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
size_t lhd_tree_size (enum tree_code c)
bool lhd_decl_ok_for_sibcall (const_tree decl)
void global_decl_processing (void)
void lhd_initialize_diagnostics (diagnostic_context *ctx)
void lhd_register_dumps (gcc::dump_manager *)
void lhd_init_options (unsigned int decoded_options_count, struct cl_decoded_option *decoded_options)
bool lhd_complain_wrong_lang_p (const struct cl_option *option)
bool lhd_handle_option (size_t code, const char *arg, HOST_WIDE_INT value, int kind, location_t loc, const struct cl_option_handlers *handlers)
void lhd_print_error_function (diagnostic_context *context, const char *file, const diagnostic_info *diagnostic)
tree lhd_make_node (enum tree_code code)
tree lhd_simulate_enum_decl (location_t loc, const char *name, vec< string_int_pair > *values_ptr)
tree lhd_simulate_record_decl (location_t loc, const char *name, array_slice< const tree > fields)
tree lhd_type_for_size (unsigned precision, int unsignedp)
HOST_WIDE_INT lhd_to_target_charset (HOST_WIDE_INT c)
tree lhd_expr_to_decl (tree expr, bool *tc, bool *se)
enum omp_clause_default_kind lhd_omp_predetermined_sharing (tree decl)
enum omp_clause_defaultmap_kind lhd_omp_predetermined_mapping (tree decl)
tree lhd_omp_assignment (tree clause, tree dst, tree src)
void lhd_omp_finish_clause (tree, gimple_seq *, bool)
tree lhd_omp_array_size (tree, gimple_seq *)
bool lhd_omp_scalar_p (tree decl, bool ptr_ok)
treelhd_omp_get_decl_init (tree decl)
void lhd_omp_finish_decl_inits (void)
void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *c, tree t)
static tree build_builtin_function (location_t location, const char *name, tree type, int function_code, enum built_in_class cl, const char *library_name, tree attrs)
tree add_builtin_function (const char *name, tree type, int function_code, enum built_in_class cl, const char *library_name, tree attrs)
tree add_builtin_function_ext_scope (const char *name, tree type, int function_code, enum built_in_class cl, const char *library_name, tree attrs)
tree simulate_builtin_function_decl (location_t location, const char *name, tree type, int function_code, const char *library_name, tree attrs)
tree lhd_builtin_function (tree decl)
tree add_builtin_type (const char *name, tree type)
void lhd_begin_section (const char *name)
void lhd_append_data (const void *data, size_t len, void *)
void lhd_end_section (void)
tree lhd_enum_underlying_base_type (const_tree enum_type)
const charlhd_get_substring_location (const substring_loc &, location_t *)
int lhd_decl_dwarf_attribute (const_tree, int)
int lhd_type_dwarf_attribute (const_tree, int)
tree lhd_unit_size_without_reusable_padding (tree t)
void lhd_finalize_early_debug (void)
const charlhd_get_sarif_source_language (const char *)
bool lang_GNU_C (void)
bool lang_GNU_CXX (void)
bool lang_GNU_Fortran (void)
bool lang_GNU_OBJC (void)


static sectionsaved_section

Function Documentation

◆ add_builtin_function()

tree add_builtin_function ( const char * name,
tree type,
int function_code,
enum built_in_class cl,
const char * library_name,
tree attrs )

◆ add_builtin_function_ext_scope()

tree add_builtin_function_ext_scope ( const char * name,
tree type,
int function_code,
enum built_in_class cl,
const char * library_name,
tree attrs )
Like add_builtin_function, but make sure the scope is the external scope.
This is used to delay putting in back end builtin functions until the ISA
that defines the builtin is declared via function specific target options,
which can save memory for machines like the x86_64 that have multiple ISAs.
If this points to the same function as builtin_function, the backend must
add all of the builtins at program initialization time.   

References build_builtin_function(), lang_hooks::builtin_function_ext_scope, BUILTINS_LOCATION, and ggc_alloc().

Referenced by rt_bb_visited::rt_bb_visited().

◆ add_builtin_type()

tree add_builtin_type ( const char * name,
tree type )

◆ build_builtin_function()

static tree build_builtin_function ( location_t location,
const char * name,
tree type,
int function_code,
enum built_in_class cl,
const char * library_name,
tree attrs )
Common function for add_builtin_function, add_builtin_function_ext_scope
and simulate_builtin_function_decl.   

References ATTR_FLAG_BUILT_IN, build_decl(), decl_attributes(), DECL_EXTERNAL, get_identifier(), ggc_alloc(), NULL_TREE, SET_DECL_ASSEMBLER_NAME, set_decl_built_in_function(), targetm, and TREE_PUBLIC.

Referenced by add_builtin_function(), add_builtin_function_ext_scope(), and simulate_builtin_function_decl().

◆ global_decl_processing()

void global_decl_processing ( void )
Generic global declaration processing.  This is meant to be called
by the front-ends at the end of parsing.  C/C++ do their own thing,
but other front-ends may call this.   

References DECL_CHAIN, lang_hooks::decls, free(), lang_hooks_for_decls::getdecls, ggc_alloc(), i, list_length(), timevar_start(), timevar_stop(), and wrapup_global_declarations().

◆ lang_GNU_C()

bool lang_GNU_C ( void )
Returns true if the current lang_hooks represents the GNU C frontend.   

References ggc_alloc(), lang_hooks::name, and startswith().

Referenced by default_floatn_builtin_p(), maybe_warn_implicit_fallthrough(), and process_options().

◆ lang_GNU_CXX()

bool lang_GNU_CXX ( void )
Returns true if the current lang_hooks represents the GNU C++ frontend.   

References lang_hooks::name, and startswith().

Referenced by fold_cond_expr_with_comparison(), and maybe_warn_implicit_fallthrough().

◆ lang_GNU_Fortran()

◆ lang_GNU_OBJC()

bool lang_GNU_OBJC ( void )
Returns true if the current lang_hooks represents the GNU Objective-C

References lang_hooks::name, and startswith().

Referenced by default_floatn_builtin_p(), and maybe_warn_implicit_fallthrough().

◆ lhd_append_data()

void lhd_append_data ( const void * data,
size_t len,
void *  )
Write DATA of length LEN to the current LTO output section.  This default
implementation just calls assemble_string.   

References assemble_string(), ggc_alloc(), timevar_pop(), and timevar_push().

◆ lhd_begin_section()

void lhd_begin_section ( const char * name)
Begin a new LTO output section named NAME.  This default implementation
saves the old section and emits assembly code to switch to the new

References gcc_assert, get_section(), in_section, NULL, saved_section, SECTION_DEBUG, SECTION_EXCLUDE, switch_to_section(), and text_section.

◆ lhd_builtin_function()

tree lhd_builtin_function ( tree decl)

◆ lhd_complain_wrong_lang_p()

bool lhd_complain_wrong_lang_p ( const struct cl_option * option)
By default, always complain about options for the wrong language.   

◆ lhd_decl_dwarf_attribute()

int lhd_decl_dwarf_attribute ( const_tree ,
int  )
Default implementation of LANG_HOOKS_DECL_DWARF_ATTRIBUTE.  Don't add
any attributes.   

◆ lhd_decl_ok_for_sibcall()

bool lhd_decl_ok_for_sibcall ( const_tree decl)
Return true if decl, which is a function decl, may be called by a

◆ lhd_decl_printable_name()

const char * lhd_decl_printable_name ( tree decl,
int ARG_UNUSEDverbosity )
This is the default decl_printable_name function.   

References DECL_NAME, gcc_assert, and IDENTIFIER_POINTER.

◆ lhd_do_nothing()

void lhd_do_nothing ( void )
Default language-specific hooks.
   Copyright (C) 2001-2024 Free Software Foundation, Inc.
   Contributed by Alexandre Oliva  <aoliva@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
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
Do nothing; in many cases the default hook.   

◆ lhd_do_nothing_f()

void lhd_do_nothing_f ( struct function * ARG_UNUSEDf)
Do nothing (function).   

◆ lhd_do_nothing_iii_return_null_tree()

tree lhd_do_nothing_iii_return_null_tree ( int ARG_UNUSEDi,
Do nothing (int, int, int).  Return NULL_TREE.   

References NULL_TREE.

◆ lhd_do_nothing_t()

void lhd_do_nothing_t ( tree ARG_UNUSEDt)
Do nothing (tree).   

◆ lhd_dwarf_name()

const char * lhd_dwarf_name ( tree t,
int verbosity )
This is the default dwarf_name function.   

References DECL_P, lang_hooks::decl_printable_name, gcc_assert, and ggc_alloc().

◆ lhd_end_section()

void lhd_end_section ( void )
Finish the current LTO output section.  This default implementation emits
assembly code to switch to any section previously saved by

References NULL, saved_section, and switch_to_section().

◆ lhd_enum_underlying_base_type()

tree lhd_enum_underlying_base_type ( const_tree enum_type)
Default implementation of enum_underlying_base_type using type_for_size.   

References lang_hooks_for_types::type_for_size, TYPE_PRECISION, TYPE_UNSIGNED, and lang_hooks::types.

◆ lhd_expr_to_decl()

tree lhd_expr_to_decl ( tree expr,
bool * tc,
bool * se )

References expr.

◆ lhd_finalize_early_debug()

void lhd_finalize_early_debug ( void )
Default implementation for the finalize_early_debug hook.   

References debug_hooks, gcc_debug_hooks::early_global_decl, FOR_EACH_FUNCTION_WITH_GIMPLE_BODY, and ggc_alloc().

◆ lhd_get_alias_set()

alias_set_type lhd_get_alias_set ( tree ARG_UNUSEDt)
Provide a default routine for alias sets that always returns -1.  This
is used by languages that don't need to do anything special.   

◆ lhd_get_sarif_source_language()

const char * lhd_get_sarif_source_language ( const char * )
Default implementation of LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE.   

References NULL.

◆ lhd_get_substring_location()

const char * lhd_get_substring_location ( const substring_loc & ,
location_t * out_loc )
Default implementation of LANG_HOOKS_GET_SUBSTRING_LOCATION.   

◆ lhd_gimplify_expr()

int lhd_gimplify_expr ( tree * expr_p,
gimple_seq * pre_p,
gimple_seq * post_p )
lang_hooks.gimplify_expr re-writes *EXPR_P into GIMPLE form.   

References GS_UNHANDLED.

◆ lhd_handle_option()

bool lhd_handle_option ( size_t code,
const char * arg,
int kind,
location_t loc,
const struct cl_option_handlers * handlers )
By default, no language-specific options are valid.   

◆ lhd_incomplete_type_error()

void lhd_incomplete_type_error ( location_t ARG_UNUSEDloc,
const_tree ARG_UNUSEDvalue,
const_tree type )
Invalid use of an incomplete type.   

References gcc_assert, ggc_alloc(), and TREE_CODE.

◆ lhd_init_options()

void lhd_init_options ( unsigned int decoded_options_count,
struct cl_decoded_option * decoded_options )
Called to perform language-specific options initialization.   

◆ lhd_initialize_diagnostics()

void lhd_initialize_diagnostics ( diagnostic_context * ctx)
Called to perform language-specific initialization of CTX.   

◆ lhd_make_node()

tree lhd_make_node ( enum tree_code code)

References make_node().

◆ lhd_omp_array_size()

tree lhd_omp_array_size ( tree ,
gimple_seq *  )
Return array size; cf. omp_array_data.   

References NULL_TREE.

◆ lhd_omp_assignment()

tree lhd_omp_assignment ( tree clause,
tree dst,
tree src )
Generate code to copy SRC to DST.   

References build2(), ggc_alloc(), and TREE_TYPE.

◆ lhd_omp_finish_clause()

void lhd_omp_finish_clause ( tree ,
gimple_seq * ,
bool  )
Finalize clause C.   

◆ lhd_omp_finish_decl_inits()

void lhd_omp_finish_decl_inits ( void )
Free any extra memory used to hold initializer information for
variable declarations.   

◆ lhd_omp_firstprivatize_type_sizes()

void lhd_omp_firstprivatize_type_sizes ( struct gimplify_omp_ctx * c,
tree t )
Register language specific type size variables as potentially OpenMP
firstprivate variables.   

◆ lhd_omp_get_decl_init()

tree * lhd_omp_get_decl_init ( tree decl)
Return static initializer for DECL.   

References DECL_INITIAL.

◆ lhd_omp_predetermined_mapping()

enum omp_clause_defaultmap_kind lhd_omp_predetermined_mapping ( tree decl)
Return sharing kind if OpenMP mapping attribute of DECL is


◆ lhd_omp_predetermined_sharing()

enum omp_clause_default_kind lhd_omp_predetermined_sharing ( tree decl)
Return sharing kind if OpenMP sharing attribute of DECL is
predetermined, OMP_CLAUSE_DEFAULT_UNSPECIFIED otherwise.   


◆ lhd_omp_scalar_p()

bool lhd_omp_scalar_p ( tree decl,
bool ptr_ok )
Return true if DECL is a scalar variable (for the purpose of
implicit firstprivatization & mapping). Only if alloc_ptr_ok
are allocatables and pointers accepted.  


◆ lhd_overwrite_decl_assembler_name()

void lhd_overwrite_decl_assembler_name ( tree decl,
tree name )
Forcibly overwrite the DECL_ASSEMBLER_NAME for DECL to NAME.   


◆ lhd_pass_through_t()

tree lhd_pass_through_t ( tree t)
Pass through (tree).   

◆ lhd_post_options()

bool lhd_post_options ( const char ** ARG_UNUSEDpfilename)
The default post options hook.   

References EXCESS_PRECISION_FAST, and ggc_alloc().

◆ lhd_print_error_function()

◆ lhd_print_tree_nothing()

void lhd_print_tree_nothing ( FILE * ARG_UNUSEDfile,
tree ARG_UNUSEDnode,
int ARG_UNUSEDindent )
Called from by print-tree.cc.   

◆ lhd_register_builtin_type()

void lhd_register_builtin_type ( tree ARG_UNUSEDtype,
const char * ARG_UNUSEDname )
Registration of machine- or os-specific builtin types.   

◆ lhd_register_dumps()

void lhd_register_dumps ( gcc::dump_manager * )
Called to register dumps.   

◆ lhd_return_null_const_tree()

tree lhd_return_null_const_tree ( const_tree ARG_UNUSEDt)
Do nothing (return NULL_TREE).   

References NULL_TREE.

◆ lhd_return_null_tree()

tree lhd_return_null_tree ( tree ARG_UNUSEDt)
Do nothing (return NULL_TREE).   

References NULL_TREE.

◆ lhd_set_decl_assembler_name()

◆ lhd_simulate_enum_decl()

tree lhd_simulate_enum_decl ( location_t loc,
const char * name,
vec< string_int_pair > * values_ptr )
Default implementation of LANG_HOOKS_SIMULATE_ENUM_DECL.  Assume a
simple int-based enumerator (which is all the hook can be used for
at present) and push each decl individually without any decoration.

This definition is suitable for LTO and is generic enough that it
might be reusable elsewhere.   

References build_decl(), build_int_cst(), DECL_INITIAL, lang_hooks::decls, FOR_EACH_VEC_ELT, get_identifier(), ggc_alloc(), i, integer_type_node, layout_type(), lang_hooks_for_types::make_type, NULL_TREE, lang_hooks_for_decls::pushdecl, SET_TYPE_ALIGN, tree_cons(), TYPE_ALIGN, TYPE_MAX_VALUE, TYPE_MIN_VALUE, TYPE_PRECISION, TYPE_STUB_DECL, and lang_hooks::types.

◆ lhd_simulate_record_decl()

tree lhd_simulate_record_decl ( location_t loc,
const char * name,
array_slice< const tree > fields )
Default implementation of LANG_HOOKS_SIMULATE_RECORD_DECL.
Just create a normal RECORD_TYPE and a TYPE_DECL for it.   

References build_decl(), DECL_CHAIN, lang_hooks::decls, fields, finish_builtin_struct(), get_identifier(), ggc_alloc(), i, lang_hooks_for_types::make_type, NULL_TREE, lang_hooks_for_decls::pushdecl, type(), and lang_hooks::types.

◆ lhd_to_target_charset()

HOST_WIDE_INT lhd_to_target_charset ( HOST_WIDE_INT c)

◆ lhd_tree_dump_dump_tree()

bool lhd_tree_dump_dump_tree ( void * di,
tree t )
lang_hooks.tree_dump.dump_tree:  Dump language-specific parts of tree
nodes.  Returns nonzero if it does not want the usual dumping of the
second argument.   

◆ lhd_tree_dump_type_quals()

int lhd_tree_dump_type_quals ( const_tree t)
lang_hooks.tree_dump.type_qual:  Determine type qualifiers in a
language-specific way.   

References TYPE_QUALS.

◆ lhd_tree_size()

size_t lhd_tree_size ( enum tree_code c)
lang_hooks.tree_size: Determine the size of a tree with code C,
which is a language-specific tree code in category tcc_constant,
tcc_exceptional or tcc_type.  The default expects never to be called.   

References gcc_unreachable.

◆ lhd_type_dwarf_attribute()

int lhd_type_dwarf_attribute ( const_tree ,
int  )
Default implementation of LANG_HOOKS_TYPE_DWARF_ATTRIBUTE.  Don't add
any attributes.   

◆ lhd_type_for_size()

◆ lhd_type_promotes_to()

tree lhd_type_promotes_to ( tree ARG_UNUSEDtype)
Type promotion for variable arguments.   

References gcc_unreachable.

◆ lhd_types_compatible_p()

int lhd_types_compatible_p ( tree x,
tree y )
This compares two types for equivalence ("compatible" in C-based languages).
This routine should only return 1 if it is sure.  It should not be used
in contexts where erroneously returning 0 causes problems.   

References TYPE_MAIN_VARIANT, and y.

◆ lhd_unit_size_without_reusable_padding()

tree lhd_unit_size_without_reusable_padding ( tree t)
Just return TYPE_SIZE_UNIT unadjusted.   

References TYPE_SIZE_UNIT.

◆ lhd_warn_unused_global_decl()

bool lhd_warn_unused_global_decl ( const_tree decl)
Called from check_global_declaration.   


◆ simulate_builtin_function_decl()

tree simulate_builtin_function_decl ( location_t location,
const char * name,
tree type,
int function_code,
const char * library_name,
tree attrs )
Simulate a declaration of a target-specific built-in function at
location LOCATION, as though it had been declared directly in the
source language.  NAME is the name of the function, TYPE is its function
type, FUNCTION_CODE is the target-specific function code, LIBRARY_NAME
is the name of the underlying library function (NULL if none) and
ATTRS is a list of function attributes.

Return the decl of the declared function.   

References build_builtin_function(), BUILT_IN_MD, fndecl_built_in_p(), ggc_alloc(), lang_hooks::simulate_builtin_function_decl, and TREE_CODE.

Variable Documentation

◆ saved_section

section* saved_section
LTO hooks.   
Used to save and restore any previously active section.   

Referenced by lhd_begin_section(), and lhd_end_section().