diff options
author | Jason Merrill <jason@yorick.cygnus.com> | 1998-08-13 17:29:30 +0000 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 1998-08-13 13:29:30 -0400 |
commit | 2ce3c6c615fa735693e1de39e9777919ba4fd106 (patch) | |
tree | 5151de01751b24d690444de42bb0d59e3a3d0764 /gcc/c-common.c | |
parent | db04386fd134ed6619ea9acf279ee245afd440a3 (diff) | |
download | gcc-2ce3c6c615fa735693e1de39e9777919ba4fd106.zip gcc-2ce3c6c615fa735693e1de39e9777919ba4fd106.tar.gz gcc-2ce3c6c615fa735693e1de39e9777919ba4fd106.tar.bz2 |
tree.h: De-conditionalize init_priority code.
* tree.h: De-conditionalize init_priority code.
* mips.h (NM_FLAGS): Change from -Bp to -Bn.
* collect2.c (NM_FLAGS): Change from -p to -n.
* configure.in: Turn on collect2 for mipstx39-elf.
Handle use_collect2=no properly.
* c-common.c: De-conditionalize init_priority code.
* collect2.c (extract_init_priority, sort_ids): New fns.
(main): Call sort_ids.
Move sequence_number to file scope.
* configure.in: Handle --enable-init-priority.
* c-common.c (attrs): Add A_INIT_PRIORITY.
(init_attributes, decl_attributes): Likewise.
* tree.h (DEFAULT_INIT_PRIORITY, MAX_INIT_PRIORITY): New macros.
* tree.c (get_file_function_name_long): Split out...
(get_file_function_name): ...from here.
cp/:
* lang-options.h: Add -finit-priority.
* decl2.c: Likewise. Check flag_init_priority instead of
USE_INIT_PRIORITY.
* decl2.c (setup_initp): New fn.
(start_objects, finish_objects, do_ctors): Handle init_priority.
(do_dtors, finish_file): Likewise.
From-SVN: r21701
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index 8405a41..6f14579 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -52,7 +52,8 @@ int skip_evaluation; enum attrs {A_PACKED, A_NOCOMMON, A_COMMON, A_NORETURN, A_CONST, A_T_UNION, A_NO_INSTRUMENT_FUNCTION, A_CONSTRUCTOR, A_DESTRUCTOR, A_MODE, A_SECTION, A_ALIGNED, - A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS}; + A_UNUSED, A_FORMAT, A_FORMAT_ARG, A_WEAK, A_ALIAS, + A_INIT_PRIORITY}; enum format_type { printf_format_type, scanf_format_type, strftime_format_type }; @@ -89,6 +90,12 @@ static int if_stack_pointer = 0; /* Generate RTL for the start of an if-then, and record the start of it for ambiguous else detection. */ +/* A list of objects which have constructors or destructors which + reside in the global scope, and have an init_priority attribute + associated with them. The decl is stored in the TREE_VALUE slot + and the priority number is stored in the TREE_PURPOSE slot. */ +tree static_aggregates_initp; + void c_expand_start_cond (cond, exitflag, compstmt_count) tree cond; @@ -383,6 +390,7 @@ init_attributes () add_attribute (A_FORMAT_ARG, "format_arg", 1, 1, 1); add_attribute (A_WEAK, "weak", 0, 0, 1); add_attribute (A_ALIAS, "alias", 1, 1, 1); + add_attribute (A_INIT_PRIORITY, "init_priority", 0, 1, 0); add_attribute (A_NO_INSTRUMENT_FUNCTION, "no_instrument_function", 0, 0, 1); } @@ -859,6 +867,62 @@ decl_attributes (node, attributes, prefix_attributes) warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name)); break; + case A_INIT_PRIORITY: + { + tree initp_expr = (args ? TREE_VALUE (args): NULL_TREE); + int pri; + + if (initp_expr) + STRIP_NOPS (initp_expr); + + if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) + { + error ("requested init_priority is not an integer constant"); + continue; + } + + pri = TREE_INT_CST_LOW (initp_expr); + + if (is_type || TREE_CODE (decl) != VAR_DECL + || ! TREE_STATIC (decl) + || DECL_EXTERNAL (decl) + || (TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE + && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE) + /* Static objects in functions are initialized the + first time control passes through that + function. This is not precise enough to pin down an + init_priority value, so don't allow it. */ + || current_function_decl) + { + error ("can only use init_priority attribute on file-scope definitions of objects of class type"); + continue; + } + + /* Check for init_priorities that are reserved for + implementation. Reserved for language and runtime + support implementations.*/ + if ((10 <= pri && pri <= 99) + /* Reserved for standard library implementations. */ + || (500 <= pri && pri <= 999) + /* Reserved for objects with no attributes. */ + || pri > (MAX_INIT_PRIORITY - 50)) + { + warning + ("requested init_priority is reserved for internal use"); + continue; + } + + if (pri > MAX_INIT_PRIORITY || pri <= 0) + { + error ("requested init_priority is out of range"); + continue; + } + + static_aggregates_initp + = perm_tree_cons (initp_expr, decl, static_aggregates_initp); + break; + } + case A_NO_INSTRUMENT_FUNCTION: if (TREE_CODE (decl) != FUNCTION_DECL) { |