| /* C-family attributes handling. |
| Copyright (C) 1992-2022 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/>. */ |
| |
| #define INCLUDE_STRING |
| #include "config.h" |
| #include "system.h" |
| #include "coretypes.h" |
| #include "target.h" |
| #include "function.h" |
| #include "tree.h" |
| #include "memmodel.h" |
| #include "c-common.h" |
| #include "gimple-expr.h" |
| #include "tm_p.h" |
| #include "stringpool.h" |
| #include "cgraph.h" |
| #include "diagnostic.h" |
| #include "intl.h" |
| #include "stor-layout.h" |
| #include "calls.h" |
| #include "attribs.h" |
| #include "varasm.h" |
| #include "trans-mem.h" |
| #include "c-objc.h" |
| #include "common/common-target.h" |
| #include "langhooks.h" |
| #include "tree-inline.h" |
| #include "toplev.h" |
| #include "tree-iterator.h" |
| #include "opts.h" |
| #include "gimplify.h" |
| #include "tree-pretty-print.h" |
| #include "gcc-rich-location.h" |
| |
| static tree handle_packed_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_nocommon_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_common_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_hot_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_cold_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_no_sanitize_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_no_sanitize_address_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_no_sanitize_thread_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_no_sanitize_undefined_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_no_sanitize_coverage_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_asan_odr_indicator_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_stack_protect_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_no_stack_protector_function_attribute (tree *, tree, |
| tree, int, bool *); |
| static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_nocf_check_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_symver_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_noicf_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_noipa_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_always_inline_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_gnu_inline_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_artificial_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_flatten_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_error_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_used_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_uninitialized_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_externally_visible_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_no_reorder_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_const_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_transparent_union_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_scalar_storage_order_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_constructor_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_destructor_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_mode_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_section_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_special_var_sec_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_aligned_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ; |
| static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ; |
| static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *); |
| static tree handle_ifunc_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_alias_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_weakref_attribute (tree *, tree, tree, int, bool *) ; |
| static tree handle_visibility_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_tls_model_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_no_instrument_function_attribute (tree *, tree, |
| tree, int, bool *); |
| static tree handle_no_profile_instrument_function_attribute (tree *, tree, |
| tree, int, bool *); |
| static tree handle_malloc_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_dealloc_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_tainted_args_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_returns_twice_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_no_limit_stack_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_pure_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_tm_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_tm_wrap_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_novops_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_unavailable_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_vector_size_attribute (tree *, tree, tree, int, |
| bool *) ATTRIBUTE_NONNULL(3); |
| static tree handle_vector_mask_attribute (tree *, tree, tree, int, |
| bool *) ATTRIBUTE_NONNULL(3); |
| static tree handle_nonnull_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_nonstring_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_nothrow_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_cleanup_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_warn_unused_result_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_access_attribute (tree *, tree, tree, int, bool *); |
| |
| static tree handle_sentinel_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_alloc_size_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_alloc_align_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_assume_aligned_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_target_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_target_clones_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_optimize_attribute (tree *, tree, tree, int, bool *); |
| static tree ignore_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_no_split_stack_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_zero_call_used_regs_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_argspec_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_warn_unused_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_returns_nonnull_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_omp_declare_variant_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_simd_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_omp_declare_target_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_non_overlapping_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_designated_init_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_patchable_function_entry_attribute (tree *, tree, tree, |
| int, bool *); |
| static tree handle_copy_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_nsobject_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_objc_root_class_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_objc_nullability_attribute (tree *, tree, tree, int, bool *); |
| static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int, |
| bool *); |
| static tree handle_retain_attribute (tree *, tree, tree, int, bool *); |
| |
| /* Helper to define attribute exclusions. */ |
| #define ATTR_EXCL(name, function, type, variable) \ |
| { name, function, type, variable } |
| |
| /* Define attributes that are mutually exclusive with one another. */ |
| static const struct attribute_spec::exclusions attr_aligned_exclusions[] = |
| { |
| /* Attribute name exclusion applies to: |
| function, type, variable */ |
| ATTR_EXCL ("aligned", true, false, false), |
| ATTR_EXCL ("packed", true, false, false), |
| ATTR_EXCL (NULL, false, false, false) |
| }; |
| |
| extern const struct attribute_spec::exclusions attr_cold_hot_exclusions[] = |
| { |
| ATTR_EXCL ("cold", true, true, true), |
| ATTR_EXCL ("hot", true, true, true), |
| ATTR_EXCL (NULL, false, false, false) |
| }; |
| |
| static const struct attribute_spec::exclusions attr_common_exclusions[] = |
| { |
| ATTR_EXCL ("common", true, true, true), |
| ATTR_EXCL ("nocommon", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| static const struct attribute_spec::exclusions attr_inline_exclusions[] = |
| { |
| ATTR_EXCL ("noinline", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| static const struct attribute_spec::exclusions attr_noinline_exclusions[] = |
| { |
| ATTR_EXCL ("always_inline", true, true, true), |
| ATTR_EXCL ("gnu_inline", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| extern const struct attribute_spec::exclusions attr_noreturn_exclusions[] = |
| { |
| 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), |
| }; |
| |
| static const struct attribute_spec::exclusions |
| attr_warn_unused_result_exclusions[] = |
| { |
| ATTR_EXCL ("noreturn", true, true, true), |
| ATTR_EXCL ("warn_unused_result", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| static const struct attribute_spec::exclusions attr_returns_twice_exclusions[] = |
| { |
| ATTR_EXCL ("noreturn", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| /* Exclusions that apply to attribute alloc_align, alloc_size, and malloc. */ |
| static const struct attribute_spec::exclusions attr_alloc_exclusions[] = |
| { |
| ATTR_EXCL ("const", true, true, true), |
| ATTR_EXCL ("noreturn", true, true, true), |
| ATTR_EXCL ("pure", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| static const struct attribute_spec::exclusions attr_const_pure_exclusions[] = |
| { |
| 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_EXCL (NULL, false, false, false) |
| }; |
| |
| /* Exclusions that apply to attributes that put declarations in specific |
| sections. */ |
| static const struct attribute_spec::exclusions attr_section_exclusions[] = |
| { |
| ATTR_EXCL ("noinit", true, true, true), |
| ATTR_EXCL ("persistent", true, true, true), |
| ATTR_EXCL ("section", true, true, true), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| static const struct attribute_spec::exclusions attr_stack_protect_exclusions[] = |
| { |
| ATTR_EXCL ("stack_protect", true, false, false), |
| ATTR_EXCL ("no_stack_protector", true, false, false), |
| ATTR_EXCL (NULL, false, false, false), |
| }; |
| |
| |
| /* Table of machine-independent attributes common to all C-like languages. |
| |
| Current list of processed common attributes: nonnull. */ |
| const struct attribute_spec c_common_attribute_table[] = |
| { |
| /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
| affects_type_identity, handler, exclude } */ |
| { "signed_bool_precision", 1, 1, false, true, false, true, |
| handle_signed_bool_precision_attribute, NULL }, |
| { "packed", 0, 0, false, false, false, false, |
| handle_packed_attribute, |
| attr_aligned_exclusions }, |
| { "nocommon", 0, 0, true, false, false, false, |
| handle_nocommon_attribute, |
| attr_common_exclusions }, |
| { "common", 0, 0, true, false, false, false, |
| handle_common_attribute, |
| attr_common_exclusions }, |
| /* FIXME: logically, noreturn attributes should be listed as |
| "false, true, true" and apply to function types. But implementing this |
| would require all the places in the compiler that use TREE_THIS_VOLATILE |
| on a decl to identify non-returning functions to be located and fixed |
| to check the function type instead. */ |
| { "noreturn", 0, 0, true, false, false, false, |
| handle_noreturn_attribute, |
| attr_noreturn_exclusions }, |
| { "volatile", 0, 0, true, false, false, false, |
| handle_noreturn_attribute, NULL }, |
| { "stack_protect", 0, 0, true, false, false, false, |
| handle_stack_protect_attribute, |
| attr_stack_protect_exclusions }, |
| { "no_stack_protector", 0, 0, true, false, false, false, |
| handle_no_stack_protector_function_attribute, |
| attr_stack_protect_exclusions }, |
| { "noinline", 0, 0, true, false, false, false, |
| handle_noinline_attribute, |
| attr_noinline_exclusions }, |
| { "noclone", 0, 0, true, false, false, false, |
| handle_noclone_attribute, NULL }, |
| { "no_icf", 0, 0, true, false, false, false, |
| handle_noicf_attribute, NULL }, |
| { "noipa", 0, 0, true, false, false, false, |
| handle_noipa_attribute, NULL }, |
| { "leaf", 0, 0, true, false, false, false, |
| handle_leaf_attribute, NULL }, |
| { "always_inline", 0, 0, true, false, false, false, |
| handle_always_inline_attribute, |
| attr_inline_exclusions }, |
| { "gnu_inline", 0, 0, true, false, false, false, |
| handle_gnu_inline_attribute, |
| attr_inline_exclusions }, |
| { "artificial", 0, 0, true, false, false, false, |
| handle_artificial_attribute, NULL }, |
| { "flatten", 0, 0, true, false, false, false, |
| handle_flatten_attribute, NULL }, |
| { "used", 0, 0, true, false, false, false, |
| handle_used_attribute, NULL }, |
| { "unused", 0, 0, false, false, false, false, |
| handle_unused_attribute, NULL }, |
| { "uninitialized", 0, 0, true, false, false, false, |
| handle_uninitialized_attribute, NULL }, |
| { "retain", 0, 0, true, false, false, false, |
| handle_retain_attribute, NULL }, |
| { "externally_visible", 0, 0, true, false, false, false, |
| handle_externally_visible_attribute, NULL }, |
| { "no_reorder", 0, 0, true, false, false, false, |
| handle_no_reorder_attribute, NULL }, |
| /* The same comments as for noreturn attributes apply to const ones. */ |
| { "const", 0, 0, true, false, false, false, |
| handle_const_attribute, |
| attr_const_pure_exclusions }, |
| { "scalar_storage_order", 1, 1, false, false, false, false, |
| handle_scalar_storage_order_attribute, NULL }, |
| { "transparent_union", 0, 0, false, false, false, false, |
| handle_transparent_union_attribute, NULL }, |
| { "constructor", 0, 1, true, false, false, false, |
| handle_constructor_attribute, NULL }, |
| { "destructor", 0, 1, true, false, false, false, |
| handle_destructor_attribute, NULL }, |
| { "mode", 1, 1, false, true, false, false, |
| handle_mode_attribute, NULL }, |
| { "section", 1, 1, true, false, false, false, |
| handle_section_attribute, attr_section_exclusions }, |
| { "aligned", 0, 1, false, false, false, false, |
| handle_aligned_attribute, |
| attr_aligned_exclusions }, |
| { "warn_if_not_aligned", 0, 1, false, false, false, false, |
| handle_warn_if_not_aligned_attribute, NULL }, |
| { "weak", 0, 0, true, false, false, false, |
| handle_weak_attribute, NULL }, |
| { "noplt", 0, 0, true, false, false, false, |
| handle_noplt_attribute, NULL }, |
| { "ifunc", 1, 1, true, false, false, false, |
| handle_ifunc_attribute, NULL }, |
| { "alias", 1, 1, true, false, false, false, |
| handle_alias_attribute, NULL }, |
| { "weakref", 0, 1, true, false, false, false, |
| handle_weakref_attribute, NULL }, |
| { "no_instrument_function", 0, 0, true, false, false, false, |
| handle_no_instrument_function_attribute, |
| NULL }, |
| { "no_profile_instrument_function", 0, 0, true, false, false, false, |
| handle_no_profile_instrument_function_attribute, |
| NULL }, |
| { "malloc", 0, 2, true, false, false, false, |
| handle_malloc_attribute, attr_alloc_exclusions }, |
| { "returns_twice", 0, 0, true, false, false, false, |
| handle_returns_twice_attribute, |
| attr_returns_twice_exclusions }, |
| { "no_stack_limit", 0, 0, true, false, false, false, |
| handle_no_limit_stack_attribute, NULL }, |
| { "pure", 0, 0, true, false, false, false, |
| handle_pure_attribute, |
| attr_const_pure_exclusions }, |
| { "transaction_callable", 0, 0, false, true, false, false, |
| handle_tm_attribute, NULL }, |
| { "transaction_unsafe", 0, 0, false, true, false, true, |
| handle_tm_attribute, NULL }, |
| { "transaction_safe", 0, 0, false, true, false, true, |
| handle_tm_attribute, NULL }, |
| { "transaction_safe_dynamic", 0, 0, true, false, false, false, |
| handle_tm_attribute, NULL }, |
| { "transaction_may_cancel_outer", 0, 0, false, true, false, false, |
| handle_tm_attribute, NULL }, |
| /* ??? These two attributes didn't make the transition from the |
| Intel language document to the multi-vendor language document. */ |
| { "transaction_pure", 0, 0, false, true, false, false, |
| handle_tm_attribute, NULL }, |
| { "transaction_wrap", 1, 1, true, false, false, false, |
| handle_tm_wrap_attribute, NULL }, |
| /* For internal use (marking of builtins) only. The name contains space |
| to prevent its usage in source code. */ |
| { "no vops", 0, 0, true, false, false, false, |
| handle_novops_attribute, NULL }, |
| { "deprecated", 0, 1, false, false, false, false, |
| handle_deprecated_attribute, NULL }, |
| { "unavailable", 0, 1, false, false, false, false, |
| handle_unavailable_attribute, NULL }, |
| { "vector_size", 1, 1, false, true, false, true, |
| handle_vector_size_attribute, NULL }, |
| { "vector_mask", 0, 0, false, true, false, true, |
| handle_vector_mask_attribute, NULL }, |
| { "visibility", 1, 1, false, false, false, false, |
| handle_visibility_attribute, NULL }, |
| { "tls_model", 1, 1, true, false, false, false, |
| handle_tls_model_attribute, NULL }, |
| { "nonnull", 0, -1, false, true, true, false, |
| handle_nonnull_attribute, NULL }, |
| { "nonstring", 0, 0, true, false, false, false, |
| handle_nonstring_attribute, NULL }, |
| { "nothrow", 0, 0, true, false, false, false, |
| handle_nothrow_attribute, NULL }, |
| { "may_alias", 0, 0, false, true, false, false, NULL, NULL }, |
| { "cleanup", 1, 1, true, false, false, false, |
| handle_cleanup_attribute, NULL }, |
| { "warn_unused_result", 0, 0, false, true, true, false, |
| handle_warn_unused_result_attribute, |
| attr_warn_unused_result_exclusions }, |
| { "sentinel", 0, 1, false, true, true, false, |
| handle_sentinel_attribute, NULL }, |
| /* For internal use (marking of builtins) only. The name contains space |
| to prevent its usage in source code. */ |
| { "type generic", 0, 0, false, true, true, false, |
| handle_type_generic_attribute, NULL }, |
| { "alloc_size", 1, 2, false, true, true, false, |
| handle_alloc_size_attribute, |
| attr_alloc_exclusions }, |
| { "cold", 0, 0, true, false, false, false, |
| handle_cold_attribute, |
| attr_cold_hot_exclusions }, |
| { "hot", 0, 0, true, false, false, false, |
| handle_hot_attribute, |
| attr_cold_hot_exclusions }, |
| { "no_address_safety_analysis", |
| 0, 0, true, false, false, false, |
| handle_no_address_safety_analysis_attribute, |
| NULL }, |
| { "no_sanitize", 1, -1, true, false, false, false, |
| handle_no_sanitize_attribute, NULL }, |
| { "no_sanitize_address", 0, 0, true, false, false, false, |
| handle_no_sanitize_address_attribute, NULL }, |
| { "no_sanitize_thread", 0, 0, true, false, false, false, |
| handle_no_sanitize_thread_attribute, NULL }, |
| { "no_sanitize_undefined", 0, 0, true, false, false, false, |
| handle_no_sanitize_undefined_attribute, NULL }, |
| { "no_sanitize_coverage", 0, 0, true, false, false, false, |
| handle_no_sanitize_coverage_attribute, NULL }, |
| { "asan odr indicator", 0, 0, true, false, false, false, |
| handle_asan_odr_indicator_attribute, NULL }, |
| { "warning", 1, 1, true, false, false, false, |
| handle_error_attribute, NULL }, |
| { "error", 1, 1, true, false, false, false, |
| handle_error_attribute, NULL }, |
| { "target", 1, -1, true, false, false, false, |
| handle_target_attribute, NULL }, |
| { "target_clones", 1, -1, true, false, false, false, |
| handle_target_clones_attribute, NULL }, |
| { "optimize", 1, -1, true, false, false, false, |
| handle_optimize_attribute, NULL }, |
| /* For internal use only. The leading '*' both prevents its usage in |
| source code and signals that it may be overridden by machine tables. */ |
| { "*tm regparm", 0, 0, false, true, true, false, |
| ignore_attribute, NULL }, |
| { "no_split_stack", 0, 0, true, false, false, false, |
| handle_no_split_stack_attribute, NULL }, |
| { "zero_call_used_regs", 1, 1, true, false, false, false, |
| handle_zero_call_used_regs_attribute, NULL }, |
| /* For internal use only (marking of function arguments). |
| The name contains a space to prevent its usage in source code. */ |
| { "arg spec", 1, -1, true, false, false, false, |
| handle_argspec_attribute, NULL }, |
| /* For internal use (marking of builtins and runtime functions) only. |
| The name contains space to prevent its usage in source code. */ |
| { "fn spec", 1, 1, false, true, true, false, |
| handle_fnspec_attribute, NULL }, |
| { "warn_unused", 0, 0, false, false, false, false, |
| handle_warn_unused_attribute, NULL }, |
| { "returns_nonnull", 0, 0, false, true, true, false, |
| handle_returns_nonnull_attribute, NULL }, |
| { "omp declare simd", 0, -1, true, false, false, false, |
| handle_omp_declare_simd_attribute, NULL }, |
| { "omp declare variant base", 0, -1, true, false, false, false, |
| handle_omp_declare_variant_attribute, NULL }, |
| { "omp declare variant variant", 0, -1, true, false, false, false, |
| handle_omp_declare_variant_attribute, NULL }, |
| { "simd", 0, 1, true, false, false, false, |
| handle_simd_attribute, NULL }, |
| { "omp declare target", 0, -1, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "omp declare target link", 0, 0, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "omp declare target implicit", 0, 0, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "omp declare target host", 0, 0, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "omp declare target nohost", 0, 0, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "omp declare target block", 0, 0, true, false, false, false, |
| handle_omp_declare_target_attribute, NULL }, |
| { "non overlapping", 0, 0, true, false, false, false, |
| handle_non_overlapping_attribute, NULL }, |
| { "alloc_align", 1, 1, false, true, true, false, |
| handle_alloc_align_attribute, |
| attr_alloc_exclusions }, |
| { "assume_aligned", 1, 2, false, true, true, false, |
| handle_assume_aligned_attribute, NULL }, |
| { "designated_init", 0, 0, false, true, false, false, |
| handle_designated_init_attribute, NULL }, |
| { "fallthrough", 0, 0, false, false, false, false, |
| handle_fallthrough_attribute, NULL }, |
| { "patchable_function_entry", 1, 2, true, false, false, false, |
| handle_patchable_function_entry_attribute, |
| NULL }, |
| { "nocf_check", 0, 0, false, true, true, true, |
| handle_nocf_check_attribute, NULL }, |
| { "symver", 1, -1, true, false, false, false, |
| handle_symver_attribute, NULL}, |
| { "copy", 1, 1, false, false, false, false, |
| handle_copy_attribute, NULL }, |
| { "noinit", 0, 0, true, false, false, false, |
| handle_special_var_sec_attribute, attr_section_exclusions }, |
| { "persistent", 0, 0, true, false, false, false, |
| handle_special_var_sec_attribute, attr_section_exclusions }, |
| { "access", 1, 3, false, true, true, false, |
| handle_access_attribute, NULL }, |
| /* Attributes used by Objective-C. */ |
| { "NSObject", 0, 0, true, false, false, false, |
| handle_nsobject_attribute, NULL }, |
| { "objc_root_class", 0, 0, true, false, false, false, |
| handle_objc_root_class_attribute, NULL }, |
| { "objc_nullability", 1, 1, true, false, false, false, |
| handle_objc_nullability_attribute, NULL }, |
| { "*dealloc", 1, 2, true, false, false, false, |
| handle_dealloc_attribute, NULL }, |
| { "tainted_args", 0, 0, true, false, false, false, |
| handle_tainted_args_attribute, NULL }, |
| { NULL, 0, 0, false, false, false, false, NULL, NULL } |
| }; |
| |
| /* Give the specifications for the format attributes, used by C and all |
| descendants. |
| |
| Current list of processed format attributes: format, format_arg. */ |
| const struct attribute_spec c_common_format_attribute_table[] = |
| { |
| /* { name, min_len, max_len, decl_req, type_req, fn_type_req, |
| affects_type_identity, handler, exclude } */ |
| { "format", 3, 3, false, true, true, false, |
| handle_format_attribute, NULL }, |
| { "format_arg", 1, 1, false, true, true, false, |
| handle_format_arg_attribute, NULL }, |
| { NULL, 0, 0, false, false, false, false, NULL, NULL } |
| }; |
| |
| /* Returns TRUE iff the attribute indicated by ATTR_ID takes a plain |
| identifier as an argument, so the front end shouldn't look it up. */ |
| |
| bool |
| attribute_takes_identifier_p (const_tree attr_id) |
| { |
| const struct attribute_spec *spec = lookup_attribute_spec (attr_id); |
| if (spec == NULL) |
| /* Unknown attribute that we'll end up ignoring, return true so we |
| don't complain about an identifier argument. */ |
| return true; |
| else if (!strcmp ("mode", spec->name) |
| || !strcmp ("format", spec->name) |
| || !strcmp ("cleanup", spec->name) |
| || !strcmp ("access", spec->name)) |
| return true; |
| else |
| return targetm.attribute_takes_identifier_p (attr_id); |
| } |
| |
| /* Verify that argument value POS at position ARGNO to attribute NAME |
| applied to function TYPE refers to a function parameter at position |
| POS and the expected type CODE. Treat CODE == INTEGER_TYPE as |
| matching all C integral types except bool. If successful, return |
| POS after default conversions, if any. Otherwise, issue appropriate |
| warnings and return null. A non-zero 1-based ARGNO should be passed |
| in by callers only for attributes with more than one argument. */ |
| |
| tree |
| positional_argument (const_tree fntype, const_tree atname, tree pos, |
| tree_code code, int argno /* = 0 */, |
| int flags /* = posargflags () */) |
| { |
| if (pos && TREE_CODE (pos) != IDENTIFIER_NODE |
| && TREE_CODE (pos) != FUNCTION_DECL) |
| pos = default_conversion (pos); |
| |
| tree postype = TREE_TYPE (pos); |
| if (pos == error_mark_node || !postype) |
| { |
| /* Only mention the positional argument number when it's non-zero. */ |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument is invalid", atname); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i is invalid", atname, argno); |
| |
| return NULL_TREE; |
| } |
| |
| if (!INTEGRAL_TYPE_P (postype)) |
| { |
| /* Handle this case specially to avoid mentioning the value |
| of pointer constants in diagnostics. Only mention |
| the positional argument number when it's non-zero. */ |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument has type %qT", |
| atname, postype); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i has type %qT", |
| atname, argno, postype); |
| |
| return NULL_TREE; |
| } |
| |
| if (TREE_CODE (pos) != INTEGER_CST) |
| { |
| /* Only mention the argument number when it's non-zero. */ |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument value %qE is not an integer " |
| "constant", |
| atname, pos); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i value %qE is not an integer " |
| "constant", |
| atname, argno, pos); |
| |
| return NULL_TREE; |
| } |
| |
| /* Argument positions are 1-based. */ |
| if (integer_zerop (pos)) |
| { |
| if (flags & POSARG_ZERO) |
| /* Zero is explicitly allowed. */ |
| return pos; |
| |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument value %qE does not refer to " |
| "a function parameter", |
| atname, pos); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i value %qE does not refer to " |
| "a function parameter", |
| atname, argno, pos); |
| |
| return NULL_TREE; |
| } |
| |
| if (!prototype_p (fntype)) |
| return pos; |
| |
| /* Verify that the argument position does not exceed the number |
| of formal arguments to the function. When POSARG_ELLIPSIS |
| is set, ARGNO may be beyond the last argument of a vararg |
| function. */ |
| unsigned nargs = type_num_arguments (fntype); |
| if (!nargs |
| || !tree_fits_uhwi_p (pos) |
| || ((flags & POSARG_ELLIPSIS) == 0 |
| && !IN_RANGE (tree_to_uhwi (pos), 1, nargs))) |
| { |
| |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument value %qE exceeds the number " |
| "of function parameters %u", |
| atname, pos, nargs); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i value %qE exceeds the number " |
| "of function parameters %u", |
| atname, argno, pos, nargs); |
| return NULL_TREE; |
| } |
| |
| /* Verify that the type of the referenced formal argument matches |
| the expected type. */ |
| unsigned HOST_WIDE_INT ipos = tree_to_uhwi (pos); |
| |
| /* Zero was handled above. */ |
| gcc_assert (ipos != 0); |
| |
| if (tree argtype = type_argument_type (fntype, ipos)) |
| { |
| if (argtype == error_mark_node) |
| return NULL_TREE; |
| |
| if (flags & POSARG_ELLIPSIS) |
| { |
| if (argno < 1) |
| error ("%qE attribute argument value %qE does not refer to " |
| "a variable argument list", |
| atname, pos); |
| else |
| error ("%qE attribute argument %i value %qE does not refer to " |
| "a variable argument list", |
| atname, argno, pos); |
| return NULL_TREE; |
| } |
| |
| /* Where the expected code is STRING_CST accept any pointer |
| expected by attribute format (this includes possibly qualified |
| char pointers and, for targets like Darwin, also pointers to |
| struct CFString). */ |
| bool type_match; |
| if (code == STRING_CST) |
| type_match = valid_format_string_type_p (argtype); |
| else if (code == INTEGER_TYPE) |
| /* For integers, accept enums, wide characters and other types |
| that match INTEGRAL_TYPE_P except for bool. */ |
| type_match = (INTEGRAL_TYPE_P (argtype) |
| && TREE_CODE (argtype) != BOOLEAN_TYPE); |
| else |
| type_match = TREE_CODE (argtype) == code; |
| |
| if (!type_match) |
| { |
| if (code == STRING_CST) |
| { |
| /* Reject invalid format strings with an error. */ |
| if (argno < 1) |
| error ("%qE attribute argument value %qE refers to " |
| "parameter type %qT", |
| atname, pos, argtype); |
| else |
| error ("%qE attribute argument %i value %qE refers to " |
| "parameter type %qT", |
| atname, argno, pos, argtype); |
| |
| return NULL_TREE; |
| } |
| |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument value %qE refers to " |
| "parameter type %qT", |
| atname, pos, argtype); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i value %qE refers to " |
| "parameter type %qT", |
| atname, argno, pos, argtype); |
| return NULL_TREE; |
| } |
| } |
| else if (!(flags & POSARG_ELLIPSIS)) |
| { |
| if (argno < 1) |
| warning (OPT_Wattributes, |
| "%qE attribute argument value %qE refers to " |
| "a variadic function parameter of unknown type", |
| atname, pos); |
| else |
| warning (OPT_Wattributes, |
| "%qE attribute argument %i value %qE refers to " |
| "a variadic function parameter of unknown type", |
| atname, argno, pos); |
| return NULL_TREE; |
| } |
| |
| return pos; |
| } |
| |
| /* 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. */ |
| |
| static tree |
| decl_or_type_attrs (tree node) |
| { |
| if (DECL_P (node)) |
| { |
| if (tree attrs = DECL_ATTRIBUTES (node)) |
| return attrs; |
| |
| tree type = TREE_TYPE (node); |
| if (type == error_mark_node) |
| return NULL_TREE; |
| return TYPE_ATTRIBUTES (type); |
| } |
| |
| if (TYPE_P (node)) |
| return TYPE_ATTRIBUTES (node); |
| |
| return NULL_TREE; |
| } |
| |
| /* 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. */ |
| |
| static bool |
| validate_attr_args (tree node[2], tree name, tree newargs[2]) |
| { |
| /* First validate the arguments against those already applied to |
| the same declaration (or type). */ |
| tree self[2] = { node[0], node[0] }; |
| if (node[0] != node[1] && !validate_attr_args (self, name, newargs)) |
| return false; |
| |
| if (!node[1]) |
| return true; |
| |
| /* Extract the same attribute from the previous declaration or type. */ |
| tree prevattr = decl_or_type_attrs (node[1]); |
| const char* const namestr = IDENTIFIER_POINTER (name); |
| prevattr = lookup_attribute (namestr, prevattr); |
| if (!prevattr) |
| return true; |
| |
| /* Extract one or both attribute arguments. */ |
| tree prevargs[2]; |
| prevargs[0] = TREE_VALUE (TREE_VALUE (prevattr)); |
| prevargs[1] = TREE_CHAIN (TREE_VALUE (prevattr)); |
| if (prevargs[1]) |
| prevargs[1] = TREE_VALUE (prevargs[1]); |
| |
| /* Both arguments must be equal or, for the second pair, neither must |
| be provided to succeed. */ |
| bool arg1eq, arg2eq; |
| if (TREE_CODE (newargs[0]) == INTEGER_CST) |
| { |
| arg1eq = tree_int_cst_equal (newargs[0], prevargs[0]); |
| if (newargs[1] && prevargs[1]) |
| arg2eq = tree_int_cst_equal (newargs[1], prevargs[1]); |
| else |
| arg2eq = newargs[1] == prevargs[1]; |
| } |
| else if (TREE_CODE (newargs[0]) == STRING_CST) |
| { |
| const char *s0 = TREE_STRING_POINTER (newargs[0]); |
| const char *s1 = TREE_STRING_POINTER (prevargs[0]); |
| arg1eq = strcmp (s0, s1) == 0; |
| if (newargs[1] && prevargs[1]) |
| { |
| s0 = TREE_STRING_POINTER (newargs[1]); |
| s1 = TREE_STRING_POINTER (prevargs[1]); |
| arg2eq = strcmp (s0, s1) == 0; |
| } |
| else |
| arg2eq = newargs[1] == prevargs[1]; |
| } |
| else |
| gcc_unreachable (); |
| |
| if (arg1eq && arg2eq) |
| return true; |
| |
| /* If the two locations are different print a note pointing to |
| the previous one. */ |
| const location_t curloc = input_location; |
| const location_t prevloc = |
| DECL_P (node[1]) ? DECL_SOURCE_LOCATION (node[1]) : curloc; |
| |
| /* Format the attribute specification for convenience. */ |
| char newspec[80], prevspec[80]; |
| if (newargs[1]) |
| snprintf (newspec, sizeof newspec, "%s (%s, %s)", namestr, |
| print_generic_expr_to_str (newargs[0]), |
| print_generic_expr_to_str (newargs[1])); |
| else |
| snprintf (newspec, sizeof newspec, "%s (%s)", namestr, |
| print_generic_expr_to_str (newargs[0])); |
| |
| if (prevargs[1]) |
| snprintf (prevspec, sizeof prevspec, "%s (%s, %s)", namestr, |
| print_generic_expr_to_str (prevargs[0]), |
| print_generic_expr_to_str (prevargs[1])); |
| else |
| snprintf (prevspec, sizeof prevspec, "%s (%s)", namestr, |
| print_generic_expr_to_str (prevargs[0])); |
| |
| if (warning_at (curloc, OPT_Wattributes, |
| "ignoring attribute %qs because it conflicts " |
| "with previous %qs", |
| newspec, prevspec) |
| && curloc != prevloc) |
| inform (prevloc, "previous declaration here"); |
| |
| return false; |
| } |
| |
| /* Convenience wrapper for validate_attr_args to validate a single |
| attribute argument. Used by handlers for attributes that take |
| just a single argument. */ |
| |
| static bool |
| validate_attr_arg (tree node[2], tree name, tree newarg) |
| { |
| tree argarray[2] = { newarg, NULL_TREE }; |
| return validate_attr_args (node, name, argarray); |
| } |
| |
| /* Attribute handlers common to C front ends. */ |
| |
| /* Handle a "signed_bool_precision" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_signed_bool_precision_attribute (tree *node, tree name, tree args, |
| int, bool *no_add_attrs) |
| { |
| *no_add_attrs = true; |
| if (!flag_gimple) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| return NULL_TREE; |
| } |
| |
| if (!TYPE_P (*node) || TREE_CODE (*node) != BOOLEAN_TYPE) |
| { |
| warning (OPT_Wattributes, "%qE attribute only supported on " |
| "boolean types", name); |
| return NULL_TREE; |
| } |
| |
| unsigned HOST_WIDE_INT prec = HOST_WIDE_INT_M1U; |
| if (tree_fits_uhwi_p (TREE_VALUE (args))) |
| prec = tree_to_uhwi (TREE_VALUE (args)); |
| if (prec > MAX_FIXED_MODE_SIZE) |
| { |
| warning (OPT_Wattributes, "%qE attribute with unsupported boolean " |
| "precision", name); |
| return NULL_TREE; |
| } |
| |
| tree new_type = build_nonstandard_boolean_type (prec); |
| *node = lang_hooks.types.reconstruct_complex_type (*node, new_type); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "packed" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int flags, bool *no_add_attrs) |
| { |
| if (TYPE_P (*node)) |
| { |
| if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
| { |
| warning (OPT_Wattributes, |
| "%qE attribute ignored for type %qT", name, *node); |
| *no_add_attrs = true; |
| } |
| else |
| TYPE_PACKED (*node) = 1; |
| } |
| else if (TREE_CODE (*node) == FIELD_DECL) |
| { |
| if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT |
| /* Still pack bitfields. */ |
| && ! DECL_C_BIT_FIELD (*node)) |
| warning (OPT_Wattributes, |
| "%qE attribute ignored for field of type %qT", |
| name, TREE_TYPE (*node)); |
| else |
| DECL_PACKED (*node) = 1; |
| } |
| /* We can't set DECL_PACKED for a VAR_DECL, because the bit is |
| used for DECL_REGISTER. It wouldn't mean anything anyway. |
| We can't set DECL_PACKED on the type of a TYPE_DECL, because |
| that changes what the typedef is typing. */ |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "nocommon" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_nocommon_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (VAR_P (*node)) |
| DECL_COMMON (*node) = 0; |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "common" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_common_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (VAR_P (*node)) |
| DECL_COMMON (*node) = 1; |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "noreturn" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| tree |
| handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree type = TREE_TYPE (*node); |
| |
| /* See FIXME comment in c_common_attribute_table. */ |
| if (TREE_CODE (*node) == FUNCTION_DECL |
| || objc_method_decl (TREE_CODE (*node))) |
| TREE_THIS_VOLATILE (*node) = 1; |
| else if (TREE_CODE (type) == POINTER_TYPE |
| && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) |
| TREE_TYPE (*node) |
| = (build_qualified_type |
| (build_pointer_type |
| (build_type_variant (TREE_TYPE (type), |
| TYPE_READONLY (TREE_TYPE (type)), 1)), |
| TYPE_QUALS (type))); |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "hot" and attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_hot_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL |
| || TREE_CODE (*node) == LABEL_DECL) |
| { |
| /* Attribute hot processing is done later with lookup_attribute. */ |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "cold" and attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_cold_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL |
| || TREE_CODE (*node) == LABEL_DECL) |
| { |
| /* Attribute cold processing is done later with lookup_attribute. */ |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Add FLAGS for a function NODE to no_sanitize_flags in DECL_ATTRIBUTES. */ |
| |
| void |
| add_no_sanitize_value (tree node, unsigned int flags) |
| { |
| tree attr = lookup_attribute ("no_sanitize", DECL_ATTRIBUTES (node)); |
| if (attr) |
| { |
| unsigned int old_value = tree_to_uhwi (TREE_VALUE (attr)); |
| flags |= old_value; |
| |
| if (flags == old_value) |
| return; |
| |
| TREE_VALUE (attr) = build_int_cst (unsigned_type_node, flags); |
| } |
| else |
| DECL_ATTRIBUTES (node) |
| = tree_cons (get_identifier ("no_sanitize"), |
| build_int_cst (unsigned_type_node, flags), |
| DECL_ATTRIBUTES (node)); |
| } |
| |
| /* Handle a "no_sanitize" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_sanitize_attribute (tree *node, tree name, tree args, int, |
| bool *no_add_attrs) |
| { |
| unsigned int flags = 0; |
| *no_add_attrs = true; |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| return NULL_TREE; |
| } |
| |
| for (; args; args = TREE_CHAIN (args)) |
| { |
| tree id = TREE_VALUE (args); |
| if (TREE_CODE (id) != STRING_CST) |
| { |
| error ("%qE argument not a string", name); |
| return NULL_TREE; |
| } |
| |
| char *string = ASTRDUP (TREE_STRING_POINTER (id)); |
| flags |= parse_no_sanitize_attribute (string); |
| } |
| |
| add_no_sanitize_value (*node, flags); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_sanitize_address" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_sanitize_address_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| *no_add_attrs = true; |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| else |
| add_no_sanitize_value (*node, SANITIZE_ADDRESS); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_sanitize_thread" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_sanitize_thread_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| *no_add_attrs = true; |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| else |
| add_no_sanitize_value (*node, SANITIZE_THREAD); |
| |
| return NULL_TREE; |
| } |
| |
| |
| /* Handle a "no_address_safety_analysis" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| *no_add_attrs = true; |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| else |
| add_no_sanitize_value (*node, SANITIZE_ADDRESS); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_sanitize_undefined" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_sanitize_undefined_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| *no_add_attrs = true; |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| else |
| add_no_sanitize_value (*node, |
| SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_sanitize_coverage" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_sanitize_coverage_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle an "asan odr indicator" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_asan_odr_indicator_attribute (tree *, tree, tree, int, bool *) |
| { |
| return NULL_TREE; |
| } |
| |
| /* Handle a "stack_protect" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_stack_protect_attribute (tree *node, tree name, tree, int, |
| bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_stack_protector" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_stack_protector_function_attribute (tree *node, tree name, tree, |
| int, bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "noipa" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_noipa_attribute (tree *node, tree name, tree, int, bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "noinline" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_noinline_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL) |
| { |
| if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (*node))) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored due to conflict " |
| "with attribute %qs", name, "always_inline"); |
| *no_add_attrs = true; |
| } |
| else |
| DECL_UNINLINABLE (*node) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "noclone" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_noclone_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "nocf_check" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_nocf_check_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_TYPE |
| && TREE_CODE (*node) != METHOD_TYPE) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| else if (!(flag_cf_protection & CF_BRANCH)) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored. Use " |
| "%<-fcf-protection%> option to enable it", |
| name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "no_icf" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_noicf_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| |
| /* Handle a "always_inline" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_always_inline_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL) |
| { |
| if (lookup_attribute ("noinline", DECL_ATTRIBUTES (*node))) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored due to conflict " |
| "with %qs attribute", name, "noinline"); |
| *no_add_attrs = true; |
| } |
| else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node))) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored due to conflict " |
| "with %qs attribute", name, "target_clones"); |
| *no_add_attrs = true; |
| } |
| else |
| /* Set the attribute and mark it for disregarding inline |
| limits. */ |
| DECL_DISREGARD_INLINE_LIMITS (*node) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "gnu_inline" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_gnu_inline_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node)) |
| { |
| /* Do nothing else, just set the attribute. We'll get at |
| it later with lookup_attribute. */ |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "leaf" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_leaf_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| if (!TREE_PUBLIC (*node)) |
| { |
| warning (OPT_Wattributes, "%qE attribute has no effect on unit local " |
| "functions", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle an "artificial" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_artificial_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (*node)) |
| { |
| /* Do nothing else, just set the attribute. We'll get at |
| it later with lookup_attribute. */ |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "flatten" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_flatten_attribute (tree *node, tree name, |
| tree args ATTRIBUTE_UNUSED, |
| int flags ATTRIBUTE_UNUSED, bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL) |
| /* Do nothing else, just set the attribute. We'll get at |
| it later with lookup_attribute. */ |
| ; |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "warning" or "error" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_error_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL |
| && TREE_CODE (TREE_VALUE (args)) == STRING_CST) |
| /* Do nothing else, just set the attribute. We'll get at |
| it later with lookup_attribute. */ |
| ; |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "used" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree node = *pnode; |
| |
| if (TREE_CODE (node) == FUNCTION_DECL |
| || (VAR_P (node) && TREE_STATIC (node)) |
| || (TREE_CODE (node) == TYPE_DECL)) |
| { |
| TREE_USED (node) = 1; |
| DECL_PRESERVE_P (node) = 1; |
| if (VAR_P (node)) |
| DECL_READ_P (node) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "unused" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| tree |
| handle_unused_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int flags, bool *no_add_attrs) |
| { |
| if (DECL_P (*node)) |
| { |
| tree decl = *node; |
| |
| if (TREE_CODE (decl) == PARM_DECL |
| || VAR_OR_FUNCTION_DECL_P (decl) |
| || TREE_CODE (decl) == LABEL_DECL |
| || TREE_CODE (decl) == CONST_DECL |
| || TREE_CODE (decl) == FIELD_DECL |
| || TREE_CODE (decl) == TYPE_DECL) |
| { |
| TREE_USED (decl) = 1; |
| if (VAR_P (decl) || TREE_CODE (decl) == PARM_DECL) |
| DECL_READ_P (decl) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| } |
| else |
| { |
| if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
| *node = build_variant_type_copy (*node); |
| TREE_USED (*node) = 1; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "retain" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_retain_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree node = *pnode; |
| |
| if (SUPPORTS_SHF_GNU_RETAIN |
| && (TREE_CODE (node) == FUNCTION_DECL |
| || (VAR_P (node) && TREE_STATIC (node)))) |
| ; |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle an "uninitialized" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_uninitialized_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree decl = *node; |
| if (!VAR_P (decl)) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored because %qD " |
| "is not a variable", name, decl); |
| *no_add_attrs = true; |
| } |
| else if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored because %qD " |
| "is not a local variable", name, decl); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "externally_visible" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_externally_visible_attribute (tree *pnode, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| tree node = *pnode; |
| |
| if (VAR_OR_FUNCTION_DECL_P (node)) |
| { |
| if ((!TREE_STATIC (node) && TREE_CODE (node) != FUNCTION_DECL |
| && !DECL_EXTERNAL (node)) || !TREE_PUBLIC (node)) |
| { |
| warning (OPT_Wattributes, |
| "%qE attribute have effect only on public objects", name); |
| *no_add_attrs = true; |
| } |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle the "no_reorder" attribute. Arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_no_reorder_attribute (tree *pnode, |
| tree name, |
| tree, |
| int, |
| bool *no_add_attrs) |
| { |
| tree node = *pnode; |
| |
| if (!VAR_OR_FUNCTION_DECL_P (node) |
| && !(TREE_STATIC (node) || DECL_EXTERNAL (node))) |
| { |
| warning (OPT_Wattributes, |
| "%qE attribute only affects top level objects", |
| name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "const" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args), |
| int flags, bool *no_add_attrs) |
| { |
| tree type = TREE_TYPE (*node); |
| |
| /* See FIXME comment on noreturn in c_common_attribute_table. */ |
| if (TREE_CODE (*node) == FUNCTION_DECL) |
| TREE_READONLY (*node) = 1; |
| else if (TREE_CODE (type) == POINTER_TYPE |
| && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) |
| TREE_TYPE (*node) |
| = (build_qualified_type |
| (build_pointer_type |
| (build_type_variant (TREE_TYPE (type), 1, |
| TREE_THIS_VOLATILE (TREE_TYPE (type)))), |
| TYPE_QUALS (type))); |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| /* void __builtin_unreachable(void) is const. Accept other such |
| built-ins but warn on user-defined functions that return void. */ |
| if (!(flags & ATTR_FLAG_BUILT_IN) |
| && TREE_CODE (*node) == FUNCTION_DECL |
| && VOID_TYPE_P (TREE_TYPE (type))) |
| warning (OPT_Wattributes, "%qE attribute on function " |
| "returning %<void%>", name); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "scalar_storage_order" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_scalar_storage_order_attribute (tree *node, tree name, tree args, |
| int flags, bool *no_add_attrs) |
| { |
| tree id = TREE_VALUE (args); |
| tree type; |
| |
| if (TREE_CODE (*node) == TYPE_DECL |
| && ! (flags & ATTR_FLAG_CXX11)) |
| node = &TREE_TYPE (*node); |
| type = *node; |
| |
| if (BYTES_BIG_ENDIAN != WORDS_BIG_ENDIAN) |
| { |
| error ("%qE attribute is not supported because endianness is not uniform", |
| name); |
| return NULL_TREE; |
| } |
| |
| if (RECORD_OR_UNION_TYPE_P (type) && !c_dialect_cxx ()) |
| { |
| bool reverse = false; |
| |
| if (TREE_CODE (id) == STRING_CST |
| && strcmp (TREE_STRING_POINTER (id), "big-endian") == 0) |
| reverse = !BYTES_BIG_ENDIAN; |
| else if (TREE_CODE (id) == STRING_CST |
| && strcmp (TREE_STRING_POINTER (id), "little-endian") == 0) |
| reverse = BYTES_BIG_ENDIAN; |
| else |
| { |
| error ("attribute %qE argument must be one of %qs or %qs", |
| name, "big-endian", "little-endian"); |
| return NULL_TREE; |
| } |
| |
| if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
| { |
| if (reverse) |
| /* A type variant isn't good enough, since we don't want a cast |
| to such a type to be removed as a no-op. */ |
| *node = type = build_duplicate_type (type); |
| } |
| |
| TYPE_REVERSE_STORAGE_ORDER (type) = reverse; |
| return NULL_TREE; |
| } |
| |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| /* Handle a "transparent_union" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_transparent_union_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), int flags, |
| bool *no_add_attrs) |
| { |
| tree type; |
| |
| *no_add_attrs = true; |
| |
| if (TREE_CODE (*node) == TYPE_DECL |
| && ! (flags & ATTR_FLAG_CXX11)) |
| node = &TREE_TYPE (*node); |
| type = *node; |
| |
| if (TREE_CODE (type) == UNION_TYPE) |
| { |
| /* Make sure that the first field will work for a transparent union. |
| If the type isn't complete yet, leave the check to the code in |
| finish_struct. */ |
| if (TYPE_SIZE (type)) |
| { |
| tree first = first_field (type); |
| if (first == NULL_TREE |
| || DECL_ARTIFICIAL (first) |
| || TYPE_MODE (type) != DECL_MODE (first)) |
| goto ignored; |
| } |
| |
| if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
| { |
| /* If the type isn't complete yet, setting the flag |
| on a variant wouldn't ever be checked. */ |
| if (!TYPE_SIZE (type)) |
| goto ignored; |
| |
| /* build_duplicate_type doesn't work for C++. */ |
| if (c_dialect_cxx ()) |
| goto ignored; |
| |
| /* A type variant isn't good enough, since we don't want a cast |
| to such a type to be removed as a no-op. */ |
| *node = type = build_duplicate_type (type); |
| } |
| |
| for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
| TYPE_TRANSPARENT_AGGR (t) = 1; |
| return NULL_TREE; |
| } |
| |
| ignored: |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| return NULL_TREE; |
| } |
| |
| /* Subroutine of handle_{con,de}structor_attribute. Evaluate ARGS to |
| get the requested priority for a constructor or destructor, |
| possibly issuing diagnostics for invalid or reserved |
| priorities. */ |
| |
| static priority_type |
| get_priority (tree args, bool is_destructor) |
| { |
| HOST_WIDE_INT pri; |
| tree arg; |
| |
| if (!args) |
| return DEFAULT_INIT_PRIORITY; |
| |
| if (!SUPPORTS_INIT_PRIORITY) |
| { |
| if (is_destructor) |
| error ("destructor priorities are not supported"); |
| else |
| error ("constructor priorities are not supported"); |
| return DEFAULT_INIT_PRIORITY; |
| } |
| |
| arg = TREE_VALUE (args); |
| if (TREE_CODE (arg) == IDENTIFIER_NODE) |
| goto invalid; |
| if (arg == error_mark_node) |
| return DEFAULT_INIT_PRIORITY; |
| arg = default_conversion (arg); |
| if (!tree_fits_shwi_p (arg) |
| || !INTEGRAL_TYPE_P (TREE_TYPE (arg))) |
| goto invalid; |
| |
| pri = tree_to_shwi (arg); |
| if (pri < 0 || pri > MAX_INIT_PRIORITY) |
| goto invalid; |
| |
| if (pri <= MAX_RESERVED_INIT_PRIORITY) |
| { |
| if (is_destructor) |
| warning (OPT_Wprio_ctor_dtor, |
| "destructor priorities from 0 to %d are reserved " |
| "for the implementation", |
| MAX_RESERVED_INIT_PRIORITY); |
| else |
| warning (OPT_Wprio_ctor_dtor, |
| "constructor priorities from 0 to %d are reserved " |
| "for the implementation", |
| MAX_RESERVED_INIT_PRIORITY); |
| } |
| return pri; |
| |
| invalid: |
| if (is_destructor) |
| error ("destructor priorities must be integers from 0 to %d inclusive", |
| MAX_INIT_PRIORITY); |
| else |
| error ("constructor priorities must be integers from 0 to %d inclusive", |
| MAX_INIT_PRIORITY); |
| return DEFAULT_INIT_PRIORITY; |
| } |
| |
| /* Handle a "constructor" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_constructor_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| tree decl = *node; |
| tree type = TREE_TYPE (decl); |
| |
| if (TREE_CODE (decl) == FUNCTION_DECL |
| && TREE_CODE (type) == FUNCTION_TYPE |
| && decl_function_context (decl) == 0) |
| { |
| priority_type priority; |
| DECL_STATIC_CONSTRUCTOR (decl) = 1; |
| priority = get_priority (args, /*is_destructor=*/false); |
| SET_DECL_INIT_PRIORITY (decl, priority); |
| TREE_USED (decl) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "destructor" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_destructor_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), |
| bool *no_add_attrs) |
| { |
| tree decl = *node; |
| tree type = TREE_TYPE (decl); |
| |
| if (TREE_CODE (decl) == FUNCTION_DECL |
| && TREE_CODE (type) == FUNCTION_TYPE |
| && decl_function_context (decl) == 0) |
| { |
| priority_type priority; |
| DECL_STATIC_DESTRUCTOR (decl) = 1; |
| priority = get_priority (args, /*is_destructor=*/true); |
| SET_DECL_FINI_PRIORITY (decl, priority); |
| TREE_USED (decl) = 1; |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Nonzero if the mode is a valid vector mode for this architecture. |
| This returns nonzero even if there is no hardware support for the |
| vector mode, but we can emulate with narrower modes. */ |
| |
| static bool |
| vector_mode_valid_p (machine_mode mode) |
| { |
| enum mode_class mclass = GET_MODE_CLASS (mode); |
| |
| /* Doh! What's going on? */ |
| if (mclass != MODE_VECTOR_INT |
| && mclass != MODE_VECTOR_FLOAT |
| && mclass != MODE_VECTOR_FRACT |
| && mclass != MODE_VECTOR_UFRACT |
| && mclass != MODE_VECTOR_ACCUM |
| && mclass != MODE_VECTOR_UACCUM) |
| return false; |
| |
| /* Hardware support. Woo hoo! */ |
| if (targetm.vector_mode_supported_p (mode)) |
| return true; |
| |
| /* We should probably return 1 if requesting V4DI and we have no DI, |
| but we have V2DI, but this is probably very unlikely. */ |
| |
| /* If we have support for the inner mode, we can safely emulate it. |
| We may not have V2DI, but me can emulate with a pair of DIs. */ |
| return targetm.scalar_mode_supported_p (GET_MODE_INNER (mode)); |
| } |
| |
| |
| /* Handle a "mode" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_mode_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree type = *node; |
| tree ident = TREE_VALUE (args); |
| |
| *no_add_attrs = true; |
| |
| if (TREE_CODE (ident) != IDENTIFIER_NODE) |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| else |
| { |
| int j; |
| const char *p = IDENTIFIER_POINTER (ident); |
| int len = strlen (p); |
| machine_mode mode = VOIDmode; |
| tree typefm; |
| bool valid_mode; |
| |
| if (len > 4 && p[0] == '_' && p[1] == '_' |
| && p[len - 1] == '_' && p[len - 2] == '_') |
| { |
| char *newp = (char *) alloca (len - 1); |
| |
| strcpy (newp, &p[2]); |
| newp[len - 4] = '\0'; |
| p = newp; |
| } |
| |
| /* Change this type to have a type with the specified mode. |
| First check for the special modes. */ |
| if (!strcmp (p, "byte")) |
| mode = byte_mode; |
| else if (!strcmp (p, "word")) |
| mode = word_mode; |
| else if (!strcmp (p, "pointer")) |
| mode = ptr_mode; |
| else if (!strcmp (p, "libgcc_cmp_return")) |
| mode = targetm.libgcc_cmp_return_mode (); |
| else if (!strcmp (p, "libgcc_shift_count")) |
| mode = targetm.libgcc_shift_count_mode (); |
| else if (!strcmp (p, "unwind_word")) |
| mode = targetm.unwind_word_mode (); |
| else |
| for (j = 0; j < NUM_MACHINE_MODES; j++) |
| if (!strcmp (p, GET_MODE_NAME (j))) |
| { |
| mode = (machine_mode) j; |
| break; |
| } |
| |
| if (mode == VOIDmode) |
| { |
| error ("unknown machine mode %qE", ident); |
| return NULL_TREE; |
| } |
| |
| /* Allow the target a chance to translate MODE into something supported. |
| See PR86324. */ |
| mode = targetm.translate_mode_attribute (mode); |
| |
| valid_mode = false; |
| switch (GET_MODE_CLASS (mode)) |
| { |
| case MODE_INT: |
| case MODE_PARTIAL_INT: |
| case MODE_FLOAT: |
| case MODE_DECIMAL_FLOAT: |
| case MODE_FRACT: |
| case MODE_UFRACT: |
| case MODE_ACCUM: |
| case MODE_UACCUM: |
| valid_mode |
| = targetm.scalar_mode_supported_p (as_a <scalar_mode> (mode)); |
| break; |
| |
| case MODE_COMPLEX_INT: |
| case MODE_COMPLEX_FLOAT: |
| valid_mode = targetm.scalar_mode_supported_p (GET_MODE_INNER (mode)); |
| break; |
| |
| case MODE_VECTOR_INT: |
| case MODE_VECTOR_FLOAT: |
| case MODE_VECTOR_FRACT: |
| case MODE_VECTOR_UFRACT: |
| case MODE_VECTOR_ACCUM: |
| case MODE_VECTOR_UACCUM: |
| warning (OPT_Wattributes, "specifying vector types with " |
| "%<__attribute__ ((mode))%> is deprecated"); |
| inform (input_location, |
| "use %<__attribute__ ((vector_size))%> instead"); |
| valid_mode = vector_mode_valid_p (mode); |
| break; |
| |
| default: |
| break; |
| } |
| if (!valid_mode) |
| { |
| error ("unable to emulate %qs", p); |
| return NULL_TREE; |
| } |
| |
| if (POINTER_TYPE_P (type)) |
| { |
| scalar_int_mode addr_mode; |
| addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type)); |
| tree (*fn)(tree, machine_mode, bool); |
| |
| if (!is_a <scalar_int_mode> (mode, &addr_mode) |
| || !targetm.addr_space.valid_pointer_mode (addr_mode, as)) |
| { |
| error ("invalid pointer mode %qs", p); |
| return NULL_TREE; |
| } |
| |
| if (TREE_CODE (type) == POINTER_TYPE) |
| fn = build_pointer_type_for_mode; |
| else |
| fn = build_reference_type_for_mode; |
| typefm = fn (TREE_TYPE (type), addr_mode, false); |
| } |
| else |
| { |
| /* For fixed-point modes, we need to test if the signness of type |
| and the machine mode are consistent. */ |
| if (ALL_FIXED_POINT_MODE_P (mode) |
| && TYPE_UNSIGNED (type) != UNSIGNED_FIXED_POINT_MODE_P (mode)) |
| { |
| error ("signedness of type and machine mode %qs don%'t match", p); |
| return NULL_TREE; |
| } |
| /* For fixed-point modes, we need to pass saturating info. */ |
| typefm = lang_hooks.types.type_for_mode (mode, |
| ALL_FIXED_POINT_MODE_P (mode) ? TYPE_SATURATING (type) |
| : TYPE_UNSIGNED (type)); |
| } |
| |
| if (typefm == NULL_TREE) |
| { |
| error ("no data type for mode %qs", p); |
| return NULL_TREE; |
| } |
| else if (TREE_CODE (type) == ENUMERAL_TYPE) |
| { |
| /* For enumeral types, copy the precision from the integer |
| type returned above. If not an INTEGER_TYPE, we can't use |
| this mode for this type. */ |
| if (TREE_CODE (typefm) != INTEGER_TYPE) |
| { |
| error ("cannot use mode %qs for enumerated types", p); |
| return NULL_TREE; |
| } |
| |
| if (flags & ATTR_FLAG_TYPE_IN_PLACE) |
| { |
| TYPE_PRECISION (type) = TYPE_PRECISION (typefm); |
| typefm = type; |
| } |
| else |
| { |
| /* We cannot build a type variant, as there's code that assumes |
| that TYPE_MAIN_VARIANT has the same mode. This includes the |
| debug generators. Instead, create a subrange type. This |
| results in all of the enumeral values being emitted only once |
| in the original, and the subtype gets them by reference. */ |
| if (TYPE_UNSIGNED (type)) |
| typefm = make_unsigned_type (TYPE_PRECISION (typefm)); |
| else |
| typefm = make_signed_type (TYPE_PRECISION (typefm)); |
| TREE_TYPE (typefm) = type; |
| } |
| *no_add_attrs = false; |
| } |
| else if (VECTOR_MODE_P (mode) |
| ? TREE_CODE (type) != TREE_CODE (TREE_TYPE (typefm)) |
| : TREE_CODE (type) != TREE_CODE (typefm)) |
| { |
| error ("mode %qs applied to inappropriate type", p); |
| return NULL_TREE; |
| } |
| |
| *node = build_qualified_type (typefm, TYPE_QUALS (type)); |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "section" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_section_attribute (tree *node, tree name, tree args, |
| int flags, bool *no_add_attrs) |
| { |
| tree decl = *node; |
| tree res = NULL_TREE; |
| tree argval = TREE_VALUE (args); |
| const char* new_section_name; |
| |
| if (!targetm_common.have_named_sections) |
| { |
| error_at (DECL_SOURCE_LOCATION (*node), |
| "section attributes are not supported for this target"); |
| goto fail; |
| } |
| |
| if (!VAR_OR_FUNCTION_DECL_P (decl)) |
| { |
| error ("section attribute not allowed for %q+D", *node); |
| goto fail; |
| } |
| |
| if (TREE_CODE (argval) != STRING_CST) |
| { |
| error ("section attribute argument not a string constant"); |
| goto fail; |
| } |
| |
| if (VAR_P (decl) |
| && current_function_decl != NULL_TREE |
| && !TREE_STATIC (decl)) |
| { |
| error_at (DECL_SOURCE_LOCATION (decl), |
| "section attribute cannot be specified for local variables"); |
| goto fail; |
| } |
| |
| new_section_name = TREE_STRING_POINTER (argval); |
| |
| /* The decl may have already been given a section attribute |
| from a previous declaration. Ensure they match. */ |
| if (const char* const old_section_name = DECL_SECTION_NAME (decl)) |
| if (strcmp (old_section_name, new_section_name) != 0) |
| { |
| error ("section of %q+D conflicts with previous declaration", |
| *node); |
| goto fail; |
| } |
| |
| if (VAR_P (decl) |
| && !targetm.have_tls && targetm.emutls.tmpl_section |
| && DECL_THREAD_LOCAL_P (decl)) |
| { |
| error ("section of %q+D cannot be overridden", *node); |
| goto fail; |
| } |
| |
| if (!validate_attr_arg (node, name, argval)) |
| goto fail; |
| |
| res = targetm.handle_generic_attribute (node, name, args, flags, |
| no_add_attrs); |
| |
| /* If the back end confirms the attribute can be added then continue onto |
| final processing. */ |
| if (!(*no_add_attrs)) |
| { |
| set_decl_section_name (decl, new_section_name); |
| return res; |
| } |
| |
| fail: |
| *no_add_attrs = true; |
| return res; |
| } |
| |
| /* Common codes shared by handle_warn_if_not_aligned_attribute and |
| handle_aligned_attribute. */ |
| |
| static tree |
| common_handle_aligned_attribute (tree *node, tree name, tree args, int flags, |
| bool *no_add_attrs, |
| bool warn_if_not_aligned_p) |
| { |
| tree decl = NULL_TREE; |
| tree *type = NULL; |
| bool is_type = false; |
| tree align_expr; |
| |
| /* The last (already pushed) declaration with all validated attributes |
| merged in or the current about-to-be-pushed one if one hasn't been |
| yet. */ |
| tree last_decl = node[1] ? node[1] : *node; |
| |
| if (args) |
| { |
| align_expr = TREE_VALUE (args); |
| if (align_expr && TREE_CODE (align_expr) != IDENTIFIER_NODE |
| && TREE_CODE (align_expr) != FUNCTION_DECL) |
| align_expr = default_conversion (align_expr); |
| } |
| else |
| align_expr = size_int (ATTRIBUTE_ALIGNED_VALUE / BITS_PER_UNIT); |
| |
| if (DECL_P (*node)) |
| { |
| decl = *node; |
| type = &TREE_TYPE (decl); |
| is_type = TREE_CODE (*node) == TYPE_DECL; |
| } |
| else if (TYPE_P (*node)) |
| type = node, is_type = true; |
| |
| /* True to consider invalid alignments greater than MAX_OFILE_ALIGNMENT. */ |
| bool objfile = (TREE_CODE (*node) == FUNCTION_DECL |
| || (VAR_P (*node) && TREE_STATIC (*node))); |
| /* Log2 of specified alignment. */ |
| int pow2align = check_user_alignment (align_expr, objfile, |
| /* warn_zero = */ true); |
| if (pow2align == -1) |
| { |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| /* The alignment in bits corresponding to the specified alignment. */ |
| unsigned bitalign = (1U << pow2align) * BITS_PER_UNIT; |
| |
| /* The alignment of the current declaration and that of the last |
| pushed declaration, determined on demand below. */ |
| unsigned curalign = 0; |
| unsigned lastalign = 0; |
| |
| /* True when SET_DECL_ALIGN() should be called for the decl when |
| *NO_ADD_ATTRS is false. */ |
| bool set_align = true; |
| if (is_type) |
| { |
| if ((flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
| /* OK, modify the type in place. */; |
| /* If we have a TYPE_DECL, then copy the type, so that we |
| don't accidentally modify a builtin type. See pushdecl. */ |
| else if (decl && TREE_TYPE (decl) != error_mark_node |
| && DECL_ORIGINAL_TYPE (decl) == NULL_TREE) |
| { |
| tree tt = TREE_TYPE (decl); |
| *type = build_variant_type_copy (*type); |
| DECL_ORIGINAL_TYPE (decl) = tt; |
| TYPE_NAME (*type) = decl; |
| TREE_USED (*type) = TREE_USED (decl); |
| TREE_TYPE (decl) = *type; |
| } |
| else |
| *type = build_variant_type_copy (*type); |
| |
| if (warn_if_not_aligned_p) |
| { |
| SET_TYPE_WARN_IF_NOT_ALIGN (*type, bitalign); |
| warn_if_not_aligned_p = false; |
| } |
| else |
| { |
| SET_TYPE_ALIGN (*type, bitalign); |
| TYPE_USER_ALIGN (*type) = 1; |
| } |
| } |
| else if (! VAR_OR_FUNCTION_DECL_P (decl) |
| && TREE_CODE (decl) != FIELD_DECL) |
| { |
| error ("alignment may not be specified for %q+D", decl); |
| *no_add_attrs = true; |
| } |
| else if (TREE_CODE (decl) == FUNCTION_DECL |
| && (((curalign = DECL_ALIGN (decl)) > bitalign) |
| | ((lastalign = DECL_ALIGN (last_decl)) > bitalign))) |
| { |
| /* Either a prior attribute on the same declaration or one |
| on a prior declaration of the same function specifies |
| stricter alignment than this attribute. */ |
| bool note = (lastalign > curalign |
| || (lastalign == curalign |
| && (DECL_USER_ALIGN (last_decl) |
| > DECL_USER_ALIGN (decl)))); |
| if (note) |
| curalign = lastalign; |
| |
| curalign /= BITS_PER_UNIT; |
| unsigned newalign = bitalign / BITS_PER_UNIT; |
| |
| auto_diagnostic_group d; |
| if ((DECL_USER_ALIGN (decl) |
| || DECL_USER_ALIGN (last_decl))) |
| { |
| if (warning (OPT_Wattributes, |
| "ignoring attribute %<%E (%u)%> because it conflicts " |
| "with attribute %<%E (%u)%>", |
| name, newalign, name, curalign) |
| && note) |
| inform (DECL_SOURCE_LOCATION (last_decl), |
| "previous declaration here"); |
| /* Only reject attempts to relax/override an alignment |
| explicitly specified previously and accept declarations |
| that appear to relax the implicit function alignment for |
| the target. Both increasing and increasing the alignment |
| set by -falign-functions setting is permitted. */ |
| *no_add_attrs = true; |
| } |
| else if (!warn_if_not_aligned_p) |
| { |
| /* Do not fail for attribute warn_if_not_aligned. Otherwise, |
| silently avoid applying the alignment to the declaration |
| because it's implicitly satisfied by the target. Apply |
| the attribute nevertheless so it can be retrieved by |
| __builtin_has_attribute. */ |
| set_align = false; |
| } |
| } |
| else if (DECL_USER_ALIGN (decl) |
| && DECL_ALIGN (decl) > bitalign) |
| /* C++-11 [dcl.align/4]: |
| |
| When multiple alignment-specifiers are specified for an |
| entity, the alignment requirement shall be set to the |
| strictest specified alignment. |
| |
| This formally comes from the c++11 specification but we are |
| doing it for the GNU attribute syntax as well. */ |
| *no_add_attrs = true; |
| else if (warn_if_not_aligned_p |
| && TREE_CODE (decl) == FIELD_DECL |
| && !DECL_C_BIT_FIELD (decl)) |
| { |
| SET_DECL_WARN_IF_NOT_ALIGN (decl, bitalign); |
| warn_if_not_aligned_p = false; |
| set_align = false; |
| } |
| |
| if (warn_if_not_aligned_p) |
| { |
| error ("%<warn_if_not_aligned%> may not be specified for %q+D", |
| decl); |
| *no_add_attrs = true; |
| } |
| else if (!is_type && !*no_add_attrs && set_align) |
| { |
| SET_DECL_ALIGN (decl, bitalign); |
| DECL_USER_ALIGN (decl) = 1; |
| } |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "aligned" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_aligned_attribute (tree *node, tree name, tree args, |
| int flags, bool *no_add_attrs) |
| { |
| return common_handle_aligned_attribute (node, name, args, flags, |
| no_add_attrs, false); |
| } |
| |
| /* Handle a "warn_if_not_aligned" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_warn_if_not_aligned_attribute (tree *node, tree name, |
| tree args, int flags, |
| bool *no_add_attrs) |
| { |
| return common_handle_aligned_attribute (node, name, args, flags, |
| no_add_attrs, true); |
| } |
| |
| /* Handle a "weak" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_weak_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool * ARG_UNUSED (no_add_attrs)) |
| { |
| if (TREE_CODE (*node) == FUNCTION_DECL |
| && DECL_DECLARED_INLINE_P (*node)) |
| { |
| warning (OPT_Wattributes, "inline function %q+D declared weak", *node); |
| *no_add_attrs = true; |
| } |
| else if (lookup_attribute ("ifunc", DECL_ATTRIBUTES (*node))) |
| { |
| error ("indirect function %q+D cannot be declared weak", *node); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| else if (VAR_OR_FUNCTION_DECL_P (*node)) |
| declare_weak (*node); |
| else |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle a "noinit" or "persistent" attribute; arguments as in |
| struct attribute_spec.handler. |
| This generic handler is used for "special variable sections" that allow the |
| section name to be set using a dedicated attribute. Additional validation |
| is performed for the specific properties of the section corresponding to the |
| attribute. |
| The ".noinit" section *is not* loaded by the program loader, and is not |
| initialized by the runtime startup code. |
| The ".persistent" section *is* loaded by the program loader, but is not |
| initialized by the runtime startup code. */ |
| static tree |
| handle_special_var_sec_attribute (tree *node, tree name, tree args, |
| int flags, bool *no_add_attrs) |
| { |
| tree decl = *node; |
| tree res = NULL_TREE; |
| |
| /* First perform generic validation common to "noinit" and "persistent" |
| attributes. */ |
| if (!targetm_common.have_named_sections) |
| { |
| error_at (DECL_SOURCE_LOCATION (decl), |
| "section attributes are not supported for this target"); |
| goto fail; |
| } |
| |
| if (!VAR_P (decl)) |
| { |
| warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, |
| "ignoring %qE attribute not set on a variable", |
| name); |
| goto fail; |
| } |
| |
| if (VAR_P (decl) |
| && current_function_decl != NULL_TREE |
| && !TREE_STATIC (decl)) |
| { |
| error_at (DECL_SOURCE_LOCATION (decl), |
| "%qE attribute cannot be specified for local variables", |
| name); |
| goto fail; |
| } |
| |
| if (VAR_P (decl) |
| && !targetm.have_tls && targetm.emutls.tmpl_section |
| && DECL_THREAD_LOCAL_P (decl)) |
| { |
| error ("section of %q+D cannot be overridden", decl); |
| goto fail; |
| } |
| |
| if (!targetm.have_switchable_bss_sections) |
| { |
| error ("%qE attribute is specific to ELF targets", name); |
| goto fail; |
| } |
| |
| if (TREE_READONLY (decl)) |
| { |
| warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, |
| "ignoring %qE attribute set on const variable", |
| name); |
| goto fail; |
| } |
| |
| /* Now validate noinit/persistent individually. */ |
| if (strcmp (IDENTIFIER_POINTER (name), "noinit") == 0) |
| { |
| if (DECL_INITIAL (decl)) |
| { |
| warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, |
| "ignoring %qE attribute set on initialized variable", |
| name); |
| goto fail; |
| } |
| /* If this var is thought to be common, then change this. "noinit" |
| variables must be placed in an explicit ".noinit" section. */ |
| DECL_COMMON (decl) = 0; |
| } |
| else if (strcmp (IDENTIFIER_POINTER (name), "persistent") == 0) |
| { |
| if (DECL_COMMON (decl) || DECL_INITIAL (decl) == NULL_TREE) |
| { |
| warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, |
| "ignoring %qE attribute set on uninitialized variable", |
| name); |
| goto fail; |
| } |
| } |
| else |
| gcc_unreachable (); |
| |
| res = targetm.handle_generic_attribute (node, name, args, flags, |
| no_add_attrs); |
| |
| /* If the back end confirms the attribute can be added then continue onto |
| final processing. */ |
| if (!(*no_add_attrs)) |
| return res; |
| |
| fail: |
| *no_add_attrs = true; |
| return res; |
| } |
| |
| /* Handle a "noplt" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_noplt_attribute (tree *node, tree name, |
| tree ARG_UNUSED (args), |
| int ARG_UNUSED (flags), |
| bool * ARG_UNUSED (no_add_attrs)) |
| { |
| if (TREE_CODE (*node) != FUNCTION_DECL) |
| { |
| warning (OPT_Wattributes, |
| "%qE attribute is only applicable on functions", name); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| return NULL_TREE; |
| } |
| |
| /* Handle a "symver" attribute. */ |
| |
| static tree |
| handle_symver_attribute (tree *node, tree ARG_UNUSED (name), tree args, |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| tree symver; |
| const char *symver_str; |
| |
| if (TREE_CODE (*node) != FUNCTION_DECL && TREE_CODE (*node) != VAR_DECL) |
| { |
| warning (OPT_Wattributes, |
| "%<symver%> attribute only applies to functions and variables"); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| if (!decl_in_symtab_p (*node)) |
| { |
| warning (OPT_Wattributes, |
| "%<symver%> attribute is only applicable to symbols"); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| for (; args; args = TREE_CHAIN (args)) |
| { |
| symver = TREE_VALUE (args); |
| if (TREE_CODE (symver) != STRING_CST) |
| { |
| error ("%<symver%> attribute argument not a string constant"); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| symver_str = TREE_STRING_POINTER (symver); |
| |
| int ats = 0; |
| for (int n = 0; (int)n < TREE_STRING_LENGTH (symver); n++) |
| if (symver_str[n] == '@') |
| ats++; |
| |
| if (ats != 1 && ats != 2) |
| { |
| error ("symver attribute argument must have format %<name@nodename%>"); |
| error ("%<symver%> attribute argument %qs must contain one or two " |
| "%<@%>", symver_str); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| } |
| |
| return NULL_TREE; |
| } |
| |
| |
| /* 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. */ |
| |
| static tree |
| handle_alias_ifunc_attribute (bool is_alias, tree *node, tree name, tree args, |
| bool *no_add_attrs) |
| { |
| tree decl = *node; |
| |
| if (TREE_CODE (decl) != FUNCTION_DECL |
| && (!is_alias || !VAR_P (decl))) |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| else if ((TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) |
| || (TREE_CODE (decl) != FUNCTION_DECL |
| && TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl)) |
| /* A static variable declaration is always a tentative definition, |
| but the alias is a non-tentative definition which overrides. */ |
| || (TREE_CODE (decl) != FUNCTION_DECL |
| && ! TREE_PUBLIC (decl) && DECL_INITIAL (decl))) |
| { |
| error ("%q+D defined both normally and as %qE attribute", decl, name); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| else if (!is_alias |
| && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl)) |
| || lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))) |
| { |
| error ("weak %q+D cannot be defined %qE", decl, name); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| |
| /* Note that the very first time we process a nested declaration, |
| decl_function_context will not be set. Indeed, *would* never |
| be set except for the DECL_INITIAL/DECL_EXTERNAL frobbery that |
| we do below. After such frobbery, pushdecl would set the context. |
| In any case, this is never what we want. */ |
| else if (decl_function_context (decl) == 0 && current_function_decl == NULL) |
| { |
| tree id; |
| |
| id = TREE_VALUE (args); |
| if (TREE_CODE (id) != STRING_CST) |
| { |
| error ("attribute %qE argument not a string", name); |
| *no_add_attrs = true; |
| return NULL_TREE; |
| } |
| id = get_identifier (TREE_STRING_POINTER (id)); |
| /* This counts as a use of the object pointed to. */ |
| TREE_USED (id) = 1; |
| |
| if (TREE_CODE (decl) == FUNCTION_DECL) |
| DECL_INITIAL (decl) = error_mark_node; |
| else |
| TREE_STATIC (decl) = 1; |
| |
| if (!is_alias) |
| { |
| /* ifuncs are also aliases, so set that attribute too. */ |
| DECL_ATTRIBUTES (decl) |
| = tree_cons (get_identifier ("alias"), args, |
| DECL_ATTRIBUTES (decl)); |
| DECL_ATTRIBUTES (decl) = tree_cons (get_identifier ("ifunc"), |
| NULL, DECL_ATTRIBUTES (decl)); |
| } |
| } |
| else |
| { |
| warning (OPT_Wattributes, "%qE attribute ignored", name); |
| *no_add_attrs = true; |
| } |
| |
| if (decl_in_symtab_p (*node)) |
| { |
| struct symtab_node *n = symtab_node::get (decl); |
| if (n && n->refuse_visibility_changes) |
| error ("%+qD declared %qs after being used", |
| decl, is_alias ? "alias" : "ifunc"); |
| } |
| |
| |
| return NULL_TREE; |
| } |
| |
| /* Handle an "alias" or "ifunc" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_ifunc_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| return handle_alias_ifunc_attribute (false, node, name, args, no_add_attrs); |
| } |
| |
| /* Handle an "alias" or "ifunc" attribute; arguments as in |
| struct attribute_spec.handler. */ |
| |
| static tree |
| handle_alias_attribute (tree *node, tree name, tree args, |
| int ARG_UNUSED (flags), bool *no_add_attrs) |
| { |
| return handle_alias_ifunc_attribute (true, node, name, args, no_add_attrs); |
| } |
| |
| /* Handle the "copy" attribute NAME by copying the set of attributes |
| from the symbol referenced by ARGS to the declaration of *NODE. */ |
| |
| static tree |
| handle_copy_attribute (tree *node, tree name, tree args, |
| int flags, bool *no_add_attrs) |
| { |
| /* Do not apply the copy attribute itself. It serves no purpose |
| other than to copy other attributes. */ |
| *no_add_attrs = true; |
| |
| tree decl = *node; |
| |
| tree ref = TREE_VALUE (args); |
| if (ref == error_mark_node) |
| return NULL_TREE; |
| |
| if (TREE_CODE (ref) == STRING_CST) |
| { |
| /* Explicitly handle this case since using a string literal |
| as an argument is a likely mistake. */ |
| error_at (DECL_SOURCE_LOCATION (decl), |
| "%qE attribute argument cannot be a string", |
| name); |
| return NULL_TREE; |
| } |
| |
| if (CONSTANT_CLASS_P (ref) |
| && (INTEGRAL_TYPE_P (TREE_TYPE (ref)) |
| || FLOAT_TYPE_P (TREE_TYPE (ref)))) |
| { |
| /* Similar to the string case, since some function attributes |
| accept literal numbers as arguments (e.g., alloc_size or |
| nonnull) using one here is a likely mistake. */ |
| error_at (DECL_SOURCE_LOCATION (decl), |
| "%qE attribute argument cannot be a constant arithmetic " |
| "expression", |
| name); |
| return NULL_TREE; |
| } |
| |
| if (ref == node[1]) |
| { |
| /* Another possible mistake (but indirect self-references aren't |
| and diagnosed and shouldn't be). */ |
| if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, |
| "%qE attribute ignored on a redeclaration " |
| "of the referenced symbol", |
| name)) |
| inform (DECL_SOURCE_LOCATION (node[1]), |
| "previous declaration here"); |
| return NULL_TREE; |
| } |
| |
| /* Consider address-of expressions in the attribute argument |
| as requests to copy from the referenced entity. */ |
| if (TREE_CODE (ref) == ADDR_EXPR) |
| ref = TREE_OPERAND (ref, 0); |
| |
| do |
| { |
| /* Drill down into references to find the referenced decl. */ |
| tree_code refcode = TREE_CODE (ref); |
| if (refcode == ARRAY_REF |
| || refcode == INDIRECT_REF) |
| ref = TREE_OPERAND (ref, 0); |
| else if (refcode == COMPONENT_REF) |
| ref = TREE_OPERAND (ref, 1); |
| else |
| break; |
| } while (!DECL_P (ref)); |
| |
| /* For object pointer expressions, consider those to be requests |
| to copy from their type, such as in: |
| struct __attribute__ (copy ((struct T *)0)) U { ... }; |
| which copies type attributes from struct T to the declaration |
| of struct U. */ |
| if ((CONSTANT_CLASS_P (ref) || EXPR_P (ref)) |
| && POINTER_TYPE_P (TREE_TYPE (ref)) |
| && !FUNCTION_POINTER_TYPE_P (TREE_TYPE (ref))) |
| ref = TREE_TYPE (ref); |
| |
| tree reftype = TYPE_P (ref) ? ref : TREE_TYPE (ref); |
| |
| if (DECL_P (decl)) |
| { |
| if ((VAR_P (decl) |
| && (TREE_CODE (ref) == FUNCTION_DECL |
| || (EXPR_P (ref) |
| && POINTER_TYPE_P (reftype) |
| && FUNC_OR_METHOD_TYPE_P (TREE_TYPE (reftype))))) |
| || (TREE_CODE (decl) == FUNCTION_DECL |
| && (VAR_P (ref) |
| || (EXPR_P (ref) |
| && !FUNC_OR_METHOD_TYPE_P (reftype) |
| && (!POINTER_TYPE_P (reftype) |
| || !FUNC_OR_METHOD_TYPE_P (TREE_TYPE (reftype))))))) |
| { |
| /* It makes no sense to try to copy function attributes |
| to a variable, or variable attributes to a function. */ |
| if (warning (OPT_Wattributes, |
| "%qE attribute ignored on a declaration of " |
| "a different kind than referenced symbol", |
| name) |
| && DECL_P (ref)) |
| inform (DECL_SOURCE_LOCATION (ref), |
| "symbol %qD referenced by %qD declared here", ref, decl); |
| return NULL_TREE; |
| } |
| |
| tree attrs = NULL_TREE; |
| if (DECL_P (ref)) |
| attrs = DECL_ATTRIBUTES (ref); |
| else if (TYPE_P (ref)) |
| attrs = TYPE_ATTRIBUTES (ref); |
| |
| /* Copy decl attributes from REF to DECL. */ |
| for (tree at = attrs; at; at = TREE_CHAIN (at)) |
| { |
| /* Avoid copying attributes that affect a symbol linkage, |
| inlining, or visibility since those in all likelihood |
| only apply to the target. |
| FIXME: make it possible to specify which attributes to |
| copy or not to copy in the copy attribute itself. */ |
| tree atname = get_attribute_name (at); |
| if |