GCC Middle and Back End API Reference
attr-handlers.cc File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "target.h"
#include "function.h"
#include "tree.h"
#include "stringpool.h"
#include "attribs.h"
#include "attr-handlers.h"
#include "diagnostic-core.h"
#include "options.h"
#include "cgraph.h"
#include "varasm.h"
#include "common/common-target.h"
#include "tree-pretty-print.h"
Include dependency graph for attr-handlers.cc:

Macros

#define ATTR_EXCL(name, function, type, variable)

Functions

static tree decl_or_type_attrs (tree node)
bool validate_attr_args (tree node[2], tree name, tree newargs[2])
bool validate_attr_arg (tree node[2], tree name, tree newarg)
tree handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args, bool *no_add_attrs)
tree ignore_attribute (tree *ARG_UNUSED(node), tree ARG_UNUSED(name), tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_leaf_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_const_attribute (tree *node, tree name, tree ARG_UNUSED(args), int flags, bool *no_add_attrs)
tree handle_pure_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_novops_attribute (tree *node, tree ARG_UNUSED(name), tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *ARG_UNUSED(no_add_attrs))
tree handle_nothrow_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_type_generic_attribute (tree *node, tree ARG_UNUSED(name), tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *ARG_UNUSED(no_add_attrs))
tree handle_returns_twice_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_fnspec_attribute (tree *node, tree ARG_UNUSED(name), tree args, int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_visibility_attribute (tree *node, tree name, tree args, int ARG_UNUSED(flags), bool *ARG_UNUSED(no_add_attrs))
tree handle_always_inline_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_noinline_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_weak_attribute (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *ARG_UNUSED(no_add_attrs))
tree handle_target_attribute (tree *node, tree name, tree args, int flags, bool *no_add_attrs)
tree handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_alias_attribute (tree *node, tree name, tree args, int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_section_attribute (tree *node, tree name, tree args, int flags, bool *no_add_attrs)
tree handle_retain_attribute (tree *pnode, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)
tree handle_malloc_common (tree *node, tree name, tree ARG_UNUSED(args), int ARG_UNUSED(flags), bool *no_add_attrs)

Variables

const struct attribute_spec::exclusions attr_noreturn_exclusions []
const struct attribute_spec::exclusions attr_returns_twice_exclusions []
const struct attribute_spec::exclusions attr_alloc_exclusions []
const struct attribute_spec::exclusions attr_const_pure_exclusions []
const struct attribute_spec::exclusions attr_always_inline_exclusions []
const struct attribute_spec::exclusions attr_cold_hot_exclusions []
const struct attribute_spec::exclusions attr_noinline_exclusions []
const struct attribute_spec::exclusions attr_target_exclusions []
const struct attribute_spec::exclusions attr_section_exclusions []

Macro Definition Documentation

◆ ATTR_EXCL

#define ATTR_EXCL ( name,
function,
type,
variable )
Value:
{ name, function, type, variable }
Definition function.h:249
Definition gengtype.h:252
Definition var-tracking.cc:367
Language-independent attribute handlers shared across front ends.
   Copyright (C) 2026 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/>.   
Helper to define attribute exclusions.   

Function Documentation

◆ decl_or_type_attrs()

tree decl_or_type_attrs ( tree node)
static
Return the first of DECL or TYPE attributes installed in NODE if it's
a DECL, or TYPE attributes if it's a TYPE, or null otherwise.   

References DECL_ATTRIBUTES, decl_or_type_attrs(), DECL_P, error_mark_node, NULL_TREE, TREE_TYPE, TYPE_ATTRIBUTES, and TYPE_P.

Referenced by decl_or_type_attrs(), and validate_attr_args().

◆ handle_alias_attribute()

tree handle_alias_attribute ( tree * node,
tree name,
tree args,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle an "alias" or "ifunc" attribute; arguments as in
struct attribute_spec.handler.   

References handle_alias_attribute(), handle_alias_ifunc_attribute(), and symtab_node::name().

Referenced by handle_alias_attribute(), and handle_alias_attribute().

◆ handle_alias_ifunc_attribute()

tree handle_alias_ifunc_attribute ( bool is_alias,
tree * node,
tree name,
tree args,
bool * no_add_attrs )
Handle an "alias" or "ifunc" attribute; arguments as in
struct attribute_spec.handler, except that IS_ALIAS tells us
whether this is an alias as opposed to ifunc attribute.   
Attribute handlers.   

References current_function_decl, DECL_ATTRIBUTES, DECL_EXTERNAL, decl_function_context(), decl_in_symtab_p(), DECL_INITIAL, error(), error_mark_node, symtab_node::get(), get_identifier(), handle_alias_ifunc_attribute(), lookup_attribute(), NULL, NULL_TREE, TREE_CODE, tree_cons(), TREE_PUBLIC, TREE_STATIC, TREE_STRING_POINTER, TREE_USED, TREE_VALUE, VAR_P, and warning().

Referenced by handle_alias_attribute(), and handle_alias_ifunc_attribute().

◆ handle_always_inline_attribute()

tree handle_always_inline_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "always_inline" attribute; arguments as in
struct attribute_spec.handler.   

References DECL_DISREGARD_INLINE_LIMITS, handle_always_inline_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, and warning().

Referenced by handle_always_inline_attribute(), and handle_always_inline_attribute().

◆ handle_const_attribute()

tree handle_const_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int flags,
bool * no_add_attrs )

◆ handle_fnspec_attribute()

tree handle_fnspec_attribute ( tree * node,
tree ARG_UNUSEDname,
tree args,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "fn spec" attribute; arguments as in
struct attribute_spec.handler.   

References gcc_assert, handle_fnspec_attribute(), NULL_TREE, TREE_CHAIN, TREE_CODE, and TREE_VALUE.

Referenced by handle_fnspec_attribute(), and handle_fnspec_attribute().

◆ handle_leaf_attribute()

tree handle_leaf_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "leaf" attribute; arguments as in
struct attribute_spec.handler.   

References handle_leaf_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, TREE_PUBLIC, and warning().

Referenced by handle_leaf_attribute(), and handle_leaf_attribute().

◆ handle_malloc_common()

tree handle_malloc_common ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Part of the `malloc` attribute handling which is shared by libgccjit and
the C-family front-end.   

References DECL_IS_MALLOC, handle_malloc_common(), symtab_node::name(), NULL_TREE, POINTER_TYPE_P, TREE_CODE, TREE_TYPE, and warning().

Referenced by handle_malloc_common(), and handle_malloc_common().

◆ handle_noinline_attribute()

tree handle_noinline_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "noinline" attribute; arguments as in
struct attribute_spec.handler.   

References DECL_UNINLINABLE, handle_noinline_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, and warning().

Referenced by handle_noinline_attribute(), and handle_noinline_attribute().

◆ handle_nothrow_attribute()

tree handle_nothrow_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "nothrow" attribute; arguments as in
struct attribute_spec.handler.   

References handle_nothrow_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, TREE_NOTHROW, and warning().

Referenced by handle_nothrow_attribute(), and handle_nothrow_attribute().

◆ handle_novops_attribute()

tree handle_novops_attribute ( tree * node,
tree ARG_UNUSEDname,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * ARG_UNUSEDno_add_attrs )
Handle a "no vops" attribute; arguments as in
struct attribute_spec.handler.   

References DECL_IS_NOVOPS, gcc_assert, handle_novops_attribute(), NULL_TREE, and TREE_CODE.

Referenced by handle_novops_attribute(), and handle_novops_attribute().

◆ handle_pure_attribute()

tree handle_pure_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "pure" attribute; arguments as in
struct attribute_spec.handler.   

References DECL_PURE_P, handle_pure_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, TREE_TYPE, VOID_TYPE_P, and warning().

Referenced by handle_pure_attribute(), and handle_pure_attribute().

◆ handle_retain_attribute()

tree handle_retain_attribute ( tree * pnode,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "retain" attribute; arguments as in
struct attribute_spec.handler.   

References handle_retain_attribute(), symtab_node::name(), NULL_TREE, SUPPORTS_SHF_GNU_RETAIN, TREE_CODE, TREE_STATIC, VAR_P, and warning().

Referenced by handle_retain_attribute(), and handle_retain_attribute().

◆ handle_returns_twice_attribute()

tree handle_returns_twice_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )

◆ handle_section_attribute()

◆ handle_target_attribute()

tree handle_target_attribute ( tree * node,
tree name,
tree args,
int flags,
bool * no_add_attrs )

◆ handle_type_generic_attribute()

tree handle_type_generic_attribute ( tree * node,
tree ARG_UNUSEDname,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * ARG_UNUSEDno_add_attrs )

◆ handle_used_attribute()

tree handle_used_attribute ( tree * pnode,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Handle a "used" attribute; arguments as in
struct attribute_spec.handler.   

References DECL_PRESERVE_P, DECL_READ_P, handle_used_attribute(), symtab_node::name(), NULL_TREE, TREE_CODE, TREE_STATIC, TREE_USED, VAR_P, and warning().

Referenced by handle_used_attribute(), and handle_used_attribute().

◆ handle_visibility_attribute()

◆ handle_weak_attribute()

tree handle_weak_attribute ( tree * node,
tree name,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * ARG_UNUSEDno_add_attrs )

◆ ignore_attribute()

tree ignore_attribute ( tree * ARG_UNUSEDnode,
tree ARG_UNUSEDname,
tree ARG_UNUSEDargs,
int ARG_UNUSEDflags,
bool * no_add_attrs )
Ignore the given attribute.  Used when this attribute may be usefully
overridden by the target, but is not used generically.   

References ignore_attribute(), and NULL_TREE.

Referenced by ignore_attribute(), and ignore_attribute().

◆ validate_attr_arg()

bool validate_attr_arg ( tree node[2],
tree name,
tree newarg )
Convenience wrapper for validate_attr_args to validate a single
attribute argument.  Used by handlers for attributes that take
just a single argument.   

References NULL_TREE, validate_attr_arg(), and validate_attr_args().

Referenced by handle_section_attribute(), and validate_attr_arg().

◆ validate_attr_args()

bool validate_attr_args ( tree node[2],
tree name,
tree newargs[2] )
Given a pair of NODEs for arbitrary DECLs or TYPEs, validate one or
two integral or string attribute arguments NEWARGS to be applied to
NODE[0] for the absence of conflicts with the same attribute arguments
already applied to NODE[1]. Issue a warning for conflicts and return
false.  Otherwise, when no conflicts are found, return true.   
Shared helpers used by the handlers.   

References decl_or_type_attrs(), DECL_P, DECL_SOURCE_LOCATION, gcc_unreachable, IDENTIFIER_POINTER, inform(), input_location, lookup_attribute(), print_generic_expr_to_str(), TREE_CHAIN, TREE_CODE, tree_int_cst_equal(), TREE_STRING_POINTER, TREE_VALUE, validate_attr_args(), and warning_at().

Referenced by validate_attr_arg(), and validate_attr_args().

Variable Documentation

◆ attr_alloc_exclusions

const struct attribute_spec::exclusions attr_alloc_exclusions[]
Initial value:
=
{
ATTR_EXCL ("const", true, true, true),
ATTR_EXCL ("noreturn", true, true, true),
ATTR_EXCL ("pure", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}
#define ATTR_EXCL(name, function, type, variable)
Definition attr-handlers.cc:37
#define NULL
Definition system.h:58
Exclusions that apply to attribute alloc_align, alloc_size, and malloc.   

◆ attr_always_inline_exclusions

const struct attribute_spec::exclusions attr_always_inline_exclusions[]
Initial value:
=
{
ATTR_EXCL ("noinline", true, true, true),
ATTR_EXCL ("target_clones", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}

◆ attr_cold_hot_exclusions

const struct attribute_spec::exclusions attr_cold_hot_exclusions[]
Initial value:
=
{
ATTR_EXCL ("cold", true, true, true),
ATTR_EXCL ("hot", true, true, true),
}

◆ attr_const_pure_exclusions

const struct attribute_spec::exclusions attr_const_pure_exclusions[]
Initial value:
=
{
ATTR_EXCL ("const", true, true, true),
ATTR_EXCL ("alloc_align", true, true, true),
ATTR_EXCL ("alloc_size", true, true, true),
ATTR_EXCL ("malloc", true, true, true),
ATTR_EXCL ("noreturn", true, true, true),
ATTR_EXCL ("pure", true, true, true),
}

◆ attr_noinline_exclusions

const struct attribute_spec::exclusions attr_noinline_exclusions[]
Initial value:
=
{
ATTR_EXCL ("always_inline", true, true, true),
ATTR_EXCL ("gnu_inline", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}

◆ attr_noreturn_exclusions

const struct attribute_spec::exclusions attr_noreturn_exclusions[]
Initial value:
=
{
ATTR_EXCL ("alloc_align", true, true, true),
ATTR_EXCL ("alloc_size", true, true, true),
ATTR_EXCL ("const", true, true, true),
ATTR_EXCL ("malloc", true, true, true),
ATTR_EXCL ("pure", true, true, true),
ATTR_EXCL ("returns_twice", true, true, true),
ATTR_EXCL ("warn_unused_result", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}
Define attributes that are mutually exclusive with one another.   
Language-independent attribute handlers shared across front ends.
   Copyright (C) 2026 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/>.   
Attribute exclusion tables used by `c-family` and `libgccjit`.   

◆ attr_returns_twice_exclusions

const struct attribute_spec::exclusions attr_returns_twice_exclusions[]
Initial value:
=
{
ATTR_EXCL ("noreturn", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}

◆ attr_section_exclusions

const struct attribute_spec::exclusions attr_section_exclusions[]
Initial value:
=
{
ATTR_EXCL ("noinit", true, true, true),
ATTR_EXCL ("persistent", true, true, true),
ATTR_EXCL ("section", true, true, true),
ATTR_EXCL (NULL, false, false, false),
}
Exclusions that apply to attributes that put declarations in specific
sections.   

◆ attr_target_exclusions

const struct attribute_spec::exclusions attr_target_exclusions[]
Initial value:
=
{
ATTR_EXCL (NULL, false, false, false),
}
#define TARGET_HAS_FMV_TARGET_ATTRIBUTE
Definition defaults.h:874