Index: head/contrib/gcc/cp/decl.c =================================================================== --- head/contrib/gcc/cp/decl.c (revision 60969) +++ head/contrib/gcc/cp/decl.c (revision 60970) @@ -1,15043 +1,15162 @@ /* Process declarations and variables for C compiler. Copyright (C) 1988, 92-98, 1999 Free Software Foundation, Inc. Contributed by Michael Tiemann (tiemann@cygnus.com) This file is part of GNU CC. GNU CC 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 2, or (at your option) any later version. GNU CC 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 GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* $FreeBSD$ */ /* Process declarations and symbol lookup for C front end. Also constructs types; the standard scalar types at initialization, and structure, union, array and enum types when they are declared. */ /* ??? not all decl nodes are given the most useful possible line numbers. For example, the CONST_DECLs for enum values. */ #include "config.h" #include "system.h" #include "tree.h" #include "rtl.h" #include "flags.h" #include "cp-tree.h" #include "decl.h" #include "lex.h" #include #include "obstack.h" #include "defaults.h" #include "output.h" #include "except.h" #include "toplev.h" #include "../hash.h" #define obstack_chunk_alloc xmalloc #define obstack_chunk_free free extern tree builtin_return_address_fndecl; extern struct obstack permanent_obstack; extern struct obstack* saveable_obstack; extern int current_class_depth; extern tree static_ctors, static_dtors; extern int static_labelno; extern tree current_namespace; extern tree global_namespace; extern void (*print_error_function) PROTO((char *)); extern int (*valid_lang_attribute) PROTO ((tree, tree, tree, tree)); /* Obstack used for remembering local class declarations (like enums and static (const) members. */ #include "stack.h" struct obstack decl_obstack; static struct stack_level *decl_stack; #ifndef CHAR_TYPE_SIZE #define CHAR_TYPE_SIZE BITS_PER_UNIT #endif #ifndef SHORT_TYPE_SIZE #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) #endif #ifndef INT_TYPE_SIZE #define INT_TYPE_SIZE BITS_PER_WORD #endif #ifndef LONG_TYPE_SIZE #define LONG_TYPE_SIZE BITS_PER_WORD #endif #ifndef LONG_LONG_TYPE_SIZE #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) #endif #ifndef WCHAR_UNSIGNED #define WCHAR_UNSIGNED 0 #endif #ifndef FLOAT_TYPE_SIZE #define FLOAT_TYPE_SIZE BITS_PER_WORD #endif #ifndef DOUBLE_TYPE_SIZE #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) #endif #ifndef LONG_DOUBLE_TYPE_SIZE #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) #endif #ifndef BOOL_TYPE_SIZE #ifdef SLOW_BYTE_ACCESS #define BOOL_TYPE_SIZE ((SLOW_BYTE_ACCESS) ? (POINTER_SIZE) : (CHAR_TYPE_SIZE)) #else #define BOOL_TYPE_SIZE CHAR_TYPE_SIZE #endif #endif /* We let tm.h override the types used here, to handle trivial differences such as the choice of unsigned int or long unsigned int for size_t. When machines start needing nontrivial differences in the size type, it would be best to do something here to figure out automatically from other information what type to use. */ #ifndef SIZE_TYPE #define SIZE_TYPE "long unsigned int" #endif #ifndef PTRDIFF_TYPE #define PTRDIFF_TYPE "long int" #endif #ifndef WCHAR_TYPE #define WCHAR_TYPE "int" #endif static tree grokparms PROTO((tree, int)); static tree lookup_nested_type PROTO((tree, tree)); static const char *redeclaration_error_message PROTO((tree, tree)); static struct stack_level *push_decl_level PROTO((struct stack_level *, struct obstack *)); static void push_binding_level PROTO((struct binding_level *, int, int)); static void pop_binding_level PROTO((void)); static void suspend_binding_level PROTO((void)); static void resume_binding_level PROTO((struct binding_level *)); static struct binding_level *make_binding_level PROTO((void)); static void declare_namespace_level PROTO((void)); static void signal_catch PROTO((int)) ATTRIBUTE_NORETURN; static void storedecls PROTO((tree)); static void require_complete_types_for_parms PROTO((tree)); static void push_overloaded_decl_1 PROTO((tree)); static int ambi_op_p PROTO((tree)); static int unary_op_p PROTO((tree)); static tree store_bindings PROTO((tree, tree)); static tree lookup_tag_reverse PROTO((tree, tree)); static tree obscure_complex_init PROTO((tree, tree)); static tree maybe_build_cleanup_1 PROTO((tree, tree)); static tree lookup_name_real PROTO((tree, int, int, int)); static void warn_extern_redeclared_static PROTO((tree, tree)); static void grok_reference_init PROTO((tree, tree, tree)); static tree grokfndecl PROTO((tree, tree, tree, tree, int, enum overload_flags, tree, tree, int, int, int, int, int, int, tree)); static tree grokvardecl PROTO((tree, tree, RID_BIT_TYPE *, int, int, tree)); static tree lookup_tag PROTO((enum tree_code, tree, struct binding_level *, int)); static void set_identifier_type_value_with_scope PROTO((tree, tree, struct binding_level *)); static void record_builtin_type PROTO((enum rid, const char *, tree)); static void record_unknown_type PROTO((tree, const char *)); static int member_function_or_else PROTO((tree, tree, const char *)); static void bad_specifiers PROTO((tree, const char *, int, int, int, int, int)); static void lang_print_error_function PROTO((char *)); static tree maybe_process_template_type_declaration PROTO((tree, int, struct binding_level*)); static void check_for_uninitialized_const_var PROTO((tree)); static unsigned long typename_hash PROTO((hash_table_key)); static boolean typename_compare PROTO((hash_table_key, hash_table_key)); static void push_binding PROTO((tree, tree, struct binding_level*)); static int add_binding PROTO((tree, tree)); static void pop_binding PROTO((tree, tree)); static tree local_variable_p PROTO((tree)); static tree find_binding PROTO((tree, tree)); static tree select_decl PROTO((tree, int)); static tree unqualified_namespace_lookup PROTO((tree, int)); static int lookup_flags PROTO((int, int)); static tree qualify_lookup PROTO((tree, int)); static tree record_builtin_java_type PROTO((const char *, int)); static const char *tag_name PROTO((enum tag_types code)); static void find_class_binding_level PROTO((void)); static struct binding_level *innermost_nonclass_level PROTO((void)); +static void finish_dtor PROTO((void)); +static void finish_ctor PROTO((int)); static tree poplevel_class PROTO((void)); static void warn_about_implicit_typename_lookup PROTO((tree, tree)); static int walk_namespaces_r PROTO((tree, walk_namespaces_fn, void *)); static int walk_globals_r PROTO((tree, void *)); #if defined (DEBUG_CP_BINDING_LEVELS) static void indent PROTO((void)); #endif /* A node which has tree code ERROR_MARK, and whose type is itself. All erroneous expressions are replaced with this node. All functions that accept nodes as arguments should avoid generating error messages if this node is one of the arguments, since it is undesirable to get multiple error messages from one error in the input. */ tree error_mark_node; /* Erroneous argument lists can use this *IFF* they do not modify it. */ tree error_mark_list; /* INTEGER_TYPE and REAL_TYPE nodes for the standard data types */ tree short_integer_type_node; tree integer_type_node; tree long_integer_type_node; tree long_long_integer_type_node; tree short_unsigned_type_node; tree unsigned_type_node; tree long_unsigned_type_node; tree long_long_unsigned_type_node; tree ptrdiff_type_node; tree unsigned_char_type_node; tree signed_char_type_node; tree char_type_node; tree wchar_type_node; tree signed_wchar_type_node; tree unsigned_wchar_type_node; tree wchar_decl_node; tree float_type_node; tree double_type_node; tree long_double_type_node; tree complex_integer_type_node; tree complex_float_type_node; tree complex_double_type_node; tree complex_long_double_type_node; tree intQI_type_node; tree intHI_type_node; tree intSI_type_node; tree intDI_type_node; #if HOST_BITS_PER_WIDE_INT >= 64 tree intTI_type_node; #endif tree unsigned_intQI_type_node; tree unsigned_intHI_type_node; tree unsigned_intSI_type_node; tree unsigned_intDI_type_node; #if HOST_BITS_PER_WIDE_INT >= 64 tree unsigned_intTI_type_node; #endif tree java_byte_type_node; tree java_short_type_node; tree java_int_type_node; tree java_long_type_node; tree java_float_type_node; tree java_double_type_node; tree java_char_type_node; tree java_boolean_type_node; /* A VOID_TYPE node, and the same, packaged in a TREE_LIST. */ tree void_type_node, void_list_node; tree void_zero_node; /* Nodes for types `void *' and `const void *'. */ tree ptr_type_node; tree const_ptr_type_node; /* Nodes for types `char *' and `const char *'. */ tree string_type_node, const_string_type_node; /* Type `char[256]' or something like it. Used when an array of char is needed and the size is irrelevant. */ tree char_array_type_node; /* Type `int[256]' or something like it. Used when an array of int needed and the size is irrelevant. */ tree int_array_type_node; /* Type `wchar_t[256]' or something like it. Used when a wide string literal is created. */ tree wchar_array_type_node; /* The bool data type, and constants */ tree boolean_type_node, boolean_true_node, boolean_false_node; /* Type `int ()' -- used for implicit declaration of functions. */ tree default_function_type; /* Function types `double (double)' and `double (double, double)', etc. */ static tree double_ftype_double, double_ftype_double_double; static tree int_ftype_int, long_ftype_long; static tree float_ftype_float; static tree ldouble_ftype_ldouble; /* Function type `int (const void *, const void *, size_t)' */ static tree int_ftype_cptr_cptr_sizet; /* C++ extensions */ tree vtable_entry_type; tree delta_type_node; #if 0 /* Old rtti stuff. */ tree __baselist_desc_type_node; tree __i_desc_type_node, __m_desc_type_node; tree __t_desc_array_type, __i_desc_array_type, __m_desc_array_type; #endif tree __t_desc_type_node; #if 0 tree __tp_desc_type_node; #endif tree __access_mode_type_node; tree __bltn_desc_type_node, __user_desc_type_node, __class_desc_type_node; tree __ptr_desc_type_node, __attr_desc_type_node, __func_desc_type_node; tree __ptmf_desc_type_node, __ptmd_desc_type_node; #if 0 /* Not needed yet? May be needed one day? */ tree __bltn_desc_array_type, __user_desc_array_type, __class_desc_array_type; tree __ptr_desc_array_type, __attr_dec_array_type, __func_desc_array_type; tree __ptmf_desc_array_type, __ptmd_desc_array_type; #endif +/* This is the identifier __vlist. */ +tree vlist_identifier; + +/* This is the type _Vlist = vtable_entry_type**. */ +tree vlist_type_node; + +/* A null pointer of type _Vlist. */ +tree vlist_zero_node; + /* Indicates that there is a type value in some namespace, although that is not necessarily in scope at the moment. */ static tree global_type_node; tree class_star_type_node; tree class_type_node, record_type_node, union_type_node, enum_type_node; tree unknown_type_node; tree opaque_type_node, signature_type_node; tree sigtable_entry_type; /* Array type `vtable_entry_type[]' */ tree vtbl_type_node; tree vtbl_ptr_type_node; /* namespace std */ tree std_node; int in_std = 0; /* Expect only namespace names now. */ static int only_namespace_names; /* In a destructor, the point at which all derived class destroying has been done, just before any base class destroying will be done. */ tree dtor_label; /* In a destructor, the last insn emitted after the start of the function and the parms. */ static rtx last_dtor_insn; /* In a constructor, the last insn emitted after the start of the function and the parms, the exception specification and any function-try-block. The constructor initializers are emitted after this insn. */ static rtx last_parm_cleanup_insn; /* In a constructor, the point at which we are ready to return the pointer to the initialized object. */ tree ctor_label; /* A FUNCTION_DECL which can call `abort'. Not necessarily the one that the user will declare, but sufficient to be called by routines that want to abort the program. */ tree abort_fndecl; /* A FUNCTION_DECL for the default `::operator delete'. */ tree global_delete_fndecl; extern rtx cleanup_label, return_label; /* If original DECL_RESULT of current function was a register, but due to being an addressable named return value, would up on the stack, this variable holds the named return value's original location. */ static rtx original_result_rtx; /* Sequence of insns which represents base initialization. */ tree base_init_expr; /* C++: Keep these around to reduce calls to `get_identifier'. Identifiers for `this' in member functions and the auto-delete parameter for destructors. */ tree this_identifier, in_charge_identifier; tree ctor_identifier, dtor_identifier; /* Used in pointer to member functions, in vtables, and in sigtables. */ tree pfn_identifier, index_identifier, delta_identifier, delta2_identifier; tree pfn_or_delta2_identifier, tag_identifier; tree vt_off_identifier; struct named_label_list { struct binding_level *binding_level; tree names_in_scope; tree label_decl; char *filename_o_goto; int lineno_o_goto; struct named_label_list *next; }; /* A list (chain of TREE_LIST nodes) of named label uses. The TREE_PURPOSE field is the list of variables defined in the label's scope defined at the point of use. The TREE_VALUE field is the LABEL_DECL used. The TREE_TYPE field holds `current_binding_level' at the point of the label's use. BWAHAHAAHAHahhahahahaah. No, no, no, said the little chicken. Look at the pretty struct named_label_list. See the pretty struct with the pretty named fields that describe what they do. See the pretty lack of gratuitous casts. Notice the code got a lot cleaner. Used only for jumps to as-yet undefined labels, since jumps to defined labels can have their validity checked by stmt.c. */ static struct named_label_list *named_label_uses = NULL; /* A list of objects which have constructors or destructors which reside in the global scope. The decl is stored in the TREE_VALUE slot and the initializer is stored in the TREE_PURPOSE slot. */ tree static_aggregates; /* -- end of C++ */ /* Two expressions that are constants with value zero. The first is of type `int', the second of type `void *'. */ tree integer_zero_node; tree null_pointer_node; /* The value for __null (NULL), namely, a zero of an integer type with the same number of bits as a pointer. */ tree null_node; /* A node for the integer constants 1, 2, and 3. */ tree integer_one_node, integer_two_node, integer_three_node; /* While defining an enum type, this is 1 plus the last enumerator constant value. */ static tree enum_next_value; /* Nonzero means that there was overflow computing enum_next_value. */ static int enum_overflow; /* Parsing a function declarator leaves a list of parameter names or a chain or parameter decls here. */ tree last_function_parms; /* Parsing a function declarator leaves here a chain of structure and enum types declared in the parmlist. */ static tree last_function_parm_tags; /* After parsing the declarator that starts a function definition, `start_function' puts here the list of parameter names or chain of decls. `store_parm_decls' finds it here. */ static tree current_function_parms; /* Similar, for last_function_parm_tags. */ static tree current_function_parm_tags; /* A list (chain of TREE_LIST nodes) of all LABEL_DECLs in the function that have names. Here so we can clear out their names' definitions at the end of the function. */ static tree named_labels; /* A list of LABEL_DECLs from outer contexts that are currently shadowed. */ static tree shadowed_labels; /* The FUNCTION_DECL for the function currently being compiled, or 0 if between functions. */ tree current_function_decl; /* Set to 0 at beginning of a function definition, set to 1 if a return statement that specifies a return value is seen. */ int current_function_returns_value; /* Set to 0 at beginning of a function definition, set to 1 if a return statement with no argument is seen. */ int current_function_returns_null; /* Set to 0 at beginning of a function definition, and whenever a label (case or named) is defined. Set to value of expression returned from function when that value can be transformed into a named return value. */ tree current_function_return_value; /* Nonzero means give `double' the same size as `float'. */ extern int flag_short_double; /* Nonzero means don't recognize any builtin functions. */ extern int flag_no_builtin; /* Nonzero means don't recognize the non-ANSI builtin functions. -ansi sets this. */ extern int flag_no_nonansi_builtin; /* Nonzero means enable obscure ANSI features and disable GNU extensions that might cause ANSI-compliant code to be miscompiled. */ extern int flag_ansi; /* Nonzero if we want to support huge (> 2^(sizeof(short)*8-1) bytes) objects. */ extern int flag_huge_objects; /* Nonzero if we want to conserve space in the .o files. We do this by putting uninitialized data and runtime initialized data into .common instead of .data at the expense of not flagging multiple definitions. */ extern int flag_conserve_space; /* Pointers to the base and current top of the language name stack. */ extern tree *current_lang_base, *current_lang_stack; /* C and C++ flags are in decl2.c. */ /* Set to 0 at beginning of a constructor, set to 1 if that function does an allocation before referencing its instance variable. */ static int current_function_assigns_this; int current_function_just_assigned_this; /* Set to 0 at beginning of a function. Set non-zero when store_parm_decls is called. Don't call store_parm_decls if this flag is non-zero! */ int current_function_parms_stored; /* Flag used when debugging spew.c */ extern int spew_debug; /* This is a copy of the class_shadowed list of the previous class binding contour when at global scope. It's used to reset IDENTIFIER_CLASS_VALUEs when entering another class scope (i.e. a cache miss). */ extern tree previous_class_values; /* A expression of value 0 with the same precision as a sizetype node, but signed. */ tree signed_size_zero_node; /* The name of the anonymous namespace, throughout this translation unit. */ tree anonymous_namespace_name; /* Allocate a level of searching. */ static struct stack_level * push_decl_level (stack, obstack) struct stack_level *stack; struct obstack *obstack; { struct stack_level tem; tem.prev = stack; return push_stack_level (obstack, (char *)&tem, sizeof (tem)); } /* For each binding contour we allocate a binding_level structure which records the names defined in that contour. Contours include: 0) the global one 1) one for each function definition, where internal declarations of the parameters appear. 2) one for each compound statement, to record its declarations. The current meaning of a name can be found by searching the levels from the current one out to the global one. Off to the side, may be the class_binding_level. This exists only to catch class-local declarations. It is otherwise nonexistent. Also there may be binding levels that catch cleanups that must be run when exceptions occur. Thus, to see whether a name is bound in the current scope, it is not enough to look in the CURRENT_BINDING_LEVEL. You should use lookup_name_current_level instead. */ /* Note that the information in the `names' component of the global contour is duplicated in the IDENTIFIER_GLOBAL_VALUEs of all identifiers. */ struct binding_level { /* A chain of _DECL nodes for all variables, constants, functions, and typedef types. These are in the reverse of the order supplied. There may be OVERLOADs on this list, too, but they are wrapped in TREE_LISTs; the TREE_VALUE is the OVERLOAD. */ tree names; /* A list of structure, union and enum definitions, for looking up tag names. It is a chain of TREE_LIST nodes, each of whose TREE_PURPOSE is a name, or NULL_TREE; and whose TREE_VALUE is a RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. C++: the TREE_VALUE nodes can be simple types for component_bindings. */ tree tags; /* A list of USING_DECL nodes. */ tree usings; /* A list of used namespaces. PURPOSE is the namespace, VALUE the common ancestor with this binding_level's namespace. */ tree using_directives; /* If this binding level is the binding level for a class, then class_shadowed is a TREE_LIST. The TREE_PURPOSE of each node is the name of an entity bound in the class; the TREE_VALUE is the IDENTIFIER_CLASS_VALUE before we entered the class. Thus, when leaving class scope, we can restore the IDENTIFIER_CLASS_VALUE by walking this list. The TREE_TYPE is the DECL bound by this name in the class. */ tree class_shadowed; /* Similar to class_shadowed, but for IDENTIFIER_TYPE_VALUE, and is used for all binding levels. */ tree type_shadowed; /* For each level (except not the global one), a chain of BLOCK nodes for all the levels that were entered and exited one level down. */ tree blocks; /* The BLOCK node for this level, if one has been preallocated. If 0, the BLOCK is allocated (if needed) when the level is popped. */ tree this_block; /* The binding level which this one is contained in (inherits from). */ struct binding_level *level_chain; /* List of decls in `names' that have incomplete structure or union types. */ tree incomplete; /* List of VAR_DECLS saved from a previous for statement. These would be dead in ANSI-conforming code, but might be referenced in ARM-era code. These are stored in a TREE_LIST; the TREE_VALUE is the actual declaration. */ tree dead_vars_from_for; /* 1 for the level that holds the parameters of a function. 2 for the level that holds a class declaration. 3 for levels that hold parameter declarations. */ unsigned parm_flag : 4; /* 1 means make a BLOCK for this level regardless of all else. 2 for temporary binding contours created by the compiler. */ unsigned keep : 3; /* Nonzero if this level "doesn't exist" for tags. */ unsigned tag_transparent : 1; /* Nonzero if this level can safely have additional cleanup-needing variables added to it. */ unsigned more_cleanups_ok : 1; unsigned have_cleanups : 1; /* Nonzero if this level is for storing the decls for template parameters and generic decls; these decls will be discarded and replaced with a TEMPLATE_DECL. */ unsigned pseudo_global : 1; /* This is set for a namespace binding level. */ unsigned namespace_p : 1; /* True if this level is that of a for-statement where we need to worry about ambiguous (ARM or ANSI) scope rules. */ unsigned is_for_scope : 1; /* Two bits left for this word. */ #if defined(DEBUG_CP_BINDING_LEVELS) /* Binding depth at which this level began. */ unsigned binding_depth; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ }; #define NULL_BINDING_LEVEL ((struct binding_level *) NULL) /* The binding level currently in effect. */ static struct binding_level *current_binding_level; /* The binding level of the current class, if any. */ static struct binding_level *class_binding_level; /* A chain of binding_level structures awaiting reuse. */ static struct binding_level *free_binding_level; /* The outermost binding level, for names of file scope. This is created when the compiler is started and exists through the entire run. */ static struct binding_level *global_binding_level; /* Binding level structures are initialized by copying this one. */ static struct binding_level clear_binding_level; /* Nonzero means unconditionally make a BLOCK for the next level pushed. */ static int keep_next_level_flag; #if defined(DEBUG_CP_BINDING_LEVELS) static int binding_depth = 0; static int is_class_level = 0; static void indent () { register unsigned i; for (i = 0; i < binding_depth*2; i++) putc (' ', stderr); } #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ static tree pushdecl_with_scope PROTO((tree, struct binding_level *)); static void push_binding_level (newlevel, tag_transparent, keep) struct binding_level *newlevel; int tag_transparent, keep; { /* Add this level to the front of the chain (stack) of levels that are active. */ *newlevel = clear_binding_level; newlevel->level_chain = current_binding_level; current_binding_level = newlevel; newlevel->tag_transparent = tag_transparent; newlevel->more_cleanups_ok = 1; newlevel->keep = keep; #if defined(DEBUG_CP_BINDING_LEVELS) newlevel->binding_depth = binding_depth; indent (); fprintf (stderr, "push %s level 0x%08x line %d\n", (is_class_level) ? "class" : "block", newlevel, lineno); is_class_level = 0; binding_depth++; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ } /* Find the innermost enclosing class scope, and reset CLASS_BINDING_LEVEL appropriately. */ static void find_class_binding_level () { struct binding_level *level = current_binding_level; while (level && level->parm_flag != 2) level = level->level_chain; if (level && level->parm_flag == 2) class_binding_level = level; else class_binding_level = 0; } static void pop_binding_level () { if (global_binding_level) { /* Cannot pop a level, if there are none left to pop. */ if (current_binding_level == global_binding_level) my_friendly_abort (123); } /* Pop the current level, and free the structure for reuse. */ #if defined(DEBUG_CP_BINDING_LEVELS) binding_depth--; indent (); fprintf (stderr, "pop %s level 0x%08x line %d\n", (is_class_level) ? "class" : "block", current_binding_level, lineno); if (is_class_level != (current_binding_level == class_binding_level)) { indent (); fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); } is_class_level = 0; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ { register struct binding_level *level = current_binding_level; current_binding_level = current_binding_level->level_chain; level->level_chain = free_binding_level; #if 0 /* defined(DEBUG_CP_BINDING_LEVELS) */ if (level->binding_depth != binding_depth) abort (); #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ free_binding_level = level; find_class_binding_level (); } } static void suspend_binding_level () { if (class_binding_level) current_binding_level = class_binding_level; if (global_binding_level) { /* Cannot suspend a level, if there are none left to suspend. */ if (current_binding_level == global_binding_level) my_friendly_abort (123); } /* Suspend the current level. */ #if defined(DEBUG_CP_BINDING_LEVELS) binding_depth--; indent (); fprintf (stderr, "suspend %s level 0x%08x line %d\n", (is_class_level) ? "class" : "block", current_binding_level, lineno); if (is_class_level != (current_binding_level == class_binding_level)) { indent (); fprintf (stderr, "XXX is_class_level != (current_binding_level == class_binding_level)\n"); } is_class_level = 0; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ current_binding_level = current_binding_level->level_chain; find_class_binding_level (); } static void resume_binding_level (b) struct binding_level *b; { /* Resuming binding levels is meant only for namespaces, and those cannot nest into classes. */ my_friendly_assert(!class_binding_level, 386); /* Also, resuming a non-directly nested namespace is a no-no. */ my_friendly_assert(b->level_chain == current_binding_level, 386); current_binding_level = b; #if defined(DEBUG_CP_BINDING_LEVELS) b->binding_depth = binding_depth; indent (); fprintf (stderr, "resume %s level 0x%08x line %d\n", (is_class_level) ? "class" : "block", b, lineno); is_class_level = 0; binding_depth++; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ } /* Create a new `struct binding_level'. */ static struct binding_level * make_binding_level () { /* NOSTRICT */ return (struct binding_level *) xmalloc (sizeof (struct binding_level)); } /* Nonzero if we are currently in the global binding level. */ int global_bindings_p () { return current_binding_level == global_binding_level; } /* Return the innermost binding level that is not for a class scope. */ static struct binding_level * innermost_nonclass_level () { struct binding_level *b; b = current_binding_level; while (b->parm_flag == 2) b = b->level_chain; return b; } /* Nonzero if we are currently in a toplevel binding level. This means either the global binding level or a namespace in a toplevel binding level. Since there are no non-toplevel namespace levels, this really means any namespace or pseudo-global level. We also include a class whose context is toplevel. */ int toplevel_bindings_p () { struct binding_level *b = innermost_nonclass_level (); return b->namespace_p || b->pseudo_global; } /* Nonzero if this is a namespace scope, or if we are defining a class which is itself at namespace scope, or whose enclosing class is such a class, etc. */ int namespace_bindings_p () { struct binding_level *b = innermost_nonclass_level (); return b->namespace_p; } void keep_next_level () { keep_next_level_flag = 1; } /* Nonzero if the current level needs to have a BLOCK made. */ int kept_level_p () { return (current_binding_level->blocks != NULL_TREE || current_binding_level->keep || current_binding_level->names != NULL_TREE || (current_binding_level->tags != NULL_TREE && !current_binding_level->tag_transparent)); } /* Identify this binding level as a level of parameters. */ void declare_parm_level () { current_binding_level->parm_flag = 1; } void declare_pseudo_global_level () { current_binding_level->pseudo_global = 1; } static void declare_namespace_level () { current_binding_level->namespace_p = 1; } int pseudo_global_level_p () { struct binding_level *b = innermost_nonclass_level (); return b->pseudo_global; } void set_class_shadows (shadows) tree shadows; { class_binding_level->class_shadowed = shadows; } /* Enter a new binding level. If TAG_TRANSPARENT is nonzero, do so only for the name space of variables, not for that of tags. */ void pushlevel (tag_transparent) int tag_transparent; { register struct binding_level *newlevel = NULL_BINDING_LEVEL; /* If this is the top level of a function, just make sure that NAMED_LABELS is 0. They should have been set to 0 at the end of the previous function. */ if (current_binding_level == global_binding_level) my_friendly_assert (named_labels == NULL_TREE, 134); /* Reuse or create a struct for this binding level. */ #if defined(DEBUG_CP_BINDING_LEVELS) if (0) #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ if (free_binding_level) #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ { newlevel = free_binding_level; free_binding_level = free_binding_level->level_chain; } else { newlevel = make_binding_level (); } push_binding_level (newlevel, tag_transparent, keep_next_level_flag); GNU_xref_start_scope ((HOST_WIDE_INT) newlevel); keep_next_level_flag = 0; } void note_level_for_for () { current_binding_level->is_for_scope = 1; } void pushlevel_temporary (tag_transparent) int tag_transparent; { pushlevel (tag_transparent); current_binding_level->keep = 2; clear_last_expr (); /* Note we don't call push_momentary() here. Otherwise, it would cause cleanups to be allocated on the momentary obstack, and they will be overwritten by the next statement. */ expand_start_bindings (0); } /* For a binding between a name and an entity at a block scope, this is the `struct binding_level' for the block. */ #define BINDING_LEVEL(NODE) \ (((struct tree_binding*)NODE)->scope.level) /* These are currently unused, but permanent, CPLUS_BINDING nodes. They are kept here because they are allocated from the permanent obstack and cannot be easily freed. */ static tree free_binding_nodes; /* Make DECL the innermost binding for ID. The LEVEL is the binding level at which this declaration is being bound. */ static void push_binding (id, decl, level) tree id; tree decl; struct binding_level* level; { tree binding; if (!free_binding_nodes) { /* There are no free nodes, so we must build one here. */ push_obstacks_nochange (); end_temporary_allocation (); binding = make_node (CPLUS_BINDING); pop_obstacks (); } else { /* There are nodes on the free list. Grab the first one. */ binding = free_binding_nodes; /* And update the free list. */ free_binding_nodes = TREE_CHAIN (free_binding_nodes); } /* Now, fill in the binding information. */ BINDING_VALUE (binding) = decl; BINDING_TYPE (binding) = NULL_TREE; BINDING_LEVEL (binding) = level; INHERITED_VALUE_BINDING_P (binding) = 0; LOCAL_BINDING_P (binding) = (level != class_binding_level); /* And put it on the front of the list of bindings for ID. */ TREE_CHAIN (binding) = IDENTIFIER_BINDING (id); IDENTIFIER_BINDING (id) = binding; } /* ID is already bound in the current scope. But, DECL is an additional binding for ID in the same scope. This is the `struct stat' hack whereby a non-typedef class-name or enum-name can be bound at the same level as some other kind of entity. It's the responsibility of the caller to check that inserting this name is legal here. Returns nonzero if the new binding was successful. */ static int add_binding (id, decl) tree id; tree decl; { tree binding = IDENTIFIER_BINDING (id); int ok = 1; if (TREE_CODE (decl) == TYPE_DECL && DECL_ARTIFICIAL (decl)) /* The new name is the type name. */ BINDING_TYPE (binding) = decl; else if (!BINDING_VALUE (binding)) /* This situation arises when push_class_level_binding moves an inherited type-binding out of the way to make room for a new value binding. */ BINDING_VALUE (binding) = decl; else if (TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL && DECL_ARTIFICIAL (BINDING_VALUE (binding))) { /* The old binding was a type name. It was placed in BINDING_VALUE because it was thought, at the point it was declared, to be the only entity with such a name. Move the type name into the type slot; it is now hidden by the new binding. */ BINDING_TYPE (binding) = BINDING_VALUE (binding); BINDING_VALUE (binding) = decl; INHERITED_VALUE_BINDING_P (binding) = 0; } else { cp_error ("declaration of `%#D'", decl); cp_error_at ("conflicts with previous declaration `%#D'", BINDING_VALUE (binding)); ok = 0; } return ok; } /* Bind DECL to ID in the current_binding_level. If PUSH_USING is set in FLAGS, we know that DECL doesn't really belong to this binding level, that it got here through a using-declaration. */ void push_local_binding (id, decl, flags) tree id; tree decl; int flags; { struct binding_level *b; /* Skip over any local classes. This makes sense if we call push_local_binding with a friend decl of a local class. */ b = current_binding_level; while (b->parm_flag == 2) b = b->level_chain; if (lookup_name_current_level (id)) { /* Supplement the existing binding. */ if (!add_binding (id, decl)) /* It didn't work. Something else must be bound at this level. Do not add DECL to the list of things to pop later. */ return; } else /* Create a new binding. */ push_binding (id, decl, b); if (TREE_CODE (decl) == OVERLOAD || (flags & PUSH_USING)) /* We must put the OVERLOAD into a TREE_LIST since the TREE_CHAIN of an OVERLOAD is already used. Similarly for decls that got here through a using-declaration. */ decl = build_tree_list (NULL_TREE, decl); /* And put DECL on the list of things declared by the current binding level. */ TREE_CHAIN (decl) = b->names; b->names = decl; } /* Bind DECL to ID in the class_binding_level. Returns nonzero if the binding was successful. */ int push_class_binding (id, decl) tree id; tree decl; { int result = 1; tree binding = IDENTIFIER_BINDING (id); tree context; /* Note that we declared this value so that we can issue an error if this an illegal redeclaration of a name already used for some other purpose. */ note_name_declared_in_class (id, decl); if (binding && BINDING_LEVEL (binding) == class_binding_level) /* Supplement the existing binding. */ result = add_binding (id, decl); else /* Create a new binding. */ push_binding (id, decl, class_binding_level); /* Update the IDENTIFIER_CLASS_VALUE for this ID to be the class-level declaration. Note that we do not use DECL here because of the possibility of the `struct stat' hack; if DECL is a class-name or enum-name we might prefer a field-name, or some such. */ IDENTIFIER_CLASS_VALUE (id) = BINDING_VALUE (IDENTIFIER_BINDING (id)); /* If this is a binding from a base class, mark it as such. */ binding = IDENTIFIER_BINDING (id); if (BINDING_VALUE (binding) == decl && TREE_CODE (decl) != TREE_LIST) { /* Any implicit typename must be from a base-class. The context for an implicit typename declaration is always the derived class in which the lookup was done, so the checks based on the context of DECL below will not trigger. */ if (TREE_CODE (decl) == TYPE_DECL && IMPLICIT_TYPENAME_P (TREE_TYPE (decl))) INHERITED_VALUE_BINDING_P (binding) = 1; else { if (TREE_CODE (decl) == OVERLOAD) context = DECL_REAL_CONTEXT (OVL_CURRENT (decl)); else { my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd', 0); context = DECL_REAL_CONTEXT (decl); } if (is_properly_derived_from (current_class_type, context)) INHERITED_VALUE_BINDING_P (binding) = 1; else INHERITED_VALUE_BINDING_P (binding) = 0; } } else if (BINDING_VALUE (binding) == decl) /* We only encounter a TREE_LIST when push_class_decls detects an ambiguity. Such an ambiguity can be overridden by a definition in this class. */ INHERITED_VALUE_BINDING_P (binding) = 1; return result; } /* Remove the binding for DECL which should be the innermost binding for ID. */ static void pop_binding (id, decl) tree id; tree decl; { tree binding; if (id == NULL_TREE) /* It's easiest to write the loops that call this function without checking whether or not the entities involved have names. We get here for such an entity. */ return; /* Get the innermost binding for ID. */ binding = IDENTIFIER_BINDING (id); /* The name should be bound. */ my_friendly_assert (binding != NULL_TREE, 0); /* The DECL will be either the ordinary binding or the type binding for this identifier. Remove that binding. */ if (BINDING_VALUE (binding) == decl) BINDING_VALUE (binding) = NULL_TREE; else if (BINDING_TYPE (binding) == decl) BINDING_TYPE (binding) = NULL_TREE; else my_friendly_abort (0); if (!BINDING_VALUE (binding) && !BINDING_TYPE (binding)) { /* We're completely done with the innermost binding for this identifier. Unhook it from the list of bindings. */ IDENTIFIER_BINDING (id) = TREE_CHAIN (binding); /* And place it on the free list. */ TREE_CHAIN (binding) = free_binding_nodes; free_binding_nodes = binding; } } /* Exit a binding level. Pop the level off, and restore the state of the identifier-decl mappings that were in effect when this level was entered. If KEEP == 1, this level had explicit declarations, so and create a "block" (a BLOCK node) for the level to record its declarations and subblocks for symbol table output. If FUNCTIONBODY is nonzero, this level is the body of a function, so create a block as if KEEP were set and also clear out all label names. If REVERSE is nonzero, reverse the order of decls before putting them into the BLOCK. */ tree poplevel (keep, reverse, functionbody) int keep; int reverse; int functionbody; { register tree link; /* The chain of decls was accumulated in reverse order. Put it into forward order, just for cleanliness. */ tree decls; int tmp = functionbody; int real_functionbody = current_binding_level->keep == 2 ? ((functionbody = 0), tmp) : functionbody; tree tags = functionbody >= 0 ? current_binding_level->tags : 0; tree subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; tree block = NULL_TREE; tree decl; int block_previously_created; int leaving_for_scope; if (current_binding_level->parm_flag == 2) return poplevel_class (); my_friendly_assert (!current_binding_level->class_shadowed, 19990414); /* We used to use KEEP == 2 to indicate that the new block should go at the beginning of the list of blocks at this binding level, rather than the end. This hack is no longer used. */ my_friendly_assert (keep == 0 || keep == 1, 0); GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, (HOST_WIDE_INT) current_binding_level->level_chain, current_binding_level->parm_flag, current_binding_level->keep); if (current_binding_level->keep == 1) keep = 1; /* Get the decls in the order they were written. Usually current_binding_level->names is in reverse order. But parameter decls were previously put in forward order. */ if (reverse) current_binding_level->names = decls = nreverse (current_binding_level->names); else decls = current_binding_level->names; /* Output any nested inline functions within this block if they weren't already output. */ for (decl = decls; decl; decl = TREE_CHAIN (decl)) if (TREE_CODE (decl) == FUNCTION_DECL && ! TREE_ASM_WRITTEN (decl) && DECL_INITIAL (decl) != NULL_TREE && TREE_ADDRESSABLE (decl) && decl_function_context (decl) == current_function_decl) { /* If this decl was copied from a file-scope decl on account of a block-scope extern decl, propagate TREE_ADDRESSABLE to the file-scope decl. */ if (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE) TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1; else { push_function_context (); output_inline_function (decl); pop_function_context (); } } /* If there were any declarations or structure tags in that level, or if this level is a function body, create a BLOCK to record them for the life of this function. */ block = NULL_TREE; block_previously_created = (current_binding_level->this_block != NULL_TREE); if (block_previously_created) block = current_binding_level->this_block; else if (keep == 1 || functionbody) block = make_node (BLOCK); if (block != NULL_TREE) { if (block_previously_created) { if (decls || tags || subblocks) { if (BLOCK_VARS (block) || BLOCK_TYPE_TAGS (block)) warning ("internal compiler error: debugging info corrupted"); BLOCK_VARS (block) = decls; BLOCK_TYPE_TAGS (block) = tags; /* We can have previous subblocks and new subblocks when doing fixup_gotos with complex cleanups. We chain the new subblocks onto the end of any pre-existing subblocks. */ BLOCK_SUBBLOCKS (block) = chainon (BLOCK_SUBBLOCKS (block), subblocks); } /* If we created the block earlier on, and we are just diddling it now, then it already should have a proper BLOCK_END_NOTE value associated with it. */ } else { BLOCK_VARS (block) = decls; BLOCK_TYPE_TAGS (block) = tags; BLOCK_SUBBLOCKS (block) = subblocks; /* Otherwise, for a new block, install a new BLOCK_END_NOTE value. */ remember_end_note (block); } } /* In each subblock, record that this is its superior. */ if (keep >= 0) for (link = subblocks; link; link = TREE_CHAIN (link)) BLOCK_SUPERCONTEXT (link) = block; /* We still support the old for-scope rules, whereby the variables in a for-init statement were in scope after the for-statement ended. We only use the new rules in flag_new_for_scope is nonzero. */ leaving_for_scope = current_binding_level->is_for_scope && flag_new_for_scope == 1; /* Remove declarations for all the DECLs in this level. */ for (link = decls; link; link = TREE_CHAIN (link)) { if (leaving_for_scope && TREE_CODE (link) == VAR_DECL) { tree outer_binding = TREE_CHAIN (IDENTIFIER_BINDING (DECL_NAME (link))); tree ns_binding; if (!outer_binding) ns_binding = IDENTIFIER_NAMESPACE_VALUE (DECL_NAME (link)); else ns_binding = NULL_TREE; if (outer_binding && (BINDING_LEVEL (outer_binding) == current_binding_level->level_chain)) /* We have something like: int i; for (int i; ;); and we are leaving the `for' scope. There's no reason to keep the binding of the inner `i' in this case. */ pop_binding (DECL_NAME (link), link); else if ((outer_binding && (TREE_CODE (BINDING_VALUE (outer_binding)) == TYPE_DECL)) || (ns_binding && TREE_CODE (ns_binding) == TYPE_DECL)) /* Here, we have something like: typedef int I; void f () { for (int I; ;); } We must pop the for-scope binding so we know what's a type and what isn't. */ pop_binding (DECL_NAME (link), link); else { /* Mark this VAR_DECL as dead so that we can tell we left it there only for backward compatibility. */ DECL_DEAD_FOR_LOCAL (link) = 1; /* Keep track of what should of have happenned when we popped the binding. */ if (outer_binding && BINDING_VALUE (outer_binding)) DECL_SHADOWED_FOR_VAR (link) = BINDING_VALUE (outer_binding); /* Add it to the list of dead variables in the next outermost binding to that we can remove these when we leave that binding. */ current_binding_level->level_chain->dead_vars_from_for = tree_cons (NULL_TREE, link, current_binding_level->level_chain-> dead_vars_from_for); /* Although we don't pop the CPLUS_BINDING, we do clear its BINDING_LEVEL since the level is going away now. */ BINDING_LEVEL (IDENTIFIER_BINDING (DECL_NAME (link))) = 0; } } else { /* Remove the binding. */ decl = link; if (TREE_CODE (decl) == TREE_LIST) decl = TREE_VALUE (decl); if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd') pop_binding (DECL_NAME (decl), decl); else if (TREE_CODE (decl) == OVERLOAD) pop_binding (DECL_NAME (OVL_FUNCTION (decl)), decl); else my_friendly_abort (0); } } /* Remove declarations for any `for' variables from inner scopes that we kept around. */ for (link = current_binding_level->dead_vars_from_for; link; link = TREE_CHAIN (link)) pop_binding (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link)); /* Restore the IDENTIFIER_TYPE_VALUEs. */ for (link = current_binding_level->type_shadowed; link; link = TREE_CHAIN (link)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link)); /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs list if a `using' declaration put them there. The debugging back-ends won't understand OVERLOAD, so we remove them here. Because the BLOCK_VARS are (temporarily) shared with CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have popped all the bindings. */ if (block) { tree* d; for (d = &BLOCK_VARS (block); *d; ) { if (TREE_CODE (*d) == TREE_LIST) *d = TREE_CHAIN (*d); else d = &TREE_CHAIN (*d); } } /* If the level being exited is the top level of a function, check over all the labels. */ if (functionbody) { /* If this is the top level block of a function, the vars are the function's parameters. Don't leave them in the BLOCK because they are found in the FUNCTION_DECL instead. */ BLOCK_VARS (block) = 0; /* Clear out the definitions of all label names, since their scopes end here. */ for (link = named_labels; link; link = TREE_CHAIN (link)) { register tree label = TREE_VALUE (link); if (DECL_INITIAL (label) == NULL_TREE) { cp_error_at ("label `%D' used but not defined", label); /* Avoid crashing later. */ define_label (input_filename, 1, DECL_NAME (label)); } else if (warn_unused && !TREE_USED (label)) cp_warning_at ("label `%D' defined but not used", label); SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), NULL_TREE); /* Put the labels into the "variables" of the top-level block, so debugger can see them. */ TREE_CHAIN (label) = BLOCK_VARS (block); BLOCK_VARS (block) = label; } named_labels = NULL_TREE; } /* Any uses of undefined labels now operate under constraints of next binding contour. */ { struct binding_level *level_chain; level_chain = current_binding_level->level_chain; if (level_chain) { struct named_label_list *labels; for (labels = named_label_uses; labels; labels = labels->next) if (labels->binding_level == current_binding_level) { labels->binding_level = level_chain; labels->names_in_scope = level_chain->names; } } } tmp = current_binding_level->keep; pop_binding_level (); if (functionbody) DECL_INITIAL (current_function_decl) = block; else if (block) { if (!block_previously_created) current_binding_level->blocks = chainon (current_binding_level->blocks, block); } /* If we did not make a block for the level just exited, any blocks made for inner levels (since they cannot be recorded as subblocks in that level) must be carried forward so they will later become subblocks of something else. */ else if (subblocks) current_binding_level->blocks = chainon (current_binding_level->blocks, subblocks); /* Take care of compiler's internal binding structures. */ if (tmp == 2) { expand_end_bindings (getdecls (), keep, 1); /* Each and every BLOCK node created here in `poplevel' is important (e.g. for proper debugging information) so if we created one earlier, mark it as "used". */ if (block) TREE_USED (block) = 1; block = poplevel (keep, reverse, real_functionbody); } /* Each and every BLOCK node created here in `poplevel' is important (e.g. for proper debugging information) so if we created one earlier, mark it as "used". */ if (block) TREE_USED (block) = 1; return block; } /* Delete the node BLOCK from the current binding level. This is used for the block inside a stmt expr ({...}) so that the block can be reinserted where appropriate. */ void delete_block (block) tree block; { tree t; if (current_binding_level->blocks == block) current_binding_level->blocks = TREE_CHAIN (block); for (t = current_binding_level->blocks; t;) { if (TREE_CHAIN (t) == block) TREE_CHAIN (t) = TREE_CHAIN (block); else t = TREE_CHAIN (t); } TREE_CHAIN (block) = NULL_TREE; /* Clear TREE_USED which is always set by poplevel. The flag is set again if insert_block is called. */ TREE_USED (block) = 0; } /* Insert BLOCK at the end of the list of subblocks of the current binding level. This is used when a BIND_EXPR is expanded, to handle the BLOCK node inside the BIND_EXPR. */ void insert_block (block) tree block; { TREE_USED (block) = 1; current_binding_level->blocks = chainon (current_binding_level->blocks, block); } /* Set the BLOCK node for the innermost scope (the one we are currently in). */ void set_block (block) register tree block; { current_binding_level->this_block = block; } /* Do a pushlevel for class declarations. */ void pushlevel_class () { register struct binding_level *newlevel; /* Reuse or create a struct for this binding level. */ #if defined(DEBUG_CP_BINDING_LEVELS) if (0) #else /* !defined(DEBUG_CP_BINDING_LEVELS) */ if (free_binding_level) #endif /* !defined(DEBUG_CP_BINDING_LEVELS) */ { newlevel = free_binding_level; free_binding_level = free_binding_level->level_chain; } else newlevel = make_binding_level (); #if defined(DEBUG_CP_BINDING_LEVELS) is_class_level = 1; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ push_binding_level (newlevel, 0, 0); decl_stack = push_decl_level (decl_stack, &decl_obstack); class_binding_level = current_binding_level; class_binding_level->parm_flag = 2; } /* ...and a poplevel for class declarations. */ static tree poplevel_class () { register struct binding_level *level = class_binding_level; tree shadowed; my_friendly_assert (level != 0, 354); decl_stack = pop_stack_level (decl_stack); /* If we're leaving a toplevel class, don't bother to do the setting of IDENTIFIER_CLASS_VALUE to NULL_TREE, since first of all this slot shouldn't even be used when current_class_type isn't set, and second, if we don't touch it here, we're able to use the cache effect if the next time we're entering a class scope, it is the same class. */ if (current_class_depth != 1) { struct binding_level* b; /* Clear out our IDENTIFIER_CLASS_VALUEs. */ for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = NULL_TREE; /* Find the next enclosing class, and recreate IDENTIFIER_CLASS_VALUEs appropriate for that class. */ b = level->level_chain; while (b && b->parm_flag != 2) b = b->level_chain; if (b) for (shadowed = b->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) { tree t; t = IDENTIFIER_BINDING (TREE_PURPOSE (shadowed)); while (t && BINDING_LEVEL (t) != b) t = TREE_CHAIN (t); if (t) IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (shadowed)) = BINDING_VALUE (t); } } else /* Remember to save what IDENTIFIER's were bound in this scope so we can recover from cache misses. */ { previous_class_type = current_class_type; previous_class_values = class_binding_level->class_shadowed; } for (shadowed = level->type_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (shadowed), TREE_VALUE (shadowed)); /* Remove the bindings for all of the class-level declarations. */ for (shadowed = level->class_shadowed; shadowed; shadowed = TREE_CHAIN (shadowed)) pop_binding (TREE_PURPOSE (shadowed), TREE_TYPE (shadowed)); GNU_xref_end_scope ((HOST_WIDE_INT) class_binding_level, (HOST_WIDE_INT) class_binding_level->level_chain, class_binding_level->parm_flag, class_binding_level->keep); /* Now, pop out of the binding level which we created up in the `pushlevel_class' routine. */ #if defined(DEBUG_CP_BINDING_LEVELS) is_class_level = 1; #endif /* defined(DEBUG_CP_BINDING_LEVELS) */ pop_binding_level (); return NULL_TREE; } /* We are entering the scope of a class. Clear IDENTIFIER_CLASS_VALUE for any names in enclosing classes. */ void clear_identifier_class_values () { tree t; if (!class_binding_level) return; for (t = class_binding_level->class_shadowed; t; t = TREE_CHAIN (t)) IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE; } /* Returns non-zero if T is a virtual function table. */ int vtable_decl_p (t, data) tree t; void *data ATTRIBUTE_UNUSED; { return (TREE_CODE (t) == VAR_DECL && DECL_VIRTUAL_P (t)); } /* Returns non-zero if T is a TYPE_DECL for a type with virtual functions. */ int vtype_decl_p (t, data) tree t; void *data ATTRIBUTE_UNUSED; { return (TREE_CODE (t) == TYPE_DECL && TREE_TYPE (t) != error_mark_node && TYPE_LANG_SPECIFIC (TREE_TYPE (t)) && CLASSTYPE_VSIZE (TREE_TYPE (t))); } /* Returns non-zero if T is a signature table. */ int sigtable_decl_p (t, data) tree t; void *data ATTRIBUTE_UNUSED; { return (TREE_CODE (t) == VAR_DECL && TREE_TYPE (t) != error_mark_node && IS_SIGNATURE (TREE_TYPE (t))); } /* Walk all the namespaces contained NAMESPACE, including NAMESPACE itself, calling F for each. The DATA is passed to F as well. */ static int walk_namespaces_r (namespace, f, data) tree namespace; walk_namespaces_fn f; void *data; { tree current; int result = 0; result |= (*f) (namespace, data); for (current = NAMESPACE_LEVEL (namespace)->names; current; current = TREE_CHAIN (current)) { if (TREE_CODE (current) != NAMESPACE_DECL || DECL_NAMESPACE_ALIAS (current)) continue; if (!DECL_LANG_SPECIFIC (current)) { /* Hmm. std. */ my_friendly_assert (current == std_node, 393); continue; } /* We found a namespace. */ result |= walk_namespaces_r (current, f, data); } return result; } /* Walk all the namespaces, calling F for each. The DATA is passed to F as well. */ int walk_namespaces (f, data) walk_namespaces_fn f; void *data; { return walk_namespaces_r (global_namespace, f, data); } struct walk_globals_data { walk_globals_pred p; walk_globals_fn f; void *data; }; /* Walk the global declarations in NAMESPACE. Whenever one is found for which P returns non-zero, call F with its address. If any call to F returns a non-zero value, return a non-zero value. */ static int walk_globals_r (namespace, data) tree namespace; void *data; { struct walk_globals_data* wgd = (struct walk_globals_data *) data; walk_globals_pred p = wgd->p; walk_globals_fn f = wgd->f; void *d = wgd->data; tree *t; int result = 0; t = &NAMESPACE_LEVEL (namespace)->names; while (*t) { tree glbl = *t; if ((*p) (glbl, d)) result |= (*f) (t, d); /* If F changed *T, then *T still points at the next item to examine. */ if (*t == glbl) t = &TREE_CHAIN (*t); } return result; } /* Walk the global declarations. Whenever one is found for which P returns non-zero, call F with its address. If any call to F returns a non-zero value, return a non-zero value. */ int walk_globals (p, f, data) walk_globals_pred p; walk_globals_fn f; void *data; { struct walk_globals_data wgd; wgd.p = p; wgd.f = f; wgd.data = data; return walk_namespaces (walk_globals_r, &wgd); } /* Call wrapup_globals_declarations for the globals in NAMESPACE. If DATA is non-NULL, this is the last time we will call wrapup_global_declarations for this NAMESPACE. */ int wrapup_globals_for_namespace (namespace, data) tree namespace; void *data; { tree globals = NAMESPACE_LEVEL (namespace)->names; int len = list_length (globals); tree *vec = (tree *) alloca (sizeof (tree) * len); int i; int result; tree decl; int last_time = (data != 0); if (last_time && namespace == global_namespace) /* Let compile_file handle the global namespace. */ return 0; /* Process the decls in reverse order--earliest first. Put them into VEC from back to front, then take out from front. */ for (i = 0, decl = globals; i < len; i++, decl = TREE_CHAIN (decl)) vec[len - i - 1] = decl; if (last_time) { check_global_declarations (vec, len); return 0; } /* Temporarily mark vtables as external. That prevents wrapup_global_declarations from writing them out; we must process them ourselves in finish_vtable_vardecl. */ for (i = 0; i < len; ++i) if (vtable_decl_p (vec[i], /*data=*/0) && !DECL_EXTERNAL (vec[i])) { DECL_NOT_REALLY_EXTERN (vec[i]) = 1; DECL_EXTERNAL (vec[i]) = 1; } /* Write out any globals that need to be output. */ result = wrapup_global_declarations (vec, len); /* Undo the hack to DECL_EXTERNAL above. */ for (i = 0; i < len; ++i) if (vtable_decl_p (vec[i], /*data=*/0) && DECL_NOT_REALLY_EXTERN (vec[i])) { DECL_NOT_REALLY_EXTERN (vec[i]) = 0; DECL_EXTERNAL (vec[i]) = 0; } return result; } /* For debugging. */ static int no_print_functions = 0; static int no_print_builtins = 0; void print_binding_level (lvl) struct binding_level *lvl; { tree t; int i = 0, len; fprintf (stderr, " blocks="); fprintf (stderr, HOST_PTR_PRINTF, (void *) lvl->blocks); fprintf (stderr, " n_incomplete=%d parm_flag=%d keep=%d", list_length (lvl->incomplete), lvl->parm_flag, lvl->keep); if (lvl->tag_transparent) fprintf (stderr, " tag-transparent"); if (lvl->more_cleanups_ok) fprintf (stderr, " more-cleanups-ok"); if (lvl->have_cleanups) fprintf (stderr, " have-cleanups"); fprintf (stderr, "\n"); if (lvl->names) { fprintf (stderr, " names:\t"); /* We can probably fit 3 names to a line? */ for (t = lvl->names; t; t = TREE_CHAIN (t)) { if (no_print_functions && (TREE_CODE (t) == FUNCTION_DECL)) continue; if (no_print_builtins && (TREE_CODE (t) == TYPE_DECL) && (!strcmp (DECL_SOURCE_FILE (t),""))) continue; /* Function decls tend to have longer names. */ if (TREE_CODE (t) == FUNCTION_DECL) len = 3; else len = 2; i += len; if (i > 6) { fprintf (stderr, "\n\t"); i = len; } print_node_brief (stderr, "", t, 0); if (t == error_mark_node) break; } if (i) fprintf (stderr, "\n"); } if (lvl->tags) { fprintf (stderr, " tags:\t"); i = 0; for (t = lvl->tags; t; t = TREE_CHAIN (t)) { if (TREE_PURPOSE (t) == NULL_TREE) len = 3; else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) len = 2; else len = 4; i += len; if (i > 5) { fprintf (stderr, "\n\t"); i = len; } if (TREE_PURPOSE (t) == NULL_TREE) { print_node_brief (stderr, ""); } else if (TREE_PURPOSE (t) == TYPE_IDENTIFIER (TREE_VALUE (t))) print_node_brief (stderr, "", TREE_VALUE (t), 0); else { print_node_brief (stderr, ""); } } if (i) fprintf (stderr, "\n"); } if (lvl->class_shadowed) { fprintf (stderr, " class-shadowed:"); for (t = lvl->class_shadowed; t; t = TREE_CHAIN (t)) { fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); } fprintf (stderr, "\n"); } if (lvl->type_shadowed) { fprintf (stderr, " type-shadowed:"); for (t = lvl->type_shadowed; t; t = TREE_CHAIN (t)) { fprintf (stderr, " %s ", IDENTIFIER_POINTER (TREE_PURPOSE (t))); } fprintf (stderr, "\n"); } } void print_other_binding_stack (stack) struct binding_level *stack; { struct binding_level *level; for (level = stack; level != global_binding_level; level = level->level_chain) { fprintf (stderr, "binding level "); fprintf (stderr, HOST_PTR_PRINTF, (void *) level); fprintf (stderr, "\n"); print_binding_level (level); } } void print_binding_stack () { struct binding_level *b; fprintf (stderr, "current_binding_level="); fprintf (stderr, HOST_PTR_PRINTF, (void *) current_binding_level); fprintf (stderr, "\nclass_binding_level="); fprintf (stderr, HOST_PTR_PRINTF, (void *) class_binding_level); fprintf (stderr, "\nglobal_binding_level="); fprintf (stderr, HOST_PTR_PRINTF, (void *) global_binding_level); fprintf (stderr, "\n"); if (class_binding_level) { for (b = class_binding_level; b; b = b->level_chain) if (b == current_binding_level) break; if (b) b = class_binding_level; else b = current_binding_level; } else b = current_binding_level; print_other_binding_stack (b); fprintf (stderr, "global:\n"); print_binding_level (global_binding_level); } /* Namespace binding access routines: The namespace_bindings field of the identifier is polymorphic, with three possible values: NULL_TREE, a list of CPLUS_BINDINGS, or any other tree_node indicating the BINDING_VALUE of global_namespace. */ /* Check whether the a binding for the name to scope is known. Assumes that the bindings of the name are already a list of bindings. Returns the binding found, or NULL_TREE. */ static tree find_binding (name, scope) tree name; tree scope; { tree iter, prev = NULL_TREE; scope = ORIGINAL_NAMESPACE (scope); for (iter = IDENTIFIER_NAMESPACE_BINDINGS (name); iter; iter = TREE_CHAIN (iter)) { my_friendly_assert (TREE_CODE (iter) == CPLUS_BINDING, 374); if (BINDING_SCOPE (iter) == scope) { /* Move binding found to the fron of the list, so subsequent lookups will find it faster. */ if (prev) { TREE_CHAIN (prev) = TREE_CHAIN (iter); TREE_CHAIN (iter) = IDENTIFIER_NAMESPACE_BINDINGS (name); IDENTIFIER_NAMESPACE_BINDINGS (name) = iter; } return iter; } prev = iter; } return NULL_TREE; } /* Always returns a binding for name in scope. If the namespace_bindings is not a list, convert it to one first. If no binding is found, make a new one. */ tree binding_for_name (name, scope) tree name; tree scope; { tree b = IDENTIFIER_NAMESPACE_BINDINGS (name); tree result; scope = ORIGINAL_NAMESPACE (scope); if (b && TREE_CODE (b) != CPLUS_BINDING) { /* Get rid of optimization for global scope. */ IDENTIFIER_NAMESPACE_BINDINGS (name) = NULL_TREE; BINDING_VALUE (binding_for_name (name, global_namespace)) = b; b = IDENTIFIER_NAMESPACE_BINDINGS (name); } if (b && (result = find_binding (name, scope))) return result; /* Not found, make a new permanent one. */ push_obstacks (&permanent_obstack, &permanent_obstack); result = make_node (CPLUS_BINDING); TREE_CHAIN (result) = b; IDENTIFIER_NAMESPACE_BINDINGS (name) = result; BINDING_SCOPE (result) = scope; BINDING_TYPE (result) = NULL_TREE; BINDING_VALUE (result) = NULL_TREE; pop_obstacks (); return result; } /* Return the binding value for name in scope, considering that namespace_binding may or may not be a list of CPLUS_BINDINGS. */ tree namespace_binding (name, scope) tree name; tree scope; { tree b = IDENTIFIER_NAMESPACE_BINDINGS (name); if (b == NULL_TREE) return NULL_TREE; if (scope == NULL_TREE) scope = global_namespace; if (TREE_CODE (b) != CPLUS_BINDING) return (scope == global_namespace) ? b : NULL_TREE; name = find_binding (name,scope); if (name == NULL_TREE) return name; return BINDING_VALUE (name); } /* Set the binding value for name in scope. If modifying the binding of global_namespace is attempted, try to optimize it. */ void set_namespace_binding (name, scope, val) tree name; tree scope; tree val; { tree b; if (scope == NULL_TREE) scope = global_namespace; if (scope == global_namespace) { b = IDENTIFIER_NAMESPACE_BINDINGS (name); if (b == NULL_TREE || TREE_CODE (b) != CPLUS_BINDING) { IDENTIFIER_NAMESPACE_BINDINGS (name) = val; return; } } b = binding_for_name (name, scope); BINDING_VALUE (b) = val; } /* Push into the scope of the NAME namespace. If NAME is NULL_TREE, then we select a name that is unique to this compilation unit. */ void push_namespace (name) tree name; { tree d = NULL_TREE; int need_new = 1; int implicit_use = 0; int global = 0; if (!global_namespace) { /* This must be ::. */ my_friendly_assert (name == get_identifier ("::"), 377); global = 1; } else if (!name) { /* The name of anonymous namespace is unique for the translation unit. */ if (!anonymous_namespace_name) anonymous_namespace_name = get_file_function_name ('N'); name = anonymous_namespace_name; d = IDENTIFIER_NAMESPACE_VALUE (name); if (d) /* Reopening anonymous namespace. */ need_new = 0; implicit_use = 1; } else if (current_namespace == global_namespace && name == DECL_NAME (std_node)) { in_std++; return; } else { /* Check whether this is an extended namespace definition. */ d = IDENTIFIER_NAMESPACE_VALUE (name); if (d != NULL_TREE && TREE_CODE (d) == NAMESPACE_DECL) { need_new = 0; if (DECL_NAMESPACE_ALIAS (d)) { cp_error ("namespace alias `%D' not allowed here, assuming `%D'", d, DECL_NAMESPACE_ALIAS (d)); d = DECL_NAMESPACE_ALIAS (d); } } } if (need_new) { /* Make a new namespace, binding the name to it. */ d = build_lang_decl (NAMESPACE_DECL, name, void_type_node); /* The global namespace is not pushed, and the global binding level is set elsewhere. */ if (!global) { d = pushdecl (d); pushlevel (0); declare_namespace_level (); NAMESPACE_LEVEL (d) = current_binding_level; } } else resume_binding_level (NAMESPACE_LEVEL (d)); if (implicit_use) do_using_directive (d); /* Enter the name space. */ current_namespace = d; } /* Pop from the scope of the current namespace. */ void pop_namespace () { if (current_namespace == global_namespace) { my_friendly_assert (in_std>0, 980421); in_std--; return; } current_namespace = CP_DECL_CONTEXT (current_namespace); /* The binding level is not popped, as it might be re-opened later. */ suspend_binding_level (); } /* Subroutines for reverting temporarily to top-level for instantiation of templates and such. We actually need to clear out the class- and local-value slots of all identifiers, so that only the global values are at all visible. Simply setting current_binding_level to the global scope isn't enough, because more binding levels may be pushed. */ struct saved_scope { struct binding_level *old_binding_level; tree old_bindings; tree old_namespace; struct saved_scope *prev; tree class_name, class_type; tree access_specifier; tree function_decl; struct binding_level *class_bindings; tree *lang_base, *lang_stack, lang_name; int lang_stacksize; int minimal_parse_mode; tree last_function_parms; tree template_parms; HOST_WIDE_INT processing_template_decl; tree previous_class_type, previous_class_values; int processing_specialization; int processing_explicit_instantiation; char *class_cache_firstobj; }; static struct saved_scope *current_saved_scope; /* A chain of the binding vecs created by store_bindings. We create a whole bunch of these during compilation, on permanent_obstack, so we can't just throw them away. */ static tree free_binding_vecs; static tree store_bindings (names, old_bindings) tree names, old_bindings; { tree t; for (t = names; t; t = TREE_CHAIN (t)) { tree binding, t1, id; if (TREE_CODE (t) == TREE_LIST) id = TREE_PURPOSE (t); else id = DECL_NAME (t); if (!id /* Note that we may have an IDENTIFIER_CLASS_VALUE even when we have no IDENTIFIER_BINDING if we have left the class scope, but cached the class-level declarations. */ || !(IDENTIFIER_BINDING (id) || IDENTIFIER_CLASS_VALUE (id))) continue; for (t1 = old_bindings; t1; t1 = TREE_CHAIN (t1)) if (TREE_VEC_ELT (t1, 0) == id) goto skip_it; if (free_binding_vecs) { binding = free_binding_vecs; free_binding_vecs = TREE_CHAIN (free_binding_vecs); } else binding = make_tree_vec (4); if (id) { my_friendly_assert (TREE_CODE (id) == IDENTIFIER_NODE, 135); TREE_VEC_ELT (binding, 0) = id; TREE_VEC_ELT (binding, 1) = REAL_IDENTIFIER_TYPE_VALUE (id); TREE_VEC_ELT (binding, 2) = IDENTIFIER_BINDING (id); TREE_VEC_ELT (binding, 3) = IDENTIFIER_CLASS_VALUE (id); IDENTIFIER_BINDING (id) = NULL_TREE; IDENTIFIER_CLASS_VALUE (id) = NULL_TREE; } TREE_CHAIN (binding) = old_bindings; old_bindings = binding; skip_it: ; } return old_bindings; } void maybe_push_to_top_level (pseudo) int pseudo; { extern int current_lang_stacksize; struct saved_scope *s = (struct saved_scope *) xmalloc (sizeof (struct saved_scope)); struct binding_level *b = current_binding_level; tree old_bindings = NULL_TREE; push_cp_function_context (NULL_TREE); if (previous_class_type) old_bindings = store_bindings (previous_class_values, old_bindings); /* Have to include global_binding_level, because class-level decls aren't listed anywhere useful. */ for (; b; b = b->level_chain) { tree t; /* Template IDs are inserted into the global level. If they were inserted into namespace level, finish_file wouldn't find them when doing pending instantiations. Therefore, don't stop at namespace level, but continue until :: . */ if (b == global_binding_level || (pseudo && b->pseudo_global)) break; old_bindings = store_bindings (b->names, old_bindings); /* We also need to check class_shadowed to save class-level type bindings, since pushclass doesn't fill in b->names. */ if (b->parm_flag == 2) old_bindings = store_bindings (b->class_shadowed, old_bindings); /* Unwind type-value slots back to top level. */ for (t = b->type_shadowed; t; t = TREE_CHAIN (t)) SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (t), TREE_VALUE (t)); } s->old_binding_level = current_binding_level; current_binding_level = b; s->old_namespace = current_namespace; s->class_name = current_class_name; s->class_type = current_class_type; s->access_specifier = current_access_specifier; s->function_decl = current_function_decl; s->class_bindings = class_binding_level; s->lang_stack = current_lang_stack; s->lang_base = current_lang_base; s->lang_stacksize = current_lang_stacksize; s->lang_name = current_lang_name; s->minimal_parse_mode = minimal_parse_mode; s->last_function_parms = last_function_parms; s->template_parms = current_template_parms; s->processing_template_decl = processing_template_decl; s->previous_class_type = previous_class_type; s->previous_class_values = previous_class_values; s->class_cache_firstobj = class_cache_firstobj; s->processing_specialization = processing_specialization; s->processing_explicit_instantiation = processing_explicit_instantiation; current_class_name = current_class_type = NULL_TREE; current_function_decl = NULL_TREE; class_binding_level = (struct binding_level *)0; current_lang_stacksize = 10; current_lang_stack = current_lang_base = (tree *) xmalloc (current_lang_stacksize * sizeof (tree)); current_lang_name = lang_name_cplusplus; strict_prototype = strict_prototypes_lang_cplusplus; named_labels = NULL_TREE; shadowed_labels = NULL_TREE; minimal_parse_mode = 0; previous_class_type = previous_class_values = NULL_TREE; class_cache_firstobj = 0; processing_specialization = 0; processing_explicit_instantiation = 0; current_template_parms = NULL_TREE; processing_template_decl = 0; current_namespace = global_namespace; s->prev = current_saved_scope; s->old_bindings = old_bindings; current_saved_scope = s; push_obstacks (&permanent_obstack, &permanent_obstack); } void push_to_top_level () { maybe_push_to_top_level (0); } void pop_from_top_level () { extern int current_lang_stacksize; struct saved_scope *s = current_saved_scope; tree t; /* Clear out class-level bindings cache. */ if (previous_class_type) invalidate_class_lookup_cache (); pop_obstacks (); current_binding_level = s->old_binding_level; current_saved_scope = s->prev; for (t = s->old_bindings; t; ) { tree save = t; tree id = TREE_VEC_ELT (t, 0); if (id) { SET_IDENTIFIER_TYPE_VALUE (id, TREE_VEC_ELT (t, 1)); IDENTIFIER_BINDING (id) = TREE_VEC_ELT (t, 2); IDENTIFIER_CLASS_VALUE (id) = TREE_VEC_ELT (t, 3); } t = TREE_CHAIN (t); TREE_CHAIN (save) = free_binding_vecs; free_binding_vecs = save; } current_namespace = s->old_namespace; current_class_name = s->class_name; current_class_type = s->class_type; current_access_specifier = s->access_specifier; current_function_decl = s->function_decl; class_binding_level = s->class_bindings; free (current_lang_base); current_lang_base = s->lang_base; current_lang_stack = s->lang_stack; current_lang_name = s->lang_name; current_lang_stacksize = s->lang_stacksize; if (current_lang_name == lang_name_cplusplus) strict_prototype = strict_prototypes_lang_cplusplus; else if (current_lang_name == lang_name_c) strict_prototype = strict_prototypes_lang_c; minimal_parse_mode = s->minimal_parse_mode; last_function_parms = s->last_function_parms; current_template_parms = s->template_parms; processing_template_decl = s->processing_template_decl; previous_class_type = s->previous_class_type; previous_class_values = s->previous_class_values; processing_specialization = s->processing_specialization; processing_explicit_instantiation = s->processing_explicit_instantiation; class_cache_firstobj = s->class_cache_firstobj; free (s); pop_cp_function_context (NULL_TREE); } /* Push a definition of struct, union or enum tag "name". into binding_level "b". "type" should be the type node, We assume that the tag "name" is not already defined. Note that the definition may really be just a forward reference. In that case, the TYPE_SIZE will be a NULL_TREE. C++ gratuitously puts all these tags in the name space. */ /* When setting the IDENTIFIER_TYPE_VALUE field of an identifier ID, record the shadowed value for this binding contour. TYPE is the type that ID maps to. */ static void set_identifier_type_value_with_scope (id, type, b) tree id; tree type; struct binding_level *b; { if (!b->namespace_p) { /* Shadow the marker, not the real thing, so that the marker gets restored later. */ tree old_type_value = REAL_IDENTIFIER_TYPE_VALUE (id); b->type_shadowed = tree_cons (id, old_type_value, b->type_shadowed); } else { tree binding = binding_for_name (id, current_namespace); BINDING_TYPE (binding) = type; /* Store marker instead of real type. */ type = global_type_node; } SET_IDENTIFIER_TYPE_VALUE (id, type); } /* As set_identifier_type_value_with_scope, but using current_binding_level. */ void set_identifier_type_value (id, type) tree id; tree type; { set_identifier_type_value_with_scope (id, type, current_binding_level); } /* Return the type associated with id. */ tree identifier_type_value (id) tree id; { /* There is no type with that name, anywhere. */ if (REAL_IDENTIFIER_TYPE_VALUE (id) == NULL_TREE) return NULL_TREE; /* This is not the type marker, but the real thing. */ if (REAL_IDENTIFIER_TYPE_VALUE (id) != global_type_node) return REAL_IDENTIFIER_TYPE_VALUE (id); /* Have to search for it. It must be on the global level, now. Ask lookup_name not to return non-types. */ id = lookup_name_real (id, 2, 1, 0); if (id) return TREE_TYPE (id); return NULL_TREE; } /* Pop off extraneous binding levels left over due to syntax errors. We don't pop past namespaces, as they might be valid. */ void pop_everything () { #ifdef DEBUG_CP_BINDING_LEVELS fprintf (stderr, "XXX entering pop_everything ()\n"); #endif while (!toplevel_bindings_p ()) { if (current_binding_level->parm_flag == 2) pop_nested_class (); else poplevel (0, 0, 0); } #ifdef DEBUG_CP_BINDING_LEVELS fprintf (stderr, "XXX leaving pop_everything ()\n"); #endif } /* The type TYPE is being declared. If it is a class template, or a specialization of a class template, do any processing required and perform error-checking. If IS_FRIEND is non-zero, this TYPE is being declared a friend. B is the binding level at which this TYPE should be bound. Returns the TYPE_DECL for TYPE, which may have been altered by this processing. */ static tree maybe_process_template_type_declaration (type, globalize, b) tree type; int globalize; struct binding_level* b; { tree decl = TYPE_NAME (type); if (processing_template_parmlist) /* You can't declare a new template type in a template parameter list. But, you can declare a non-template type: template struct S; is a forward-declaration of `A'. */ ; else { maybe_check_template_type (type); my_friendly_assert (IS_AGGR_TYPE (type) || TREE_CODE (type) == ENUMERAL_TYPE, 0); if (/* If !GLOBALIZE then we are looking at a definition. It may not be a primary template. (For example, in: template struct S1 { class S2 {}; } we have to push_template_decl for S2.) */ (processing_template_decl && !globalize) /* If we are declaring a friend template class, we will have GLOBALIZE set, since something like: template struct S1 { template friend class S2; }; declares S2 to be at global scope. */ || PROCESSING_REAL_TEMPLATE_DECL_P ()) { /* This may change after the call to push_template_decl_real, but we want the original value. */ tree name = DECL_NAME (decl); decl = push_template_decl_real (decl, globalize); /* If the current binding level is the binding level for the template parameters (see the comment in begin_template_parm_list) and the enclosing level is a class scope, and we're not looking at a friend, push the declaration of the member class into the class scope. In the friend case, push_template_decl will already have put the friend into global scope, if appropriate. */ if (TREE_CODE (type) != ENUMERAL_TYPE && !globalize && b->pseudo_global && b->level_chain->parm_flag == 2) { finish_member_declaration (CLASSTYPE_TI_TEMPLATE (type)); /* Put this tag on the list of tags for the class, since that won't happen below because B is not the class binding level, but is instead the pseudo-global level. */ b->level_chain->tags = saveable_tree_cons (name, type, b->level_chain->tags); if (TYPE_SIZE (current_class_type) == NULL_TREE) CLASSTYPE_TAGS (current_class_type) = b->level_chain->tags; } } } return decl; } /* Push a tag name NAME for struct/class/union/enum type TYPE. Normally put it into the inner-most non-tag-transparent scope, but if GLOBALIZE is true, put it in the inner-most non-class scope. The latter is needed for implicit declarations. */ void pushtag (name, type, globalize) tree name, type; int globalize; { register struct binding_level *b; b = current_binding_level; while (b->tag_transparent || (globalize && b->parm_flag == 2)) b = b->level_chain; if (toplevel_bindings_p ()) b->tags = perm_tree_cons (name, type, b->tags); else b->tags = saveable_tree_cons (name, type, b->tags); if (name) { /* Do C++ gratuitous typedefing. */ if (IDENTIFIER_TYPE_VALUE (name) != type) { register tree d = NULL_TREE; int newdecl = 0, in_class = 0; tree context; tree c_decl = NULL_TREE; context = type ? TYPE_CONTEXT (type) : NULL_TREE; if (! context) { tree cs = current_scope (); if (! globalize) context = cs; else if (cs != NULL_TREE && TREE_CODE_CLASS (TREE_CODE (cs)) == 't') /* When declaring a friend class of a local class, we want to inject the newly named class into the scope containing the local class, not the namespace scope. */ context = hack_decl_function_context (get_type_decl (cs)); } if (context) c_decl = TREE_CODE (context) == FUNCTION_DECL ? context : TYPE_MAIN_DECL (context); if (!context) context = current_namespace; if ((b->pseudo_global && b->level_chain->parm_flag == 2) || b->parm_flag == 2) in_class = 1; else d = lookup_nested_type (type, c_decl); if (d == NULL_TREE) { newdecl = 1; d = build_decl (TYPE_DECL, name, type); if (current_lang_name == lang_name_java) TYPE_FOR_JAVA (type) = 1; SET_DECL_ARTIFICIAL (d); if (! in_class) set_identifier_type_value_with_scope (name, type, b); } else d = TYPE_MAIN_DECL (d); TYPE_NAME (type) = d; DECL_CONTEXT (d) = FROB_CONTEXT (context); d = maybe_process_template_type_declaration (type, globalize, b); if (b->parm_flag == 2) { if (newdecl && !PROCESSING_REAL_TEMPLATE_DECL_P ()) /* Put this TYPE_DECL on the TYPE_FIELDS list for the class. But if it's a member template class, we want the TEMPLATE_DECL, not the TYPE_DECL, so this is done later. */ finish_member_declaration (d); else pushdecl_class_level (d); } else d = pushdecl_with_scope (d, b); if (newdecl) { if (ANON_AGGRNAME_P (name)) DECL_IGNORED_P (d) = 1; TYPE_CONTEXT (type) = DECL_CONTEXT (d); DECL_ASSEMBLER_NAME (d) = DECL_NAME (d); if (!uses_template_parms (type)) DECL_ASSEMBLER_NAME (d) = get_identifier (build_overload_name (type, 1, 1)); } } if (b->parm_flag == 2) { if (TYPE_SIZE (current_class_type) == NULL_TREE) CLASSTYPE_TAGS (current_class_type) = b->tags; } } if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) /* Use the canonical TYPE_DECL for this node. */ TYPE_STUB_DECL (type) = TYPE_NAME (type); else { /* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the tagged type we just added to the current binding level. This fake NULL-named TYPE_DECL node helps dwarfout.c to know when it needs to output a representation of a tagged type, and it also gives us a convenient place to record the "scope start" address for the tagged type. */ tree d = build_decl (TYPE_DECL, NULL_TREE, type); TYPE_STUB_DECL (type) = pushdecl_with_scope (d, b); } } /* Counter used to create anonymous type names. */ static int anon_cnt = 0; /* Return an IDENTIFIER which can be used as a name for anonymous structs and unions. */ tree make_anon_name () { char buf[32]; sprintf (buf, ANON_AGGRNAME_FORMAT, anon_cnt++); return get_identifier (buf); } /* Clear the TREE_PURPOSE slot of tags which have anonymous typenames. This keeps dbxout from getting confused. */ void clear_anon_tags () { register struct binding_level *b; register tree tags; static int last_cnt = 0; /* Fast out if no new anon names were declared. */ if (last_cnt == anon_cnt) return; b = current_binding_level; while (b->tag_transparent) b = b->level_chain; tags = b->tags; while (tags) { /* A NULL purpose means we have already processed all tags from here to the end of the list. */ if (TREE_PURPOSE (tags) == NULL_TREE) break; if (ANON_AGGRNAME_P (TREE_PURPOSE (tags))) TREE_PURPOSE (tags) = NULL_TREE; tags = TREE_CHAIN (tags); } last_cnt = anon_cnt; } /* Subroutine of duplicate_decls: return truthvalue of whether or not types of these decls match. For C++, we must compare the parameter list so that `int' can match `int&' in a parameter position, but `int&' is not confused with `const int&'. */ int decls_match (newdecl, olddecl) tree newdecl, olddecl; { int types_match; if (newdecl == olddecl) return 1; if (TREE_CODE (newdecl) != TREE_CODE (olddecl)) /* If the two DECLs are not even the same kind of thing, we're not interested in their types. */ return 0; if (TREE_CODE (newdecl) == FUNCTION_DECL) { tree f1 = TREE_TYPE (newdecl); tree f2 = TREE_TYPE (olddecl); tree p1 = TYPE_ARG_TYPES (f1); tree p2 = TYPE_ARG_TYPES (f2); if (DECL_REAL_CONTEXT (newdecl) != DECL_REAL_CONTEXT (olddecl) && ! (DECL_LANGUAGE (newdecl) == lang_c && DECL_LANGUAGE (olddecl) == lang_c)) return 0; /* When we parse a static member function definition, we put together a FUNCTION_DECL which thinks its type is METHOD_TYPE. Change that to FUNCTION_TYPE, and proceed. */ if (TREE_CODE (f1) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (olddecl)) revert_static_member_fn (&newdecl, &f1, &p1); else if (TREE_CODE (f2) == METHOD_TYPE && DECL_STATIC_FUNCTION_P (newdecl)) revert_static_member_fn (&olddecl, &f2, &p2); /* Here we must take care of the case where new default parameters are specified. Also, warn if an old declaration becomes ambiguous because default parameters may cause the two to be ambiguous. */ if (TREE_CODE (f1) != TREE_CODE (f2)) { if (TREE_CODE (f1) == OFFSET_TYPE) cp_compiler_error ("`%D' redeclared as member function", newdecl); else cp_compiler_error ("`%D' redeclared as non-member function", newdecl); return 0; } if (same_type_p (TREE_TYPE (f1), TREE_TYPE (f2))) { if (! strict_prototypes_lang_c && DECL_LANGUAGE (olddecl) == lang_c && p2 == NULL_TREE) { types_match = self_promoting_args_p (p1); if (p1 == void_list_node) TREE_TYPE (newdecl) = TREE_TYPE (olddecl); } else if (!strict_prototypes_lang_c && DECL_LANGUAGE (olddecl)==lang_c && DECL_LANGUAGE (newdecl) == lang_c && p1 == NULL_TREE) { types_match = self_promoting_args_p (p2); TREE_TYPE (newdecl) = TREE_TYPE (olddecl); } else types_match = compparms (p1, p2); } else types_match = 0; } else if (TREE_CODE (newdecl) == TEMPLATE_DECL) { if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), DECL_TEMPLATE_PARMS (olddecl))) return 0; if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) types_match = 1; else types_match = decls_match (DECL_TEMPLATE_RESULT (olddecl), DECL_TEMPLATE_RESULT (newdecl)); } else { if (TREE_TYPE (newdecl) == error_mark_node) types_match = TREE_TYPE (olddecl) == error_mark_node; else if (TREE_TYPE (olddecl) == NULL_TREE) types_match = TREE_TYPE (newdecl) == NULL_TREE; else if (TREE_TYPE (newdecl) == NULL_TREE) types_match = 0; else types_match = comptypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl), COMPARE_REDECLARATION); } return types_match; } /* If NEWDECL is `static' and an `extern' was seen previously, warn about it. (OLDDECL may be NULL_TREE; NAME contains information about previous usage as an `extern'.) Note that this does not apply to the C++ case of declaring a variable `extern const' and then later `const'. Don't complain about built-in functions, since they are beyond the user's control. */ static void warn_extern_redeclared_static (newdecl, olddecl) tree newdecl, olddecl; { tree name; static const char *explicit_extern_static_warning = "`%D' was declared `extern' and later `static'"; static const char *implicit_extern_static_warning = "`%D' was declared implicitly `extern' and later `static'"; if (TREE_CODE (newdecl) == TYPE_DECL) return; name = DECL_ASSEMBLER_NAME (newdecl); if (TREE_PUBLIC (name) && DECL_THIS_STATIC (newdecl)) { /* It's okay to redeclare an ANSI built-in function as static, or to declare a non-ANSI built-in function as anything. */ if (! (TREE_CODE (newdecl) == FUNCTION_DECL && olddecl != NULL_TREE && TREE_CODE (olddecl) == FUNCTION_DECL && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))) { cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name) ? implicit_extern_static_warning : explicit_extern_static_warning, newdecl); if (olddecl != NULL_TREE) cp_pedwarn_at ("previous declaration of `%D'", olddecl); } } } /* Handle when a new declaration NEWDECL has the same name as an old one OLDDECL in the same binding contour. Prints an error message if appropriate. If safely possible, alter OLDDECL to look like NEWDECL, and return 1. Otherwise, return 0. */ int duplicate_decls (newdecl, olddecl) tree newdecl, olddecl; { extern struct obstack permanent_obstack; unsigned olddecl_uid = DECL_UID (olddecl); int olddecl_friend = 0, types_match = 0; int new_defines_function = 0; if (newdecl == olddecl) return 1; types_match = decls_match (newdecl, olddecl); /* If either the type of the new decl or the type of the old decl is an error_mark_node, then that implies that we have already issued an error (earlier) for some bogus type specification, and in that case, it is rather pointless to harass the user with yet more error message about the same declaration, so just pretend the types match here. */ if (TREE_TYPE (newdecl) == error_mark_node || TREE_TYPE (olddecl) == error_mark_node) types_match = 1; /* Check for redeclaration and other discrepancies. */ if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_ARTIFICIAL (olddecl) && (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl))) { /* If you declare a built-in or predefined function name as static, the old definition is overridden, but optionally warn this was a bad choice of name. Ditto for overloads. */ if (! TREE_PUBLIC (newdecl) || (TREE_CODE (newdecl) == FUNCTION_DECL && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))) { if (warn_shadow) cp_warning ("shadowing %s function `%#D'", DECL_BUILT_IN (olddecl) ? "built-in" : "library", olddecl); /* Discard the old built-in function. */ return 0; } else if (! types_match) { if (TREE_CODE (newdecl) != FUNCTION_DECL) { /* If the built-in is not ansi, then programs can override it even globally without an error. */ if (! DECL_BUILT_IN (olddecl)) cp_warning ("library function `%#D' redeclared as non-function `%#D'", olddecl, newdecl); else { cp_error ("declaration of `%#D'", newdecl); cp_error ("conflicts with built-in declaration `%#D'", olddecl); } return 0; } cp_warning ("declaration of `%#D'", newdecl); cp_warning ("conflicts with built-in declaration `%#D'", olddecl); } } else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) { if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl) && TREE_CODE (newdecl) != TYPE_DECL && ! (TREE_CODE (newdecl) == TEMPLATE_DECL && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)) || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl) && TREE_CODE (olddecl) != TYPE_DECL && ! (TREE_CODE (olddecl) == TEMPLATE_DECL && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL)))) { /* We do nothing special here, because C++ does such nasty things with TYPE_DECLs. Instead, just let the TYPE_DECL get shadowed, and know that if we need to find a TYPE_DECL for a given name, we can look in the IDENTIFIER_TYPE_VALUE slot of the identifier. */ return 0; } if ((TREE_CODE (newdecl) == FUNCTION_DECL && DECL_FUNCTION_TEMPLATE_P (olddecl)) || (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_FUNCTION_TEMPLATE_P (newdecl))) return 0; cp_error ("`%#D' redeclared as different kind of symbol", newdecl); if (TREE_CODE (olddecl) == TREE_LIST) olddecl = TREE_VALUE (olddecl); cp_error_at ("previous declaration of `%#D'", olddecl); /* New decl is completely inconsistent with the old one => tell caller to replace the old one. */ return 0; } else if (!types_match) { if (DECL_REAL_CONTEXT (newdecl) != DECL_REAL_CONTEXT (olddecl)) /* These are certainly not duplicate declarations; they're from different scopes. */ return 0; if (TREE_CODE (newdecl) == TEMPLATE_DECL) { /* The name of a class template may not be declared to refer to any other template, class, function, object, namespace, value, or type in the same scope. */ if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) { cp_error ("declaration of template `%#D'", newdecl); cp_error_at ("conflicts with previous declaration `%#D'", olddecl); } else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl)))) && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), DECL_TEMPLATE_PARMS (olddecl))) { cp_error ("new declaration `%#D'", newdecl); cp_error_at ("ambiguates old declaration `%#D'", olddecl); } return 0; } if (TREE_CODE (newdecl) == FUNCTION_DECL) { if (DECL_LANGUAGE (newdecl) == lang_c && DECL_LANGUAGE (olddecl) == lang_c) { cp_error ("declaration of C function `%#D' conflicts with", newdecl); cp_error_at ("previous declaration `%#D' here", olddecl); } else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)), TYPE_ARG_TYPES (TREE_TYPE (olddecl)))) { cp_error ("new declaration `%#D'", newdecl); cp_error_at ("ambiguates old declaration `%#D'", olddecl); } else return 0; } /* Already complained about this, so don't do so again. */ else if (current_class_type == NULL_TREE || IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (newdecl)) != current_class_type) { cp_error ("conflicting types for `%#D'", newdecl); cp_error_at ("previous declaration as `%#D'", olddecl); } } else if (TREE_CODE (newdecl) == FUNCTION_DECL && ((DECL_TEMPLATE_SPECIALIZATION (olddecl) && (!DECL_TEMPLATE_INFO (newdecl) || (DECL_TI_TEMPLATE (newdecl) != DECL_TI_TEMPLATE (olddecl)))) || (DECL_TEMPLATE_SPECIALIZATION (newdecl) && (!DECL_TEMPLATE_INFO (olddecl) || (DECL_TI_TEMPLATE (olddecl) != DECL_TI_TEMPLATE (newdecl)))))) /* It's OK to have a template specialization and a non-template with the same type, or to have specializations of two different templates with the same type. Note that if one is a specialization, and the other is an instantiation of the same template, that we do not exit at this point. That situation can occur if we instantiate a template class, and then specialize one of its methods. This situation is legal, but the declarations must be merged in the usual way. */ return 0; else if (TREE_CODE (newdecl) == FUNCTION_DECL && ((DECL_TEMPLATE_INSTANTIATION (olddecl) && !DECL_USE_TEMPLATE (newdecl)) || (DECL_TEMPLATE_INSTANTIATION (newdecl) && !DECL_USE_TEMPLATE (olddecl)))) /* One of the declarations is a template instantiation, and the other is not a template at all. That's OK. */ return 0; else if (TREE_CODE (newdecl) == NAMESPACE_DECL && DECL_NAMESPACE_ALIAS (newdecl) && DECL_NAMESPACE_ALIAS (newdecl) == DECL_NAMESPACE_ALIAS (olddecl)) /* Redeclaration of namespace alias, ignore it. */ return 1; else { const char *errmsg = redeclaration_error_message (newdecl, olddecl); if (errmsg) { cp_error (errmsg, newdecl); if (DECL_NAME (olddecl) != NULL_TREE) cp_error_at ((DECL_INITIAL (olddecl) && namespace_bindings_p ()) ? "`%#D' previously defined here" : "`%#D' previously declared here", olddecl); } else if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_INITIAL (olddecl) != NULL_TREE && TYPE_ARG_TYPES (TREE_TYPE (olddecl)) == NULL_TREE && TYPE_ARG_TYPES (TREE_TYPE (newdecl)) != NULL_TREE) { /* Prototype decl follows defn w/o prototype. */ cp_warning_at ("prototype for `%#D'", newdecl); cp_warning_at ("follows non-prototype definition here", olddecl); } else if (TREE_CODE (olddecl) == FUNCTION_DECL && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)) { /* extern "C" int foo (); int foo () { bar (); } is OK. */ if (current_lang_stack == current_lang_base) DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); else { cp_error_at ("previous declaration of `%#D' with %L linkage", olddecl, DECL_LANGUAGE (olddecl)); cp_error ("conflicts with new declaration with %L linkage", DECL_LANGUAGE (newdecl)); } } if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl)) ; else if (TREE_CODE (olddecl) == FUNCTION_DECL) { tree t1 = TYPE_ARG_TYPES (TREE_TYPE (olddecl)); tree t2 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)); int i = 1; if (TREE_CODE (TREE_TYPE (newdecl)) == METHOD_TYPE) t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2); for (; t1 && t1 != void_list_node; t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++) if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2)) { if (1 == simple_cst_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))) { if (pedantic) { cp_pedwarn ("default argument given for parameter %d of `%#D'", i, newdecl); cp_pedwarn_at ("after previous specification in `%#D'", olddecl); } } else { cp_error ("default argument given for parameter %d of `%#D'", i, newdecl); cp_error_at ("after previous specification in `%#D'", olddecl); } } if (DECL_THIS_INLINE (newdecl) && ! DECL_THIS_INLINE (olddecl) && TREE_ADDRESSABLE (olddecl) && warn_inline) { cp_warning ("`%#D' was used before it was declared inline", newdecl); cp_warning_at ("previous non-inline declaration here", olddecl); } } } /* If new decl is `static' and an `extern' was seen previously, warn about it. */ warn_extern_redeclared_static (newdecl, olddecl); /* We have committed to returning 1 at this point. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* Now that functions must hold information normally held by field decls, there is extra work to do so that declaration information does not get destroyed during definition. */ if (DECL_VINDEX (olddecl)) DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl); if (DECL_CONTEXT (olddecl)) DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl); if (DECL_CLASS_CONTEXT (olddecl)) DECL_CLASS_CONTEXT (newdecl) = DECL_CLASS_CONTEXT (olddecl); if (DECL_PENDING_INLINE_INFO (newdecl) == (struct pending_inline *)0) DECL_PENDING_INLINE_INFO (newdecl) = DECL_PENDING_INLINE_INFO (olddecl); DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl); DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl); DECL_ABSTRACT_VIRTUAL_P (newdecl) |= DECL_ABSTRACT_VIRTUAL_P (olddecl); DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl); DECL_NEEDS_FINAL_OVERRIDER_P (newdecl) |= DECL_NEEDS_FINAL_OVERRIDER_P (olddecl); new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE; /* Optionally warn about more than one declaration for the same name, but don't warn about a function declaration followed by a definition. */ if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl) && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE) /* Don't warn about extern decl followed by definition. */ && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl)) /* Don't warn about friends, let add_friend take care of it. */ && ! DECL_FRIEND_P (newdecl)) { cp_warning ("redundant redeclaration of `%D' in same scope", newdecl); cp_warning_at ("previous declaration of `%D'", olddecl); } } /* Deal with C++: must preserve virtual function table size. */ if (TREE_CODE (olddecl) == TYPE_DECL) { register tree newtype = TREE_TYPE (newdecl); register tree oldtype = TREE_TYPE (olddecl); if (newtype != error_mark_node && oldtype != error_mark_node && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype)) { CLASSTYPE_VSIZE (newtype) = CLASSTYPE_VSIZE (oldtype); CLASSTYPE_FRIEND_CLASSES (newtype) = CLASSTYPE_FRIEND_CLASSES (oldtype); } } /* Copy all the DECL_... slots specified in the new decl except for any that we copy here from the old type. */ DECL_MACHINE_ATTRIBUTES (newdecl) = merge_machine_decl_attributes (olddecl, newdecl); if (TREE_CODE (newdecl) == TEMPLATE_DECL) { if (! duplicate_decls (DECL_TEMPLATE_RESULT (newdecl), DECL_TEMPLATE_RESULT (olddecl))) cp_error ("invalid redeclaration of %D", newdecl); TREE_TYPE (olddecl) = TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl)); DECL_TEMPLATE_SPECIALIZATIONS (olddecl) = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl), DECL_TEMPLATE_SPECIALIZATIONS (newdecl)); return 1; } if (types_match) { /* Automatically handles default parameters. */ tree oldtype = TREE_TYPE (olddecl); tree newtype; /* Make sure we put the new type in the same obstack as the old one. */ if (oldtype) push_obstacks (TYPE_OBSTACK (oldtype), TYPE_OBSTACK (oldtype)); else { push_obstacks_nochange (); end_temporary_allocation (); } /* Merge the data types specified in the two decls. */ newtype = common_type (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); if (TREE_CODE (newdecl) == VAR_DECL) DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl); /* Do this after calling `common_type' so that default parameters don't confuse us. */ else if (TREE_CODE (newdecl) == FUNCTION_DECL && (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl)) != TYPE_RAISES_EXCEPTIONS (TREE_TYPE (olddecl)))) { TREE_TYPE (newdecl) = build_exception_variant (newtype, TYPE_RAISES_EXCEPTIONS (TREE_TYPE (newdecl))); TREE_TYPE (olddecl) = build_exception_variant (newtype, TYPE_RAISES_EXCEPTIONS (oldtype)); if ((pedantic || (! DECL_IN_SYSTEM_HEADER (olddecl) && ! DECL_IN_SYSTEM_HEADER (newdecl))) && DECL_SOURCE_LINE (olddecl) != 0 && flag_exceptions && ! compexcepttypes (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) { cp_pedwarn ("declaration of `%D' throws different exceptions", newdecl); cp_pedwarn_at ("previous declaration here", olddecl); } } TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype; /* Lay the type out, unless already done. */ if (! same_type_p (newtype, oldtype) && TREE_TYPE (newdecl) != error_mark_node && !(processing_template_decl && uses_template_parms (newdecl))) layout_type (TREE_TYPE (newdecl)); if ((TREE_CODE (newdecl) == VAR_DECL || TREE_CODE (newdecl) == PARM_DECL || TREE_CODE (newdecl) == RESULT_DECL || TREE_CODE (newdecl) == FIELD_DECL || TREE_CODE (newdecl) == TYPE_DECL) && !(processing_template_decl && uses_template_parms (newdecl))) layout_decl (newdecl, 0); /* Merge the type qualifiers. */ if (TREE_READONLY (newdecl)) TREE_READONLY (olddecl) = 1; if (TREE_THIS_VOLATILE (newdecl)) TREE_THIS_VOLATILE (olddecl) = 1; /* Merge the initialization information. */ if (DECL_INITIAL (newdecl) == NULL_TREE && DECL_INITIAL (olddecl) != NULL_TREE) { DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); DECL_SOURCE_FILE (newdecl) = DECL_SOURCE_FILE (olddecl); DECL_SOURCE_LINE (newdecl) = DECL_SOURCE_LINE (olddecl); if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl)) DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl); } /* Merge the section attribute. We want to issue an error if the sections conflict but that must be done later in decl_attributes since we are called before attributes are assigned. */ if (DECL_SECTION_NAME (newdecl) == NULL_TREE) DECL_SECTION_NAME (newdecl) = DECL_SECTION_NAME (olddecl); /* Keep the old rtl since we can safely use it, unless it's the call to abort() used for abstract virtuals. */ if ((DECL_LANG_SPECIFIC (olddecl) && !DECL_ABSTRACT_VIRTUAL_P (olddecl)) || DECL_RTL (olddecl) != DECL_RTL (abort_fndecl)) DECL_RTL (newdecl) = DECL_RTL (olddecl); pop_obstacks (); } /* If cannot merge, then use the new type and qualifiers, and don't preserve the old rtl. */ else { /* Clean out any memory we had of the old declaration. */ tree oldstatic = value_member (olddecl, static_aggregates); if (oldstatic) TREE_VALUE (oldstatic) = error_mark_node; TREE_TYPE (olddecl) = TREE_TYPE (newdecl); TREE_READONLY (olddecl) = TREE_READONLY (newdecl); TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl); TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl); } /* Merge the storage class information. */ DECL_WEAK (newdecl) |= DECL_WEAK (olddecl); DECL_ONE_ONLY (newdecl) |= DECL_ONE_ONLY (olddecl); TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl); TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl); if (! DECL_EXTERNAL (olddecl)) DECL_EXTERNAL (newdecl) = 0; if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl)) { DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl); DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl); DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl); DECL_TEMPLATE_INSTANTIATED (newdecl) |= DECL_TEMPLATE_INSTANTIATED (olddecl); /* Don't really know how much of the language-specific values we should copy from old to new. */ DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); olddecl_friend = DECL_FRIEND_P (olddecl); /* Only functions have DECL_BEFRIENDING_CLASSES. */ if (TREE_CODE (newdecl) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (newdecl)) DECL_BEFRIENDING_CLASSES (newdecl) = chainon (DECL_BEFRIENDING_CLASSES (newdecl), DECL_BEFRIENDING_CLASSES (olddecl)); } if (TREE_CODE (newdecl) == FUNCTION_DECL) { if (DECL_TEMPLATE_INSTANTIATION (olddecl) && !DECL_TEMPLATE_INSTANTIATION (newdecl)) { /* If newdecl is not a specialization, then it is not a template-related function at all. And that means that we shoud have exited above, returning 0. */ my_friendly_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl), 0); if (TREE_USED (olddecl)) /* From [temp.expl.spec]: If a template, a member template or the member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiation to take place, in every translation unit in which such a use occurs. */ cp_error ("explicit specialization of %D after first use", olddecl); SET_DECL_TEMPLATE_SPECIALIZATION (olddecl); } DECL_THIS_INLINE (newdecl) |= DECL_THIS_INLINE (olddecl); /* If either decl says `inline', this fn is inline, unless its definition was passed already. */ if (DECL_INLINE (newdecl) && DECL_INITIAL (olddecl) == NULL_TREE) DECL_INLINE (olddecl) = 1; DECL_INLINE (newdecl) = DECL_INLINE (olddecl); if (! types_match) { DECL_LANGUAGE (olddecl) = DECL_LANGUAGE (newdecl); DECL_ASSEMBLER_NAME (olddecl) = DECL_ASSEMBLER_NAME (newdecl); DECL_RTL (olddecl) = DECL_RTL (newdecl); } if (! types_match || new_defines_function) { /* These need to be copied so that the names are available. */ DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl); DECL_RESULT (olddecl) = DECL_RESULT (newdecl); } if (new_defines_function) /* If defining a function declared with other language linkage, use the previously declared language linkage. */ DECL_LANGUAGE (newdecl) = DECL_LANGUAGE (olddecl); else { /* If redeclaring a builtin function, and not a definition, it stays built in. */ if (DECL_BUILT_IN (olddecl)) { DECL_BUILT_IN (newdecl) = 1; DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); /* If we're keeping the built-in definition, keep the rtl, regardless of declaration matches. */ DECL_RTL (newdecl) = DECL_RTL (olddecl); } else DECL_FRAME_SIZE (newdecl) = DECL_FRAME_SIZE (olddecl); DECL_RESULT (newdecl) = DECL_RESULT (olddecl); if ((DECL_SAVED_INSNS (newdecl) = DECL_SAVED_INSNS (olddecl))) /* Previously saved insns go together with the function's previous definition. */ DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl); /* Don't clear out the arguments if we're redefining a function. */ if (DECL_ARGUMENTS (olddecl)) DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl); } if (DECL_LANG_SPECIFIC (olddecl)) DECL_MAIN_VARIANT (newdecl) = DECL_MAIN_VARIANT (olddecl); } if (TREE_CODE (newdecl) == NAMESPACE_DECL) { NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl); } /* Now preserve various other info from the definition. */ TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl); TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl); DECL_COMMON (newdecl) = DECL_COMMON (olddecl); DECL_ASSEMBLER_NAME (newdecl) = DECL_ASSEMBLER_NAME (olddecl); if (TREE_CODE (newdecl) == FUNCTION_DECL) { int function_size; struct lang_decl *ol = DECL_LANG_SPECIFIC (olddecl); struct lang_decl *nl = DECL_LANG_SPECIFIC (newdecl); function_size = sizeof (struct tree_decl); bcopy ((char *) newdecl + sizeof (struct tree_common), (char *) olddecl + sizeof (struct tree_common), function_size - sizeof (struct tree_common)); /* Can we safely free the storage used by newdecl? */ #define ROUND(x) ((x + obstack_alignment_mask (&permanent_obstack)) \ & ~ obstack_alignment_mask (&permanent_obstack)) if (DECL_TEMPLATE_INSTANTIATION (newdecl)) { /* If newdecl is a template instantiation, it is possible that the following sequence of events has occurred: o A friend function was declared in a class template. The class template was instantiated. o The instantiation of the friend declaration was recorded on the instantiation list, and is newdecl. o Later, however, instantiate_class_template called pushdecl on the newdecl to perform name injection. But, pushdecl in turn called duplicate_decls when it discovered that another declaration of a global function with the same name already existed. o Here, in duplicate_decls, we decided to clobber newdecl. If we're going to do that, we'd better make sure that olddecl, and not newdecl, is on the list of instantiations so that if we try to do the instantiation again we won't get the clobbered declaration. */ tree tmpl = DECL_TI_TEMPLATE (newdecl); tree decls = DECL_TEMPLATE_SPECIALIZATIONS (tmpl); for (; decls; decls = TREE_CHAIN (decls)) if (TREE_VALUE (decls) == newdecl) TREE_VALUE (decls) = olddecl; } if (((char *)newdecl + ROUND (function_size) == (char *)nl && ((char *)newdecl + ROUND (function_size) + ROUND (sizeof (struct lang_decl)) == obstack_next_free (&permanent_obstack))) || ((char *)newdecl + ROUND (function_size) == obstack_next_free (&permanent_obstack))) { DECL_MAIN_VARIANT (newdecl) = olddecl; DECL_LANG_SPECIFIC (olddecl) = ol; bcopy ((char *)nl, (char *)ol, sizeof (struct lang_decl)); obstack_free (&permanent_obstack, newdecl); } else if (LANG_DECL_PERMANENT (ol) && ol != nl) { if (DECL_MAIN_VARIANT (olddecl) == olddecl) { /* Save these lang_decls that would otherwise be lost. */ extern tree free_lang_decl_chain; tree free_lang_decl = (tree) ol; if (DECL_LANG_SPECIFIC (olddecl) == ol) abort (); TREE_CHAIN (free_lang_decl) = free_lang_decl_chain; free_lang_decl_chain = free_lang_decl; } else { /* Storage leak. */; } } } else { bcopy ((char *) newdecl + sizeof (struct tree_common), (char *) olddecl + sizeof (struct tree_common), sizeof (struct tree_decl) - sizeof (struct tree_common) + tree_code_length [(int)TREE_CODE (newdecl)] * sizeof (char *)); } DECL_UID (olddecl) = olddecl_uid; if (olddecl_friend) DECL_FRIEND_P (olddecl) = 1; /* NEWDECL contains the merged attribute lists. Update OLDDECL to be the same. */ DECL_MACHINE_ATTRIBUTES (olddecl) = DECL_MACHINE_ATTRIBUTES (newdecl); return 1; } /* Record a decl-node X as belonging to the current lexical scope. Check for errors (such as an incompatible declaration for the same name already seen in the same scope). Returns either X or an old decl for the same name. If an old decl is returned, it may have been smashed to agree with what X says. */ tree pushdecl (x) tree x; { register tree t; register tree name = DECL_ASSEMBLER_NAME (x); int need_new_binding = 1; if (DECL_TEMPLATE_PARM_P (x)) /* Template parameters have no context; they are not X::T even when declared within a class or namespace. */ ; else { if (current_function_decl && x != current_function_decl /* A local declaration for a function doesn't constitute nesting. */ && (TREE_CODE (x) != FUNCTION_DECL || DECL_INITIAL (x)) /* Don't change DECL_CONTEXT of virtual methods. */ && (TREE_CODE (x) != FUNCTION_DECL || !DECL_VIRTUAL_P (x)) && !DECL_CONTEXT (x)) DECL_CONTEXT (x) = current_function_decl; if (!DECL_CONTEXT (x)) DECL_CONTEXT (x) = FROB_CONTEXT (current_namespace); } /* Type are looked up using the DECL_NAME, as that is what the rest of the compiler wants to use. */ if (TREE_CODE (x) == TYPE_DECL || TREE_CODE (x) == VAR_DECL || TREE_CODE (x) == NAMESPACE_DECL) name = DECL_NAME (x); if (name) { #if 0 /* Not needed...see below. */ char *file; int line; #endif if (TREE_CODE (name) == TEMPLATE_ID_EXPR) name = TREE_OPERAND (name, 0); /* Namespace-scoped variables are not found in the current level. */ if (TREE_CODE (x) == VAR_DECL && DECL_NAMESPACE_SCOPE_P (x)) t = namespace_binding (name, DECL_CONTEXT (x)); else t = lookup_name_current_level (name); if (t == error_mark_node) { /* error_mark_node is 0 for a while during initialization! */ t = NULL_TREE; cp_error_at ("`%#D' used prior to declaration", x); } else if (t != NULL_TREE) { #if 0 /* This is turned off until I have time to do it right (bpk). */ /* With the code below that uses it... */ file = DECL_SOURCE_FILE (t); line = DECL_SOURCE_LINE (t); #endif if (TREE_CODE (t) == PARM_DECL) { if (DECL_CONTEXT (t) == NULL_TREE) fatal ("parse errors have confused me too much"); /* Check for duplicate params. */ if (duplicate_decls (x, t)) return t; } else if (((TREE_CODE (x) == FUNCTION_DECL && DECL_LANGUAGE (x) == lang_c) || DECL_FUNCTION_TEMPLATE_P (x)) && is_overloaded_fn (t)) /* Don't do anything just yet. */; else if (t == wchar_decl_node) { if (pedantic && ! DECL_IN_SYSTEM_HEADER (x)) cp_pedwarn ("redeclaration of wchar_t as `%T'", TREE_TYPE (x)); /* Throw away the redeclaration. */ return t; } else if (TREE_CODE (t) != TREE_CODE (x)) { if (duplicate_decls (x, t)) return t; } else if (duplicate_decls (x, t)) { #if 0 /* This is turned off until I have time to do it right (bpk). */ /* Also warn if they did a prototype with `static' on it, but then later left the `static' off. */ if (! TREE_PUBLIC (name) && TREE_PUBLIC (x)) { if (DECL_LANG_SPECIFIC (t) && DECL_FRIEND_P (t)) return t; if (extra_warnings) { cp_warning ("`static' missing from declaration of `%D'", t); warning_with_file_and_line (file, line, "previous declaration of `%s'", decl_as_string (t, 0)); } /* Now fix things so it'll do what they expect. */ if (current_function_decl) TREE_PUBLIC (current_function_decl) = 0; } /* Due to interference in memory reclamation (X may be obstack-deallocated at this point), we must guard against one really special case. [jason: This should be handled by start_function] */ if (current_function_decl == x) current_function_decl = t; #endif if (TREE_CODE (t) == TYPE_DECL) SET_IDENTIFIER_TYPE_VALUE (name, TREE_TYPE (t)); else if (TREE_CODE (t) == FUNCTION_DECL) check_default_args (t); return t; } else if (DECL_MAIN_P (x)) { /* A redeclaration of main, but not a duplicate of the previous one. [basic.start.main] This function shall not be overloaded. */ cp_error_at ("invalid redeclaration of `%D'", t); cp_error ("as `%D'", x); /* We don't try to push this declaration since that causes a crash. */ return x; } } check_template_shadow (x); /* If this is a function conjured up by the backend, massage it so it looks friendly. */ if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x)) { retrofit_lang_decl (x); DECL_LANGUAGE (x) = lang_c; } if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_FUNCTION_MEMBER_P (x)) { t = push_overloaded_decl (x, PUSH_LOCAL); if (t != x || DECL_LANGUAGE (x) == lang_c) return t; if (!namespace_bindings_p ()) /* We do not need to create a binding for this name; push_overloaded_decl will have already done so if necessary. */ need_new_binding = 0; } else if (DECL_FUNCTION_TEMPLATE_P (x) && DECL_NAMESPACE_SCOPE_P (x)) return push_overloaded_decl (x, PUSH_GLOBAL); /* If declaring a type as a typedef, copy the type (unless we're at line 0), and install this TYPE_DECL as the new type's typedef name. See the extensive comment in ../c-decl.c (pushdecl). */ if (TREE_CODE (x) == TYPE_DECL) { tree type = TREE_TYPE (x); if (DECL_SOURCE_LINE (x) == 0) { if (TYPE_NAME (type) == 0) TYPE_NAME (type) = x; } else if (type != error_mark_node && TYPE_NAME (type) != x /* We don't want to copy the type when all we're doing is making a TYPE_DECL for the purposes of inlining. */ && (!TYPE_NAME (type) || TYPE_NAME (type) != DECL_ABSTRACT_ORIGIN (x))) { push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); DECL_ORIGINAL_TYPE (x) = type; type = build_type_copy (type); TYPE_STUB_DECL (type) = TYPE_STUB_DECL (DECL_ORIGINAL_TYPE (x)); TYPE_NAME (type) = x; TREE_TYPE (x) = type; pop_obstacks (); } if (type != error_mark_node && TYPE_NAME (type) && TYPE_IDENTIFIER (type)) set_identifier_type_value_with_scope (DECL_NAME (x), type, current_binding_level); } /* Multiple external decls of the same identifier ought to match. We get warnings about inline functions where they are defined. We get warnings about other functions from push_overloaded_decl. Avoid duplicate warnings where they are used. */ if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL) { tree decl; if (IDENTIFIER_NAMESPACE_VALUE (name) != NULL_TREE && (DECL_EXTERNAL (IDENTIFIER_NAMESPACE_VALUE (name)) || TREE_PUBLIC (IDENTIFIER_NAMESPACE_VALUE (name)))) decl = IDENTIFIER_NAMESPACE_VALUE (name); else decl = NULL_TREE; if (decl /* If different sort of thing, we already gave an error. */ && TREE_CODE (decl) == TREE_CODE (x) && !same_type_p (TREE_TYPE (x), TREE_TYPE (decl))) { cp_pedwarn ("type mismatch with previous external decl", x); cp_pedwarn_at ("previous external decl of `%#D'", decl); } } /* This name is new in its binding level. Install the new declaration and return it. */ if (namespace_bindings_p ()) { /* Install a global value. */ /* If the first global decl has external linkage, warn if we later see static one. */ if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x)) TREE_PUBLIC (name) = 1; if (!(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x) && t != NULL_TREE)) { if (TREE_CODE (x) == FUNCTION_DECL) my_friendly_assert ((IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE) || (IDENTIFIER_GLOBAL_VALUE (name) == x), 378); SET_IDENTIFIER_NAMESPACE_VALUE (name, x); } /* Don't forget if the function was used via an implicit decl. */ if (IDENTIFIER_IMPLICIT_DECL (name) && TREE_USED (IDENTIFIER_IMPLICIT_DECL (name))) TREE_USED (x) = 1; /* Don't forget if its address was taken in that way. */ if (IDENTIFIER_IMPLICIT_DECL (name) && TREE_ADDRESSABLE (IDENTIFIER_IMPLICIT_DECL (name))) TREE_ADDRESSABLE (x) = 1; /* Warn about mismatches against previous implicit decl. */ if (IDENTIFIER_IMPLICIT_DECL (name) != NULL_TREE /* If this real decl matches the implicit, don't complain. */ && ! (TREE_CODE (x) == FUNCTION_DECL && TREE_TYPE (TREE_TYPE (x)) == integer_type_node)) cp_warning ("`%D' was previously implicitly declared to return `int'", x); /* If new decl is `static' and an `extern' was seen previously, warn about it. */ if (x != NULL_TREE && t != NULL_TREE && decls_match (x, t)) warn_extern_redeclared_static (x, t); } else { /* Here to install a non-global value. */ tree oldlocal = IDENTIFIER_VALUE (name); tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name); if (need_new_binding) { push_local_binding (name, x, 0); /* Because push_local_binding will hook X on to the current_binding_level's name list, we don't want to do that again below. */ need_new_binding = 0; } /* If this is a TYPE_DECL, push it into the type value slot. */ if (TREE_CODE (x) == TYPE_DECL) set_identifier_type_value_with_scope (name, TREE_TYPE (x), current_binding_level); /* Clear out any TYPE_DECL shadowed by a namespace so that we won't think this is a type. The C struct hack doesn't go through namespaces. */ if (TREE_CODE (x) == NAMESPACE_DECL) set_identifier_type_value_with_scope (name, NULL_TREE, current_binding_level); /* If this is an extern function declaration, see if we have a global definition or declaration for the function. */ if (oldlocal == NULL_TREE && DECL_EXTERNAL (x) && oldglobal != NULL_TREE && TREE_CODE (x) == FUNCTION_DECL && TREE_CODE (oldglobal) == FUNCTION_DECL) { /* We have one. Their types must agree. */ if (decls_match (x, oldglobal)) /* OK */; else { cp_warning ("extern declaration of `%#D' doesn't match", x); cp_warning_at ("global declaration `%#D'", oldglobal); } } /* If we have a local external declaration, and no file-scope declaration has yet been seen, then if we later have a file-scope decl it must not be static. */ if (oldlocal == NULL_TREE && oldglobal == NULL_TREE && DECL_EXTERNAL (x) && TREE_PUBLIC (x)) TREE_PUBLIC (name) = 1; if (DECL_FROM_INLINE (x)) /* Inline decls shadow nothing. */; /* Warn if shadowing an argument at the top level of the body. */ else if (oldlocal != NULL_TREE && !DECL_EXTERNAL (x) && TREE_CODE (oldlocal) == PARM_DECL /* Don't complain if it's from an enclosing function. */ && DECL_CONTEXT (oldlocal) == current_function_decl && TREE_CODE (x) != PARM_DECL) { /* Go to where the parms should be and see if we find them there. */ struct binding_level *b = current_binding_level->level_chain; if (cleanup_label) b = b->level_chain; /* ARM $8.3 */ if (b->parm_flag == 1) cp_error ("declaration of `%#D' shadows a parameter", name); } else if (warn_shadow && oldlocal != NULL_TREE && current_binding_level->is_for_scope && !DECL_DEAD_FOR_LOCAL (oldlocal)) { warning ("variable `%s' shadows local", IDENTIFIER_POINTER (name)); cp_warning_at (" this is the shadowed declaration", oldlocal); } /* Maybe warn if shadowing something else. */ else if (warn_shadow && !DECL_EXTERNAL (x) /* No shadow warnings for internally generated vars. */ && ! DECL_ARTIFICIAL (x) /* No shadow warnings for vars made for inlining. */ && ! DECL_FROM_INLINE (x)) { const char *warnstring = NULL; if (oldlocal != NULL_TREE && TREE_CODE (oldlocal) == PARM_DECL) warnstring = "declaration of `%s' shadows a parameter"; else if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE && current_class_ptr && !TREE_STATIC (name)) warnstring = "declaration of `%s' shadows a member of `this'"; else if (oldlocal != NULL_TREE) warnstring = "declaration of `%s' shadows previous local"; else if (oldglobal != NULL_TREE) /* XXX shadow warnings in outer-more namespaces */ warnstring = "declaration of `%s' shadows global declaration"; if (warnstring) warning (warnstring, IDENTIFIER_POINTER (name)); } } if (TREE_CODE (x) == FUNCTION_DECL) check_default_args (x); /* Keep count of variables in this level with incomplete type. */ if (TREE_CODE (x) == VAR_DECL && TREE_TYPE (x) != error_mark_node && ((TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE && PROMOTES_TO_AGGR_TYPE (TREE_TYPE (x), ARRAY_TYPE)) /* RTTI TD entries are created while defining the type_info. */ || (TYPE_LANG_SPECIFIC (TREE_TYPE (x)) && TYPE_BEING_DEFINED (TREE_TYPE (x))))) current_binding_level->incomplete = tree_cons (NULL_TREE, x, current_binding_level->incomplete); } if (need_new_binding) { /* Put decls on list in reverse order. We will reverse them later if necessary. */ TREE_CHAIN (x) = current_binding_level->names; current_binding_level->names = x; if (current_binding_level == global_binding_level && !TREE_PERMANENT (x)) my_friendly_abort (124); } return x; } /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the caller to set DECL_CONTEXT properly. */ static tree pushdecl_with_scope (x, level) tree x; struct binding_level *level; { register struct binding_level *b; tree function_decl = current_function_decl; current_function_decl = NULL_TREE; if (level->parm_flag == 2) { b = class_binding_level; class_binding_level = level; pushdecl_class_level (x); class_binding_level = b; } else { b = current_binding_level; current_binding_level = level; x = pushdecl (x); current_binding_level = b; } current_function_decl = function_decl; return x; } /* Like pushdecl, only it places X in the current namespace, if appropriate. */ tree pushdecl_namespace_level (x) tree x; { register struct binding_level *b = current_binding_level; register tree t; t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace)); /* Now, the type_shadowed stack may screw us. Munge it so it does what we want. */ if (TREE_CODE (x) == TYPE_DECL) { tree name = DECL_NAME (x); tree newval; tree *ptr = (tree *)0; for (; b != global_binding_level; b = b->level_chain) { tree shadowed = b->type_shadowed; for (; shadowed; shadowed = TREE_CHAIN (shadowed)) if (TREE_PURPOSE (shadowed) == name) { ptr = &TREE_VALUE (shadowed); /* Can't break out of the loop here because sometimes a binding level will have duplicate bindings for PT names. It's gross, but I haven't time to fix it. */ } } newval = TREE_TYPE (x); if (ptr == (tree *)0) { /* @@ This shouldn't be needed. My test case "zstring.cc" trips up here if this is changed to an assertion. --KR */ SET_IDENTIFIER_TYPE_VALUE (name, newval); } else { *ptr = newval; } } return t; } /* Like pushdecl, only it places X in GLOBAL_BINDING_LEVEL, if appropriate. */ tree pushdecl_top_level (x) tree x; { tree cur_namespace = current_namespace; current_namespace = global_namespace; x = pushdecl_namespace_level (x); current_namespace = cur_namespace; return x; } /* Make the declaration of X appear in CLASS scope. */ void pushdecl_class_level (x) tree x; { /* Don't use DECL_ASSEMBLER_NAME here! Everything that looks in class scope looks for the pre-mangled name. */ register tree name; if (TREE_CODE (x) == OVERLOAD) x = OVL_CURRENT (x); name = DECL_NAME (x); if (name) { push_class_level_binding (name, x); if (TREE_CODE (x) == TYPE_DECL) set_identifier_type_value (name, TREE_TYPE (x)); } else if (ANON_UNION_TYPE_P (TREE_TYPE (x))) { tree f; for (f = TYPE_FIELDS (TREE_TYPE (x)); f; f = TREE_CHAIN (f)) pushdecl_class_level (f); } } #if 0 /* This function is used to push the mangled decls for nested types into the appropriate scope. Previously pushdecl_top_level was used, but that is incorrect for members of local classes. */ void pushdecl_nonclass_level (x) tree x; { struct binding_level *b = current_binding_level; my_friendly_assert (b->parm_flag != 2, 180); #if 0 /* Get out of template binding levels */ while (b->pseudo_global) b = b->level_chain; #endif pushdecl_with_scope (x, b); } #endif /* Make the declaration(s) of X appear in CLASS scope under the name NAME. */ void push_class_level_binding (name, x) tree name; tree x; { tree binding; /* The class_binding_level will be NULL if x is a template parameter name in a member template. */ if (!class_binding_level) return; /* Make sure that this new member does not have the same name as a template parameter. */ if (TYPE_BEING_DEFINED (current_class_type)) check_template_shadow (x); /* If this declaration shadows a declaration from an enclosing class, then we will need to restore IDENTIFIER_CLASS_VALUE when we leave this class. Record the shadowed declaration here. */ binding = IDENTIFIER_BINDING (name); if (binding && ((TREE_CODE (x) == OVERLOAD && BINDING_VALUE (binding) && is_overloaded_fn (BINDING_VALUE (binding))) || INHERITED_VALUE_BINDING_P (binding))) { tree shadow; tree old_decl; /* If the old binding was from a base class, and was for a tag name, slide it over to make room for the new binding. The old binding is still visible if explicitly qualified with a class-key. */ if (INHERITED_VALUE_BINDING_P (binding) && BINDING_VALUE (binding) && TREE_CODE (BINDING_VALUE (binding)) == TYPE_DECL && DECL_ARTIFICIAL (BINDING_VALUE (binding)) && !(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))) { old_decl = BINDING_TYPE (binding); BINDING_TYPE (binding) = BINDING_VALUE (binding); BINDING_VALUE (binding) = NULL_TREE; INHERITED_VALUE_BINDING_P (binding) = 0; } else old_decl = BINDING_VALUE (binding); /* There was already a binding for X containing fewer functions than are named in X. Find the previous declaration of X on the class-shadowed list, and update it. */ for (shadow = class_binding_level->class_shadowed; shadow; shadow = TREE_CHAIN (shadow)) if (TREE_PURPOSE (shadow) == name && TREE_TYPE (shadow) == old_decl) { BINDING_VALUE (binding) = x; INHERITED_VALUE_BINDING_P (binding) = 0; TREE_TYPE (shadow) = x; return; } } /* If we didn't replace an existing binding, put the binding on the stack of bindings for the identifier, and update IDENTIFIER_CLASS_VALUE. */ if (push_class_binding (name, x)) { push_cache_obstack (); class_binding_level->class_shadowed = tree_cons (name, IDENTIFIER_CLASS_VALUE (name), class_binding_level->class_shadowed); pop_obstacks (); /* Record the value we are binding NAME to so that we can know what to pop later. */ TREE_TYPE (class_binding_level->class_shadowed) = x; } } /* Insert another USING_DECL into the current binding level, returning this declaration. If this is a redeclaration, do nothing and return NULL_TREE. */ tree push_using_decl (scope, name) tree scope; tree name; { tree decl; my_friendly_assert (TREE_CODE (scope) == NAMESPACE_DECL, 383); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 384); for (decl = current_binding_level->usings; decl; decl = TREE_CHAIN (decl)) if (DECL_INITIAL (decl) == scope && DECL_NAME (decl) == name) break; if (decl) return NULL_TREE; decl = build_lang_decl (USING_DECL, name, void_type_node); DECL_INITIAL (decl) = scope; TREE_CHAIN (decl) = current_binding_level->usings; current_binding_level->usings = decl; return decl; } /* Add namespace to using_directives. Return NULL_TREE if nothing was changed (i.e. there was already a directive), or the fresh TREE_LIST otherwise. */ tree push_using_directive (used) tree used; { tree ud = current_binding_level->using_directives; tree iter, ancestor; /* Check if we already have this. */ if (purpose_member (used, ud) != NULL_TREE) return NULL_TREE; /* Recursively add all namespaces used. */ for (iter = DECL_NAMESPACE_USING (used); iter; iter = TREE_CHAIN (iter)) push_using_directive (TREE_PURPOSE (iter)); ancestor = namespace_ancestor (current_decl_namespace (), used); ud = current_binding_level->using_directives; ud = perm_tree_cons (used, ancestor, ud); current_binding_level->using_directives = ud; return ud; } /* DECL is a FUNCTION_DECL for a non-member function, which may have other definitions already in place. We get around this by making the value of the identifier point to a list of all the things that want to be referenced by that name. It is then up to the users of that name to decide what to do with that list. DECL may also be a TEMPLATE_DECL, with a FUNCTION_DECL in its DECL_RESULT slot. It is dealt with the same way. FLAGS is a bitwise-or of the following values: PUSH_LOCAL: Bind DECL in the current scope, rather than at namespace scope. PUSH_USING: DECL is being pushed as the result of a using declaration. The value returned may be a previous declaration if we guessed wrong about what language DECL should belong to (C or C++). Otherwise, it's always DECL (and never something that's not a _DECL). */ tree push_overloaded_decl (decl, flags) tree decl; int flags; { tree name = DECL_NAME (decl); tree old; tree new_binding; int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL)); if (doing_global) { old = namespace_binding (name, DECL_CONTEXT (decl)); if (old && TREE_CODE (old) == FUNCTION_DECL && DECL_ARTIFICIAL (old) && (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old))) { if (duplicate_decls (decl, old)) return old; old = NULL_TREE; } } else old = lookup_name_current_level (name); if (old) { if (TREE_CODE (old) == TYPE_DECL && DECL_ARTIFICIAL (old)) { tree t = TREE_TYPE (old); if (IS_AGGR_TYPE (t) && warn_shadow && (! DECL_IN_SYSTEM_HEADER (decl) || ! DECL_IN_SYSTEM_HEADER (old))) cp_warning ("`%#D' hides constructor for `%#T'", decl, t); old = NULL_TREE; } else if (is_overloaded_fn (old)) { tree tmp; for (tmp = old; tmp; tmp = OVL_NEXT (tmp)) { tree fn = OVL_CURRENT (tmp); if (TREE_CODE (tmp) == OVERLOAD && OVL_USED (tmp) && !(flags & PUSH_USING) && compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)), TYPE_ARG_TYPES (TREE_TYPE (decl)))) cp_error ("`%#D' conflicts with previous using declaration `%#D'", decl, fn); if (duplicate_decls (decl, fn)) return fn; } } else { cp_error_at ("previous non-function declaration `%#D'", old); cp_error ("conflicts with function declaration `%#D'", decl); return decl; } } if (old || TREE_CODE (decl) == TEMPLATE_DECL) { if (old && TREE_CODE (old) != OVERLOAD) new_binding = ovl_cons (decl, ovl_cons (old, NULL_TREE)); else new_binding = ovl_cons (decl, old); if (flags & PUSH_USING) OVL_USED (new_binding) = 1; } else /* NAME is not ambiguous. */ new_binding = decl; if (doing_global) set_namespace_binding (name, current_namespace, new_binding); else { /* We only create an OVERLOAD if there was a previous binding at this level, or if decl is a template. In the former case, we need to remove the old binding and replace it with the new binding. We must also run through the NAMES on the binding level where the name was bound to update the chain. */ if (TREE_CODE (new_binding) == OVERLOAD && old) { tree *d; for (d = &BINDING_LEVEL (IDENTIFIER_BINDING (name))->names; *d; d = &TREE_CHAIN (*d)) if (*d == old || (TREE_CODE (*d) == TREE_LIST && TREE_VALUE (*d) == old)) { if (TREE_CODE (*d) == TREE_LIST) /* Just replace the old binding with the new. */ TREE_VALUE (*d) = new_binding; else /* Build a TREE_LIST to wrap the OVERLOAD. */ *d = build_tree_list (NULL_TREE, new_binding); /* And update the CPLUS_BINDING node. */ BINDING_VALUE (IDENTIFIER_BINDING (name)) = new_binding; return decl; } /* We should always find a previous binding in this case. */ my_friendly_abort (0); } /* Install the new binding. */ push_local_binding (name, new_binding, flags); } return decl; } /* Generate an implicit declaration for identifier FUNCTIONID as a function of type int (). Print a warning if appropriate. */ tree implicitly_declare (functionid) tree functionid; { register tree decl; int temp = allocation_temporary_p (); push_obstacks_nochange (); /* Save the decl permanently so we can warn if definition follows. In ANSI C, warn_implicit is usually false, so the saves little space. But in C++, it's usually true, hence the extra code. */ if (temp && (! warn_implicit || toplevel_bindings_p ())) end_temporary_allocation (); /* We used to reuse an old implicit decl here, but this loses with inline functions because it can clobber the saved decl chains. */ decl = build_lang_decl (FUNCTION_DECL, functionid, default_function_type); DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; /* ANSI standard says implicit declarations are in the innermost block. So we record the decl in the standard fashion. */ pushdecl (decl); rest_of_decl_compilation (decl, NULL_PTR, 0, 0); if (warn_implicit /* Only one warning per identifier. */ && IDENTIFIER_IMPLICIT_DECL (functionid) == NULL_TREE) { cp_pedwarn ("implicit declaration of function `%#D'", decl); } SET_IDENTIFIER_IMPLICIT_DECL (functionid, decl); pop_obstacks (); return decl; } /* Return zero if the declaration NEWDECL is valid when the declaration OLDDECL (assumed to be for the same name) has already been seen. Otherwise return an error message format string with a %s where the identifier should go. */ static const char * redeclaration_error_message (newdecl, olddecl) tree newdecl, olddecl; { if (TREE_CODE (newdecl) == TYPE_DECL) { /* Because C++ can put things into name space for free, constructs like "typedef struct foo { ... } foo" would look like an erroneous redeclaration. */ if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl))) return 0; else return "redefinition of `%#D'"; } else if (TREE_CODE (newdecl) == FUNCTION_DECL) { /* If this is a pure function, its olddecl will actually be the original initialization to `0' (which we force to call abort()). Don't complain about redefinition in this case. */ if (DECL_LANG_SPECIFIC (olddecl) && DECL_ABSTRACT_VIRTUAL_P (olddecl)) return 0; /* If both functions come from different namespaces, this is not a redeclaration - this is a conflict with a used function. */ if (DECL_NAMESPACE_SCOPE_P (olddecl) && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)) return "`%D' conflicts with used function"; /* We'll complain about linkage mismatches in warn_extern_redeclared_static. */ /* Defining the same name twice is no good. */ if (DECL_INITIAL (olddecl) != NULL_TREE && DECL_INITIAL (newdecl) != NULL_TREE) { if (DECL_NAME (olddecl) == NULL_TREE) return "`%#D' not declared in class"; else return "redefinition of `%#D'"; } return 0; } else if (TREE_CODE (newdecl) == TEMPLATE_DECL) { if ((TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL && DECL_INITIAL (DECL_TEMPLATE_RESULT (newdecl)) && DECL_INITIAL (DECL_TEMPLATE_RESULT (olddecl))) || (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL && TYPE_SIZE (TREE_TYPE (newdecl)) && TYPE_SIZE (TREE_TYPE (olddecl)))) return "redefinition of `%#D'"; return 0; } else if (toplevel_bindings_p ()) { /* Objects declared at top level: */ /* If at least one is a reference, it's ok. */ if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl)) return 0; /* Reject two definitions. */ return "redefinition of `%#D'"; } else { /* Objects declared with block scope: */ /* Reject two definitions, and reject a definition together with an external reference. */ if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl))) return "redeclaration of `%#D'"; return 0; } } /* Get the LABEL_DECL corresponding to identifier ID as a label. Create one if none exists so far for the current function. This function is called for both label definitions and label references. */ tree lookup_label (id) tree id; { register tree decl = IDENTIFIER_LABEL_VALUE (id); if (current_function_decl == NULL_TREE) { error ("label `%s' referenced outside of any function", IDENTIFIER_POINTER (id)); return NULL_TREE; } if ((decl == NULL_TREE || DECL_SOURCE_LINE (decl) == 0) && (named_label_uses == NULL || named_label_uses->names_in_scope != current_binding_level->names || named_label_uses->label_decl != decl)) { struct named_label_list *new_ent; new_ent = (struct named_label_list*)oballoc (sizeof (struct named_label_list)); new_ent->label_decl = decl; new_ent->names_in_scope = current_binding_level->names; new_ent->binding_level = current_binding_level; new_ent->lineno_o_goto = lineno; new_ent->filename_o_goto = input_filename; new_ent->next = named_label_uses; named_label_uses = new_ent; } /* Use a label already defined or ref'd with this name. */ if (decl != NULL_TREE) { /* But not if it is inherited and wasn't declared to be inheritable. */ if (DECL_CONTEXT (decl) != current_function_decl && ! C_DECLARED_LABEL_FLAG (decl)) return shadow_label (id); return decl; } decl = build_decl (LABEL_DECL, id, void_type_node); /* Make sure every label has an rtx. */ label_rtx (decl); /* A label not explicitly declared must be local to where it's ref'd. */ DECL_CONTEXT (decl) = current_function_decl; DECL_MODE (decl) = VOIDmode; /* Say where one reference is to the label, for the sake of the error if it is not defined. */ DECL_SOURCE_LINE (decl) = lineno; DECL_SOURCE_FILE (decl) = input_filename; SET_IDENTIFIER_LABEL_VALUE (id, decl); named_labels = tree_cons (NULL_TREE, decl, named_labels); named_label_uses->label_decl = decl; return decl; } /* Make a label named NAME in the current function, shadowing silently any that may be inherited from containing functions or containing scopes. Note that valid use, if the label being shadowed comes from another scope in the same function, requires calling declare_nonlocal_label right away. */ tree shadow_label (name) tree name; { register tree decl = IDENTIFIER_LABEL_VALUE (name); if (decl != NULL_TREE) { shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); } return lookup_label (name); } /* Define a label, specifying the location in the source file. Return the LABEL_DECL node for the label, if the definition is valid. Otherwise return 0. */ tree define_label (filename, line, name) char *filename; int line; tree name; { tree decl; if (minimal_parse_mode) { push_obstacks (&permanent_obstack, &permanent_obstack); decl = build_decl (LABEL_DECL, name, void_type_node); pop_obstacks (); DECL_SOURCE_LINE (decl) = line; DECL_SOURCE_FILE (decl) = filename; add_tree (decl); return decl; } decl = lookup_label (name); /* After labels, make any new cleanups go into their own new (temporary) binding contour. */ current_binding_level->more_cleanups_ok = 0; /* If label with this name is known from an outer context, shadow it. */ if (decl != NULL_TREE && DECL_CONTEXT (decl) != current_function_decl) { shadowed_labels = tree_cons (NULL_TREE, decl, shadowed_labels); SET_IDENTIFIER_LABEL_VALUE (name, NULL_TREE); decl = lookup_label (name); } if (name == get_identifier ("wchar_t")) cp_pedwarn ("label named wchar_t"); if (DECL_INITIAL (decl) != NULL_TREE) { cp_error ("duplicate label `%D'", decl); return 0; } else { struct named_label_list *uses, *prev; int identified = 0; /* Mark label as having been defined. */ DECL_INITIAL (decl) = error_mark_node; /* Say where in the source. */ DECL_SOURCE_FILE (decl) = filename; DECL_SOURCE_LINE (decl) = line; prev = NULL; uses = named_label_uses; while (uses != NULL) if (uses->label_decl == decl) { struct binding_level *b = current_binding_level; while (b) { tree new_decls = b->names; tree old_decls = (b == uses->binding_level) ? uses->names_in_scope : NULL_TREE; while (new_decls != old_decls) { if (TREE_CODE (new_decls) == VAR_DECL /* Don't complain about crossing initialization of internal entities. They can't be accessed, and they should be cleaned up by the time we get to the label. */ && ! DECL_ARTIFICIAL (new_decls) && !(DECL_INITIAL (new_decls) == NULL_TREE && pod_type_p (TREE_TYPE (new_decls)))) { /* This is really only important if we're crossing an initialization. The POD stuff is just pedantry; why should it matter if the class contains a field of pointer to member type? */ int problem = (DECL_INITIAL (new_decls) || (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))); if (! identified) { if (problem) { cp_error ("jump to label `%D'", decl); error_with_file_and_line (uses->filename_o_goto, uses->lineno_o_goto, " from here"); } else { cp_pedwarn ("jump to label `%D'", decl); pedwarn_with_file_and_line (uses->filename_o_goto, uses->lineno_o_goto, " from here"); } identified = 1; } if (problem) cp_error_at (" crosses initialization of `%#D'", new_decls); else cp_pedwarn_at (" enters scope of non-POD `%#D'", new_decls); } new_decls = TREE_CHAIN (new_decls); } if (b == uses->binding_level) break; b = b->level_chain; } if (prev != NULL) prev->next = uses->next; else named_label_uses = uses->next; uses = uses->next; } else { prev = uses; uses = uses->next; } current_function_return_value = NULL_TREE; return decl; } } struct cp_switch { struct binding_level *level; struct cp_switch *next; }; static struct cp_switch *switch_stack; void push_switch () { struct cp_switch *p = (struct cp_switch *) oballoc (sizeof (struct cp_switch)); p->level = current_binding_level; p->next = switch_stack; switch_stack = p; } void pop_switch () { switch_stack = switch_stack->next; } /* Same, but for CASE labels. If DECL is NULL_TREE, it's the default. */ /* XXX Note decl is never actually used. (bpk) */ void define_case_label () { tree cleanup = last_cleanup_this_contour (); struct binding_level *b = current_binding_level; int identified = 0; if (cleanup) { static int explained = 0; cp_warning_at ("destructor needed for `%#D'", TREE_PURPOSE (cleanup)); warning ("where case label appears here"); if (!explained) { warning ("(enclose actions of previous case statements requiring"); warning ("destructors in their own binding contours.)"); explained = 1; } } for (; b && b != switch_stack->level; b = b->level_chain) { tree new_decls = b->names; for (; new_decls; new_decls = TREE_CHAIN (new_decls)) { if (TREE_CODE (new_decls) == VAR_DECL /* Don't complain about crossing initialization of internal entities. They can't be accessed, and they should be cleaned up by the time we get to the label. */ && ! DECL_ARTIFICIAL (new_decls) && ((DECL_INITIAL (new_decls) != NULL_TREE && DECL_INITIAL (new_decls) != error_mark_node) || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (new_decls)))) { if (! identified) error ("jump to case label"); identified = 1; cp_error_at (" crosses initialization of `%#D'", new_decls); } } } /* After labels, make any new cleanups go into their own new (temporary) binding contour. */ current_binding_level->more_cleanups_ok = 0; current_function_return_value = NULL_TREE; } /* Return the list of declarations of the current level. Note that this list is in reverse order unless/until you nreverse it; and when you do nreverse it, you must store the result back using `storedecls' or you will lose. */ tree getdecls () { return current_binding_level->names; } /* Return the list of type-tags (for structs, etc) of the current level. */ tree gettags () { return current_binding_level->tags; } /* Store the list of declarations of the current level. This is done for the parameter declarations of a function being defined, after they are modified in the light of any missing parameters. */ static void storedecls (decls) tree decls; { current_binding_level->names = decls; } /* Similarly, store the list of tags of the current level. */ void storetags (tags) tree tags; { current_binding_level->tags = tags; } /* Given NAME, an IDENTIFIER_NODE, return the structure (or union or enum) definition for that name. Searches binding levels from BINDING_LEVEL up to the global level. If THISLEVEL_ONLY is nonzero, searches only the specified context (but skips any tag-transparent contexts to find one that is meaningful for tags). FORM says which kind of type the caller wants; it is RECORD_TYPE or UNION_TYPE or ENUMERAL_TYPE. If the wrong kind of type is found, and it's not a template, an error is reported. */ static tree lookup_tag (form, name, binding_level, thislevel_only) enum tree_code form; tree name; struct binding_level *binding_level; int thislevel_only; { register struct binding_level *level; /* Non-zero if, we should look past a pseudo-global level, even if THISLEVEL_ONLY. */ int allow_pseudo_global = 1; for (level = binding_level; level; level = level->level_chain) { register tree tail; if (ANON_AGGRNAME_P (name)) for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) { /* There's no need for error checking here, because anon names are unique throughout the compilation. */ if (TYPE_IDENTIFIER (TREE_VALUE (tail)) == name) return TREE_VALUE (tail); } else if (level->namespace_p) /* Do namespace lookup. */ for (tail = current_namespace; 1; tail = CP_DECL_CONTEXT (tail)) { tree old = binding_for_name (name, tail); /* If we just skipped past a pseudo global level, even though THISLEVEL_ONLY, and we find a template class declaration, then we use the _TYPE node for the template. See the example below. */ if (thislevel_only && !allow_pseudo_global && old && BINDING_VALUE (old) && DECL_CLASS_TEMPLATE_P (BINDING_VALUE (old))) old = TREE_TYPE (BINDING_VALUE (old)); else old = BINDING_TYPE (old); /* If it has an original type, it is a typedef, and we should not return it. */ if (old && DECL_ORIGINAL_TYPE (TYPE_NAME (old))) old = NULL_TREE; if (old && TREE_CODE (old) != form && !(form != ENUMERAL_TYPE && TREE_CODE (old) == TEMPLATE_DECL)) { cp_error ("`%#D' redeclared as %C", old, form); return NULL_TREE; } if (old) return old; if (thislevel_only || tail == global_namespace) return NULL_TREE; } else for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) { if (TREE_PURPOSE (tail) == name) { enum tree_code code = TREE_CODE (TREE_VALUE (tail)); /* Should tighten this up; it'll probably permit UNION_TYPE and a struct template, for example. */ if (code != form && !(form != ENUMERAL_TYPE && code == TEMPLATE_DECL)) { /* Definition isn't the kind we were looking for. */ cp_error ("`%#D' redeclared as %C", TREE_VALUE (tail), form); return NULL_TREE; } return TREE_VALUE (tail); } } if (thislevel_only && ! level->tag_transparent) { if (level->pseudo_global && allow_pseudo_global) { /* We must deal with cases like this: template struct S; template struct S {}; When looking up `S', for the second declaration, we would like to find the first declaration. But, we are in the pseudo-global level created for the template parameters, rather than the (surrounding) namespace level. Thus, we keep going one more level, even though THISLEVEL_ONLY is non-zero. */ allow_pseudo_global = 0; continue; } else return NULL_TREE; } if (current_class_type && level->level_chain->namespace_p) { /* Try looking in this class's tags before heading into global binding level. */ tree context = current_class_type; while (context) { switch (TREE_CODE_CLASS (TREE_CODE (context))) { tree these_tags; case 't': these_tags = CLASSTYPE_TAGS (context); if (ANON_AGGRNAME_P (name)) while (these_tags) { if (TYPE_IDENTIFIER (TREE_VALUE (these_tags)) == name) return TREE_VALUE (tail); these_tags = TREE_CHAIN (these_tags); } else while (these_tags) { if (TREE_PURPOSE (these_tags) == name) { if (TREE_CODE (TREE_VALUE (these_tags)) != form) { cp_error ("`%#D' redeclared as %C in class scope", TREE_VALUE (tail), form); return NULL_TREE; } return TREE_VALUE (tail); } these_tags = TREE_CHAIN (these_tags); } /* If this type is not yet complete, then don't look at its context. */ if (TYPE_SIZE (context) == NULL_TREE) goto no_context; /* Go to next enclosing type, if any. */ context = DECL_CONTEXT (TYPE_MAIN_DECL (context)); break; case 'd': context = DECL_CONTEXT (context); break; default: my_friendly_abort (10); } continue; no_context: break; } } } return NULL_TREE; } #if 0 void set_current_level_tags_transparency (tags_transparent) int tags_transparent; { current_binding_level->tag_transparent = tags_transparent; } #endif /* Given a type, find the tag that was defined for it and return the tag name. Otherwise return 0. However, the value can never be 0 in the cases in which this is used. C++: If NAME is non-zero, this is the new name to install. This is done when replacing anonymous tags with real tag names. */ static tree lookup_tag_reverse (type, name) tree type; tree name; { register struct binding_level *level; for (level = current_binding_level; level; level = level->level_chain) { register tree tail; for (tail = level->tags; tail; tail = TREE_CHAIN (tail)) { if (TREE_VALUE (tail) == type) { if (name) TREE_PURPOSE (tail) = name; return TREE_PURPOSE (tail); } } } return NULL_TREE; } /* Lookup TYPE in CONTEXT (a chain of nested types or a FUNCTION_DECL). Return the type value, or NULL_TREE if not found. */ static tree lookup_nested_type (type, context) tree type; tree context; { if (context == NULL_TREE) return NULL_TREE; while (context) { switch (TREE_CODE (context)) { case TYPE_DECL: { tree ctype = TREE_TYPE (context); tree match = value_member (type, CLASSTYPE_TAGS (ctype)); if (match) return TREE_VALUE (match); context = DECL_CONTEXT (context); /* When we have a nested class whose member functions have local types (e.g., a set of enums), we'll arrive here with the DECL_CONTEXT as the actual RECORD_TYPE node for the enclosing class. Instead, we want to make sure we come back in here with the TYPE_DECL, not the RECORD_TYPE. */ if (context && TREE_CODE (context) == RECORD_TYPE) context = TREE_CHAIN (context); } break; case FUNCTION_DECL: if (TYPE_NAME (type) && TYPE_IDENTIFIER (type)) return lookup_name (TYPE_IDENTIFIER (type), 1); return NULL_TREE; default: my_friendly_abort (12); } } return NULL_TREE; } /* Look up NAME in the NAMESPACE. */ tree lookup_namespace_name (namespace, name) tree namespace, name; { struct tree_binding _b; tree val; my_friendly_assert (TREE_CODE (namespace) == NAMESPACE_DECL, 370); if (TREE_CODE (name) == NAMESPACE_DECL) /* This happens for A::B when B is a namespace. */ return name; else if (TREE_CODE (name) == TEMPLATE_DECL) { /* This happens for A::B where B is a template, and there are no template arguments. */ cp_error ("invalid use of `%D'", name); return error_mark_node; } namespace = ORIGINAL_NAMESPACE (namespace); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 373); val = binding_init (&_b); if (!qualified_lookup_using_namespace (name, namespace, val, 0)) return error_mark_node; if (BINDING_VALUE (val)) { val = BINDING_VALUE (val); /* If we have a single function from a using decl, pull it out. */ if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val)) val = OVL_FUNCTION (val); return val; } cp_error ("`%D' undeclared in namespace `%D'", name, namespace); return error_mark_node; } /* Hash a TYPENAME_TYPE. K is really of type `tree'. */ static unsigned long typename_hash (k) hash_table_key k; { unsigned long hash; tree t; t = (tree) k; hash = (((unsigned long) TYPE_CONTEXT (t)) ^ ((unsigned long) DECL_NAME (TYPE_NAME (t)))); return hash; } /* Compare two TYPENAME_TYPEs. K1 and K2 are really of type `tree'. */ static boolean typename_compare (k1, k2) hash_table_key k1; hash_table_key k2; { tree t1; tree t2; tree d1; tree d2; t1 = (tree) k1; t2 = (tree) k2; d1 = TYPE_NAME (t1); d2 = TYPE_NAME (t2); return (DECL_NAME (d1) == DECL_NAME (d2) && same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)) && ((TREE_TYPE (t1) != NULL_TREE) == (TREE_TYPE (t2) != NULL_TREE)) && same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) && TYPENAME_TYPE_FULLNAME (t1) == TYPENAME_TYPE_FULLNAME (t2)); } /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is the type of `T', NAME is the IDENTIFIER_NODE for `t'. If BASE_TYPE is non-NULL, this type is being created by the implicit typename extension, and BASE_TYPE is a type named `t' in some base class of `T' which depends on template parameters. Returns the new TYPENAME_TYPE. */ tree build_typename_type (context, name, fullname, base_type) tree context; tree name; tree fullname; tree base_type; { tree t; tree d; struct hash_entry* e; static struct hash_table ht; push_obstacks (&permanent_obstack, &permanent_obstack); if (!ht.table && !hash_table_init (&ht, &hash_newfunc, &typename_hash, &typename_compare)) fatal ("virtual memory exhausted"); /* The FULLNAME needs to exist for the life of the hash table, i.e., for the entire compilation. */ if (!TREE_PERMANENT (fullname)) fullname = copy_to_permanent (fullname); /* Build the TYPENAME_TYPE. */ t = make_lang_type (TYPENAME_TYPE); TYPE_CONTEXT (t) = FROB_CONTEXT (context); TYPENAME_TYPE_FULLNAME (t) = fullname; TREE_TYPE (t) = base_type; /* Build the corresponding TYPE_DECL. */ d = build_decl (TYPE_DECL, name, t); TYPE_NAME (TREE_TYPE (d)) = d; TYPE_STUB_DECL (TREE_TYPE (d)) = d; DECL_CONTEXT (d) = FROB_CONTEXT (context); DECL_ARTIFICIAL (d) = 1; /* See if we already have this type. */ e = hash_lookup (&ht, t, /*create=*/false, /*copy=*/0); if (e) { /* This will free not only TREE_TYPE, but the lang-specific data and the TYPE_DECL as well. */ obstack_free (&permanent_obstack, t); t = (tree) e->key; } else /* Insert the type into the table. */ hash_lookup (&ht, t, /*create=*/true, /*copy=*/0); pop_obstacks (); return t; } tree make_typename_type (context, name) tree context, name; { tree t; tree fullname; if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') { if (!(TYPE_LANG_SPECIFIC (name) && (CLASSTYPE_IS_TEMPLATE (name) || CLASSTYPE_USE_TEMPLATE (name)))) name = TYPE_IDENTIFIER (name); else /* Create a TEMPLATE_ID_EXPR for the type. */ name = build_nt (TEMPLATE_ID_EXPR, CLASSTYPE_TI_TEMPLATE (name), CLASSTYPE_TI_ARGS (name)); } else if (TREE_CODE (name) == TYPE_DECL) name = DECL_NAME (name); fullname = name; if (TREE_CODE (name) == TEMPLATE_ID_EXPR) { name = TREE_OPERAND (name, 0); if (TREE_CODE (name) == TEMPLATE_DECL) name = TREE_OPERAND (fullname, 0) = DECL_NAME (name); } if (TREE_CODE (name) != IDENTIFIER_NODE) my_friendly_abort (2000); if (TREE_CODE (context) == NAMESPACE_DECL) { /* We can get here from typename_sub0 in the explicit_template_type expansion. Just fail. */ cp_error ("no class template named `%#T' in `%#T'", name, context); return error_mark_node; } if (! uses_template_parms (context) || currently_open_class (context)) { if (TREE_CODE (fullname) == TEMPLATE_ID_EXPR) { tree tmpl = NULL_TREE; if (IS_AGGR_TYPE (context)) tmpl = lookup_field (context, name, 0, 0); if (!tmpl || !DECL_CLASS_TEMPLATE_P (tmpl)) { cp_error ("no class template named `%#T' in `%#T'", name, context); return error_mark_node; } return lookup_template_class (tmpl, TREE_OPERAND (fullname, 1), NULL_TREE, context, /*entering_scope=*/0); } else { if (IS_AGGR_TYPE (context)) t = lookup_field (context, name, 0, 1); else { cp_error ("no type named `%#T' in `%#T'", name, context); return error_mark_node; } if (t) return TREE_TYPE (t); } } /* If the CONTEXT is not a template type, then either the field is there now or its never going to be. */ if (!uses_template_parms (context) && !t) { cp_error ("no type named `%#T' in `%#T'", name, context); return error_mark_node; } return build_typename_type (context, name, fullname, NULL_TREE); } /* Select the right _DECL from multiple choices. */ static tree select_decl (binding, flags) tree binding; int flags; { tree val; val = BINDING_VALUE (binding); if (LOOKUP_NAMESPACES_ONLY (flags)) { /* We are not interested in types. */ if (val && TREE_CODE (val) == NAMESPACE_DECL) return val; return NULL_TREE; } /* If we could have a type and we have nothing or we need a type and have none. */ if (BINDING_TYPE (binding) && (!val || ((flags & LOOKUP_PREFER_TYPES) && TREE_CODE (val) != TYPE_DECL))) val = TYPE_STUB_DECL (BINDING_TYPE (binding)); /* Don't return non-types if we really prefer types. */ else if (val && LOOKUP_TYPES_ONLY (flags) && TREE_CODE (val) != TYPE_DECL && (TREE_CODE (val) != TEMPLATE_DECL || !DECL_CLASS_TEMPLATE_P (val))) val = NULL_TREE; return val; } /* Unscoped lookup of a global, iterate over namespaces, considering using namespace statements. */ static tree unqualified_namespace_lookup (name, flags) tree name; int flags; { struct tree_binding _binding; tree b = binding_init (&_binding); tree initial = current_decl_namespace(); tree scope = initial; tree siter; struct binding_level *level; tree val = NULL_TREE; while (!val) { val = binding_for_name (name, scope); /* Initialize binding for this context. */ BINDING_VALUE (b) = BINDING_VALUE (val); BINDING_TYPE (b) = BINDING_TYPE (val); /* Add all _DECLs seen through local using-directives. */ for (level = current_binding_level; !level->namespace_p; level = level->level_chain) if (!lookup_using_namespace (name, b, level->using_directives, scope, flags)) /* Give up because of error. */ return error_mark_node; /* Add all _DECLs seen through global using-directives. */ /* XXX local and global using lists should work equally. */ siter = initial; while (1) { if (!lookup_using_namespace (name, b, DECL_NAMESPACE_USING (siter), scope, flags)) /* Give up because of error. */ return error_mark_node; if (siter == scope) break; siter = CP_DECL_CONTEXT (siter); } val = select_decl (b, flags); if (scope == global_namespace) break; scope = CP_DECL_CONTEXT (scope); } return val; } /* Combine prefer_type and namespaces_only into flags. */ static int lookup_flags (prefer_type, namespaces_only) int prefer_type, namespaces_only; { if (namespaces_only) return LOOKUP_PREFER_NAMESPACES; if (prefer_type > 1) return LOOKUP_PREFER_TYPES; if (prefer_type > 0) return LOOKUP_PREFER_BOTH; return 0; } /* Given a lookup that returned VAL, use FLAGS to decide if we want to ignore it or not. Subroutine of lookup_name_real. */ static tree qualify_lookup (val, flags) tree val; int flags; { if (val == NULL_TREE) return val; if ((flags & LOOKUP_PREFER_NAMESPACES) && TREE_CODE (val) == NAMESPACE_DECL) return val; if ((flags & LOOKUP_PREFER_TYPES) && (TREE_CODE (val) == TYPE_DECL || ((flags & LOOKUP_TEMPLATES_EXPECTED) && DECL_CLASS_TEMPLATE_P (val)))) return val; if (flags & (LOOKUP_PREFER_NAMESPACES | LOOKUP_PREFER_TYPES)) return NULL_TREE; return val; } /* Any other BINDING overrides an implicit TYPENAME. Warn about that. */ static void warn_about_implicit_typename_lookup (typename, binding) tree typename; tree binding; { tree subtype = TREE_TYPE (TREE_TYPE (typename)); tree name = DECL_NAME (typename); if (! (TREE_CODE (binding) == TEMPLATE_DECL && CLASSTYPE_TEMPLATE_INFO (subtype) && CLASSTYPE_TI_TEMPLATE (subtype) == binding) && ! (TREE_CODE (binding) == TYPE_DECL && same_type_p (TREE_TYPE (binding), subtype))) { cp_warning ("lookup of `%D' finds `%#D'", name, binding); cp_warning (" instead of `%D' from dependent base class", typename); cp_warning (" (use `typename %T::%D' if that's what you meant)", constructor_name (current_class_type), name); } } /* Look up NAME in the current binding level and its superiors in the namespace of variables, functions and typedefs. Return a ..._DECL node of some kind representing its definition if there is only one such declaration, or return a TREE_LIST with all the overloaded definitions if there are many, or return 0 if it is undefined. If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces. If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces). If PREFER_TYPE is -2, we're being called from yylex(). (UGLY) Otherwise we prefer non-TYPE_DECLs. If NONCLASS is non-zero, we don't look for the NAME in class scope, using IDENTIFIER_CLASS_VALUE. */ static tree lookup_name_real (name, prefer_type, nonclass, namespaces_only) tree name; int prefer_type, nonclass, namespaces_only; { tree t; tree val = NULL_TREE; int yylex = 0; tree from_obj = NULL_TREE; int flags; int val_is_implicit_typename = 0; /* Hack: copy flag set by parser, if set. */ if (only_namespace_names) namespaces_only = 1; if (prefer_type == -2) { extern int looking_for_typename; tree type = NULL_TREE; yylex = 1; prefer_type = looking_for_typename; flags = lookup_flags (prefer_type, namespaces_only); /* If the next thing is '<', class templates are types. */ if (looking_for_template) flags |= LOOKUP_TEMPLATES_EXPECTED; /* std:: becomes :: for now. */ if (got_scope == std_node) got_scope = void_type_node; if (got_scope) type = got_scope; else if (got_object != error_mark_node) type = got_object; if (type) { if (type == error_mark_node) return error_mark_node; if (TREE_CODE (type) == TYPENAME_TYPE && TREE_TYPE (type)) type = TREE_TYPE (type); if (TYPE_P (type)) type = complete_type (type); if (TREE_CODE (type) == VOID_TYPE) type = global_namespace; if (TREE_CODE (type) == NAMESPACE_DECL) { struct tree_binding b; val = binding_init (&b); flags |= LOOKUP_COMPLAIN; if (!qualified_lookup_using_namespace (name, type, val, flags)) return NULL_TREE; val = select_decl (val, flags); } else if (! IS_AGGR_TYPE (type) || TREE_CODE (type) == TEMPLATE_TYPE_PARM || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM || TREE_CODE (type) == TYPENAME_TYPE) /* Someone else will give an error about this if needed. */ val = NULL_TREE; else if (type == current_class_type) val = IDENTIFIER_CLASS_VALUE (name); else val = lookup_member (type, name, 0, prefer_type); } else val = NULL_TREE; if (got_scope) goto done; else if (got_object && val) from_obj = val; } else { flags = lookup_flags (prefer_type, namespaces_only); /* If we're not parsing, we need to complain. */ flags |= LOOKUP_COMPLAIN; } /* First, look in non-namespace scopes. */ for (t = IDENTIFIER_BINDING (name); t; t = TREE_CHAIN (t)) { tree binding; if (!LOCAL_BINDING_P (t) && nonclass) /* We're not looking for class-scoped bindings, so keep going. */ continue; /* If this is the kind of thing we're looking for, we're done. */ if (qualify_lookup (BINDING_VALUE (t), flags)) binding = BINDING_VALUE (t); else if ((flags & LOOKUP_PREFER_TYPES) && qualify_lookup (BINDING_TYPE (t), flags)) binding = BINDING_TYPE (t); else binding = NULL_TREE; if (binding && (!val || !(TREE_CODE (binding) == TYPE_DECL && IMPLICIT_TYPENAME_P (TREE_TYPE (binding))))) { if (val_is_implicit_typename && !yylex) warn_about_implicit_typename_lookup (val, binding); val = binding; val_is_implicit_typename = (TREE_CODE (val) == TYPE_DECL && IMPLICIT_TYPENAME_P (TREE_TYPE (val))); if (!val_is_implicit_typename) break; } } /* Now lookup in namespace scopes. */ if (!val || val_is_implicit_typename) { t = unqualified_namespace_lookup (name, flags); if (t) { if (val_is_implicit_typename && !yylex) warn_about_implicit_typename_lookup (val, t); val = t; } } done: if (val) { /* This should only warn about types used in qualified-ids. */ if (from_obj && from_obj != val) { if (looking_for_typename && TREE_CODE (from_obj) == TYPE_DECL && TREE_CODE (val) == TYPE_DECL && TREE_TYPE (from_obj) != TREE_TYPE (val)) { cp_pedwarn ("lookup of `%D' in the scope of `%#T' (`%#T')", name, got_object, TREE_TYPE (from_obj)); cp_pedwarn (" does not match lookup in the current scope (`%#T')", TREE_TYPE (val)); } /* We don't change val to from_obj if got_object depends on template parms because that breaks implicit typename for destructor calls. */ if (! uses_template_parms (got_object)) val = from_obj; } /* If we have a single function from a using decl, pull it out. */ if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val)) val = OVL_FUNCTION (val); } else if (from_obj) val = from_obj; return val; } tree lookup_name_nonclass (name) tree name; { return lookup_name_real (name, 0, 1, 0); } tree lookup_function_nonclass (name, args) tree name; tree args; { return lookup_arg_dependent (name, lookup_name_nonclass (name), args); } tree lookup_name_namespace_only (name) tree name; { /* type-or-namespace, nonclass, namespace_only */ return lookup_name_real (name, 1, 1, 1); } tree lookup_name (name, prefer_type) tree name; int prefer_type; { return lookup_name_real (name, prefer_type, 0, 0); } /* Similar to `lookup_name' but look only in the innermost non-class binding level. */ tree lookup_name_current_level (name) tree name; { struct binding_level *b; tree t = NULL_TREE; b = current_binding_level; while (b->parm_flag == 2) b = b->level_chain; if (b->namespace_p) { t = IDENTIFIER_NAMESPACE_VALUE (name); /* extern "C" function() */ if (t != NULL_TREE && TREE_CODE (t) == TREE_LIST) t = TREE_VALUE (t); } else if (IDENTIFIER_BINDING (name) && LOCAL_BINDING_P (IDENTIFIER_BINDING (name))) { while (1) { if (BINDING_LEVEL (IDENTIFIER_BINDING (name)) == b) return IDENTIFIER_VALUE (name); if (b->keep == 2) b = b->level_chain; else break; } } return t; } /* Like lookup_name_current_level, but for types. */ tree lookup_type_current_level (name) tree name; { register tree t = NULL_TREE; my_friendly_assert (! current_binding_level->namespace_p, 980716); if (REAL_IDENTIFIER_TYPE_VALUE (name) != NULL_TREE && REAL_IDENTIFIER_TYPE_VALUE (name) != global_type_node) { struct binding_level *b = current_binding_level; while (1) { if (purpose_member (name, b->type_shadowed)) return REAL_IDENTIFIER_TYPE_VALUE (name); if (b->keep == 2) b = b->level_chain; else break; } } return t; } void begin_only_namespace_names () { only_namespace_names = 1; } void end_only_namespace_names () { only_namespace_names = 0; } /* Arrange for the user to get a source line number, even when the compiler is going down in flames, so that she at least has a chance of working around problems in the compiler. We used to call error(), but that let the segmentation fault continue through; now, it's much more passive by asking them to send the maintainers mail about the problem. */ static void signal_catch (sig) int sig ATTRIBUTE_UNUSED; { signal (SIGSEGV, SIG_DFL); #ifdef SIGIOT signal (SIGIOT, SIG_DFL); #endif #ifdef SIGILL signal (SIGILL, SIG_DFL); #endif #ifdef SIGABRT signal (SIGABRT, SIG_DFL); #endif #ifdef SIGBUS signal (SIGBUS, SIG_DFL); #endif my_friendly_abort (0); } #if 0 /* Unused -- brendan 970107 */ /* Array for holding types considered "built-in". These types are output in the module in which `main' is defined. */ static tree *builtin_type_tdescs_arr; static int builtin_type_tdescs_len, builtin_type_tdescs_max; #endif /* Push the declarations of builtin types into the namespace. RID_INDEX, if < RID_MAX is the index of the builtin type in the array RID_POINTERS. NAME is the name used when looking up the builtin type. TYPE is the _TYPE node for the builtin type. */ static void record_builtin_type (rid_index, name, type) enum rid rid_index; const char *name; tree type; { tree rname = NULL_TREE, tname = NULL_TREE; tree tdecl = NULL_TREE; if ((int) rid_index < (int) RID_MAX) rname = ridpointers[(int) rid_index]; if (name) tname = get_identifier (name); TYPE_BUILT_IN (type) = 1; if (tname) { tdecl = pushdecl (build_decl (TYPE_DECL, tname, type)); set_identifier_type_value (tname, NULL_TREE); if ((int) rid_index < (int) RID_MAX) /* Built-in types live in the global namespace. */ SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl); } if (rname != NULL_TREE) { if (tname != NULL_TREE) { set_identifier_type_value (rname, NULL_TREE); SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl); } else { tdecl = pushdecl (build_decl (TYPE_DECL, rname, type)); set_identifier_type_value (rname, NULL_TREE); } } } /* Record one of the standard Java types. * Declare it as having the given NAME. * If SIZE > 0, it is the size of one of the integral types; * otherwise it is the negative of the size of one of the other types. */ static tree record_builtin_java_type (name, size) const char *name; int size; { tree type, decl; if (size > 0) type = make_signed_type (size); else if (size > -32) { /* "__java_char" or ""__java_boolean". */ type = make_unsigned_type (-size); /*if (size == -1) TREE_SET_CODE (type, BOOLEAN_TYPE);*/ } else { /* "__java_float" or ""__java_double". */ type = make_node (REAL_TYPE); TYPE_PRECISION (type) = - size; layout_type (type); } record_builtin_type (RID_MAX, name, type); decl = TYPE_NAME (type); /* Suppress generate debug symbol entries for these types, since for normal C++ they are just clutter. However, push_lang_context undoes this if extern "Java" is seen. */ DECL_IGNORED_P (decl) = 1; TYPE_FOR_JAVA (type) = 1; return type; } /* Push a type into the namespace so that the back-ends ignore it. */ static void record_unknown_type (type, name) tree type; const char *name; { tree decl = pushdecl (build_decl (TYPE_DECL, get_identifier (name), type)); /* Make sure the "unknown type" typedecl gets ignored for debug info. */ DECL_IGNORED_P (decl) = 1; TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; TYPE_SIZE (type) = TYPE_SIZE (void_type_node); TYPE_ALIGN (type) = 1; TYPE_MODE (type) = TYPE_MODE (void_type_node); } /* Push overloaded decl, in global scope, with one argument so it can be used as a callback from define_function. */ static void push_overloaded_decl_1 (x) tree x; { push_overloaded_decl (x, PUSH_GLOBAL); } #ifdef __GNUC__ __inline #endif tree auto_function (name, type, code) tree name, type; enum built_in_function code; { return define_function (IDENTIFIER_POINTER (name), type, code, push_overloaded_decl_1, IDENTIFIER_POINTER (build_decl_overload (name, TYPE_ARG_TYPES (type), 0))); } /* Create the predefined scalar types of C, and some nodes representing standard constants (0, 1, (void *)0). Initialize the global binding level. Make definitions for built-in primitive functions. */ void init_decl_processing () { register tree endlink, int_endlink, double_endlink, unsigned_endlink; tree fields[20]; /* Data type of memcpy. */ tree memcpy_ftype, strlen_ftype; int wchar_type_size; tree temp; tree array_domain_type; tree vb_off_identifier = NULL_TREE; /* Function type `char *(char *, char *)' and similar ones */ tree string_ftype_ptr_ptr, int_ftype_string_string; tree sizetype_endlink; tree ptr_ftype, ptr_ftype_unsigned, ptr_ftype_sizetype; tree void_ftype, void_ftype_int, void_ftype_ptr; /* Have to make these distinct before we try using them. */ lang_name_cplusplus = get_identifier ("C++"); lang_name_c = get_identifier ("C"); lang_name_java = get_identifier ("Java"); /* Enter the global namespace. */ my_friendly_assert (global_namespace == NULL_TREE, 375); my_friendly_assert (current_lang_name == NULL_TREE, 375); current_lang_name = lang_name_cplusplus; push_namespace (get_identifier ("::")); global_namespace = current_namespace; current_lang_name = NULL_TREE; if (flag_strict_prototype == 2) flag_strict_prototype = pedantic; if (! flag_permissive && ! pedantic) flag_pedantic_errors = 1; strict_prototypes_lang_c = flag_strict_prototype; /* Initially, C. */ current_lang_name = lang_name_c; current_function_decl = NULL_TREE; named_labels = NULL_TREE; named_label_uses = NULL; current_binding_level = NULL_BINDING_LEVEL; free_binding_level = NULL_BINDING_LEVEL; /* Because most segmentation signals can be traced back into user code, catch them and at least give the user a chance of working around compiler bugs. */ signal (SIGSEGV, signal_catch); /* We will also catch aborts in the back-end through signal_catch and give the user a chance to see where the error might be, and to defeat aborts in the back-end when there have been errors previously in their code. */ #ifdef SIGIOT signal (SIGIOT, signal_catch); #endif #ifdef SIGILL signal (SIGILL, signal_catch); #endif #ifdef SIGABRT signal (SIGABRT, signal_catch); #endif #ifdef SIGBUS signal (SIGBUS, signal_catch); #endif gcc_obstack_init (&decl_obstack); /* Must lay these out before anything else gets laid out. */ error_mark_node = make_node (ERROR_MARK); TREE_PERMANENT (error_mark_node) = 1; TREE_TYPE (error_mark_node) = error_mark_node; error_mark_list = build_tree_list (error_mark_node, error_mark_node); TREE_TYPE (error_mark_list) = error_mark_node; /* Make the binding_level structure for global names. */ pushlevel (0); global_binding_level = current_binding_level; /* The global level is the namespace level of ::. */ NAMESPACE_LEVEL (global_namespace) = global_binding_level; declare_namespace_level (); this_identifier = get_identifier (THIS_NAME); in_charge_identifier = get_identifier (IN_CHARGE_NAME); + vlist_identifier = get_identifier (VLIST_NAME); ctor_identifier = get_identifier (CTOR_NAME); dtor_identifier = get_identifier (DTOR_NAME); pfn_identifier = get_identifier (VTABLE_PFN_NAME); index_identifier = get_identifier (VTABLE_INDEX_NAME); delta_identifier = get_identifier (VTABLE_DELTA_NAME); delta2_identifier = get_identifier (VTABLE_DELTA2_NAME); pfn_or_delta2_identifier = get_identifier ("__pfn_or_delta2"); if (flag_handle_signatures) { tag_identifier = get_identifier (SIGTABLE_TAG_NAME); vb_off_identifier = get_identifier (SIGTABLE_VB_OFF_NAME); vt_off_identifier = get_identifier (SIGTABLE_VT_OFF_NAME); } /* Define `int' and `char' first so that dbx will output them first. */ integer_type_node = make_signed_type (INT_TYPE_SIZE); record_builtin_type (RID_INT, NULL_PTR, integer_type_node); /* Define `char', which is like either `signed char' or `unsigned char' but not the same as either. */ char_type_node = (flag_signed_char ? make_signed_type (CHAR_TYPE_SIZE) : make_unsigned_type (CHAR_TYPE_SIZE)); record_builtin_type (RID_CHAR, "char", char_type_node); /* `signed' is the same as `int' */ record_builtin_type (RID_SIGNED, NULL_PTR, integer_type_node); long_integer_type_node = make_signed_type (LONG_TYPE_SIZE); record_builtin_type (RID_LONG, "long int", long_integer_type_node); unsigned_type_node = make_unsigned_type (INT_TYPE_SIZE); record_builtin_type (RID_UNSIGNED, "unsigned int", unsigned_type_node); long_unsigned_type_node = make_unsigned_type (LONG_TYPE_SIZE); record_builtin_type (RID_MAX, "long unsigned int", long_unsigned_type_node); record_builtin_type (RID_MAX, "unsigned long", long_unsigned_type_node); long_long_integer_type_node = make_signed_type (LONG_LONG_TYPE_SIZE); record_builtin_type (RID_MAX, "long long int", long_long_integer_type_node); long_long_unsigned_type_node = make_unsigned_type (LONG_LONG_TYPE_SIZE); record_builtin_type (RID_MAX, "long long unsigned int", long_long_unsigned_type_node); record_builtin_type (RID_MAX, "long long unsigned", long_long_unsigned_type_node); short_integer_type_node = make_signed_type (SHORT_TYPE_SIZE); record_builtin_type (RID_SHORT, "short int", short_integer_type_node); short_unsigned_type_node = make_unsigned_type (SHORT_TYPE_SIZE); record_builtin_type (RID_MAX, "short unsigned int", short_unsigned_type_node); record_builtin_type (RID_MAX, "unsigned short", short_unsigned_type_node); /* `unsigned long' is the standard type for sizeof. Note that stddef.h uses `unsigned long', and this must agree, even if long and int are the same size. */ set_sizetype (TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (SIZE_TYPE)))); ptrdiff_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (PTRDIFF_TYPE))); /* Define both `signed char' and `unsigned char'. */ signed_char_type_node = make_signed_type (CHAR_TYPE_SIZE); record_builtin_type (RID_MAX, "signed char", signed_char_type_node); unsigned_char_type_node = make_unsigned_type (CHAR_TYPE_SIZE); record_builtin_type (RID_MAX, "unsigned char", unsigned_char_type_node); /* These are types that type_for_size and type_for_mode use. */ intQI_type_node = make_signed_type (GET_MODE_BITSIZE (QImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, intQI_type_node)); intHI_type_node = make_signed_type (GET_MODE_BITSIZE (HImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, intHI_type_node)); intSI_type_node = make_signed_type (GET_MODE_BITSIZE (SImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, intSI_type_node)); intDI_type_node = make_signed_type (GET_MODE_BITSIZE (DImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, intDI_type_node)); #if HOST_BITS_PER_WIDE_INT >= 64 intTI_type_node = make_signed_type (GET_MODE_BITSIZE (TImode)); pushdecl (build_decl (TYPE_DECL, get_identifier ("__int128_t"), intTI_type_node)); #endif unsigned_intQI_type_node = make_unsigned_type (GET_MODE_BITSIZE (QImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intQI_type_node)); unsigned_intHI_type_node = make_unsigned_type (GET_MODE_BITSIZE (HImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intHI_type_node)); unsigned_intSI_type_node = make_unsigned_type (GET_MODE_BITSIZE (SImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intSI_type_node)); unsigned_intDI_type_node = make_unsigned_type (GET_MODE_BITSIZE (DImode)); pushdecl (build_decl (TYPE_DECL, NULL_TREE, unsigned_intDI_type_node)); #if HOST_BITS_PER_WIDE_INT >= 64 unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode)); pushdecl (build_decl (TYPE_DECL, get_identifier ("__uint128_t"), unsigned_intTI_type_node)); #endif float_type_node = make_node (REAL_TYPE); TYPE_PRECISION (float_type_node) = FLOAT_TYPE_SIZE; record_builtin_type (RID_FLOAT, NULL_PTR, float_type_node); layout_type (float_type_node); double_type_node = make_node (REAL_TYPE); if (flag_short_double) TYPE_PRECISION (double_type_node) = FLOAT_TYPE_SIZE; else TYPE_PRECISION (double_type_node) = DOUBLE_TYPE_SIZE; record_builtin_type (RID_DOUBLE, NULL_PTR, double_type_node); layout_type (double_type_node); long_double_type_node = make_node (REAL_TYPE); TYPE_PRECISION (long_double_type_node) = LONG_DOUBLE_TYPE_SIZE; record_builtin_type (RID_MAX, "long double", long_double_type_node); layout_type (long_double_type_node); complex_integer_type_node = make_node (COMPLEX_TYPE); pushdecl (build_decl (TYPE_DECL, get_identifier ("complex int"), complex_integer_type_node)); TREE_TYPE (complex_integer_type_node) = integer_type_node; layout_type (complex_integer_type_node); complex_float_type_node = make_node (COMPLEX_TYPE); pushdecl (build_decl (TYPE_DECL, get_identifier ("complex float"), complex_float_type_node)); TREE_TYPE (complex_float_type_node) = float_type_node; layout_type (complex_float_type_node); complex_double_type_node = make_node (COMPLEX_TYPE); pushdecl (build_decl (TYPE_DECL, get_identifier ("complex double"), complex_double_type_node)); TREE_TYPE (complex_double_type_node) = double_type_node; layout_type (complex_double_type_node); complex_long_double_type_node = make_node (COMPLEX_TYPE); pushdecl (build_decl (TYPE_DECL, get_identifier ("complex long double"), complex_long_double_type_node)); TREE_TYPE (complex_long_double_type_node) = long_double_type_node; layout_type (complex_long_double_type_node); java_byte_type_node = record_builtin_java_type ("__java_byte", 8); java_short_type_node = record_builtin_java_type ("__java_short", 16); java_int_type_node = record_builtin_java_type ("__java_int", 32); java_long_type_node = record_builtin_java_type ("__java_long", 64); java_float_type_node = record_builtin_java_type ("__java_float", -32); java_double_type_node = record_builtin_java_type ("__java_double", -64); java_char_type_node = record_builtin_java_type ("__java_char", -16); java_boolean_type_node = record_builtin_java_type ("__java_boolean", -1); integer_zero_node = build_int_2 (0, 0); TREE_TYPE (integer_zero_node) = integer_type_node; integer_one_node = build_int_2 (1, 0); TREE_TYPE (integer_one_node) = integer_type_node; integer_two_node = build_int_2 (2, 0); TREE_TYPE (integer_two_node) = integer_type_node; integer_three_node = build_int_2 (3, 0); TREE_TYPE (integer_three_node) = integer_type_node; boolean_type_node = make_unsigned_type (BOOL_TYPE_SIZE); TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE); TYPE_MAX_VALUE (boolean_type_node) = build_int_2 (1, 0); TREE_TYPE (TYPE_MAX_VALUE (boolean_type_node)) = boolean_type_node; TYPE_PRECISION (boolean_type_node) = 1; record_builtin_type (RID_BOOL, "bool", boolean_type_node); boolean_false_node = build_int_2 (0, 0); TREE_TYPE (boolean_false_node) = boolean_type_node; boolean_true_node = build_int_2 (1, 0); TREE_TYPE (boolean_true_node) = boolean_type_node; /* These are needed by stor-layout.c. */ size_zero_node = size_int (0); size_one_node = size_int (1); signed_size_zero_node = build_int_2 (0, 0); TREE_TYPE (signed_size_zero_node) = make_signed_type (TYPE_PRECISION (sizetype)); void_type_node = make_node (VOID_TYPE); record_builtin_type (RID_VOID, NULL_PTR, void_type_node); layout_type (void_type_node); /* Uses integer_zero_node. */ void_list_node = build_tree_list (NULL_TREE, void_type_node); TREE_PARMLIST (void_list_node) = 1; null_pointer_node = build_int_2 (0, 0); TREE_TYPE (null_pointer_node) = build_pointer_type (void_type_node); layout_type (TREE_TYPE (null_pointer_node)); /* Used for expressions that do nothing, but are not errors. */ void_zero_node = build_int_2 (0, 0); TREE_TYPE (void_zero_node) = void_type_node; string_type_node = build_pointer_type (char_type_node); const_string_type_node = build_pointer_type (build_qualified_type (char_type_node, TYPE_QUAL_CONST)); #if 0 record_builtin_type (RID_MAX, NULL_PTR, string_type_node); #endif /* Make a type to be the domain of a few array types whose domains don't really matter. 200 is small enough that it always fits in size_t and large enough that it can hold most function names for the initializations of __FUNCTION__ and __PRETTY_FUNCTION__. */ array_domain_type = build_index_type (build_int_2 (200, 0)); /* Make a type for arrays of characters. With luck nothing will ever really depend on the length of this array type. */ char_array_type_node = build_array_type (char_type_node, array_domain_type); /* Likewise for arrays of ints. */ int_array_type_node = build_array_type (integer_type_node, array_domain_type); /* This is just some anonymous class type. Nobody should ever need to look inside this envelope. */ class_star_type_node = build_pointer_type (make_lang_type (RECORD_TYPE)); default_function_type = build_function_type (integer_type_node, NULL_TREE); ptr_type_node = build_pointer_type (void_type_node); const_ptr_type_node = build_pointer_type (build_qualified_type (void_type_node, TYPE_QUAL_CONST)); #if 0 record_builtin_type (RID_MAX, NULL_PTR, ptr_type_node); #endif + endlink = void_list_node; int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); double_endlink = tree_cons (NULL_TREE, double_type_node, endlink); unsigned_endlink = tree_cons (NULL_TREE, unsigned_type_node, endlink); ptr_ftype = build_function_type (ptr_type_node, NULL_TREE); ptr_ftype_unsigned = build_function_type (ptr_type_node, unsigned_endlink); sizetype_endlink = tree_cons (NULL_TREE, sizetype, endlink); /* We realloc here because sizetype could be int or unsigned. S'ok. */ ptr_ftype_sizetype = build_function_type (ptr_type_node, sizetype_endlink); void_ftype = build_function_type (void_type_node, endlink); void_ftype_int = build_function_type (void_type_node, int_endlink); void_ftype_ptr = build_function_type (void_type_node, tree_cons (NULL_TREE, ptr_type_node, endlink)); void_ftype_ptr = build_exception_variant (void_ftype_ptr, tree_cons (NULL_TREE, NULL_TREE, NULL_TREE)); float_ftype_float = build_function_type (float_type_node, tree_cons (NULL_TREE, float_type_node, endlink)); double_ftype_double = build_function_type (double_type_node, double_endlink); ldouble_ftype_ldouble = build_function_type (long_double_type_node, tree_cons (NULL_TREE, long_double_type_node, endlink)); double_ftype_double_double = build_function_type (double_type_node, tree_cons (NULL_TREE, double_type_node, double_endlink)); int_ftype_int = build_function_type (integer_type_node, int_endlink); long_ftype_long = build_function_type (long_integer_type_node, tree_cons (NULL_TREE, long_integer_type_node, endlink)); int_ftype_cptr_cptr_sizet = build_function_type (integer_type_node, tree_cons (NULL_TREE, const_ptr_type_node, tree_cons (NULL_TREE, const_ptr_type_node, tree_cons (NULL_TREE, sizetype, endlink)))); string_ftype_ptr_ptr /* strcpy prototype */ = build_function_type (string_type_node, tree_cons (NULL_TREE, string_type_node, tree_cons (NULL_TREE, const_string_type_node, endlink))); int_ftype_string_string /* strcmp prototype */ = build_function_type (integer_type_node, tree_cons (NULL_TREE, const_string_type_node, tree_cons (NULL_TREE, const_string_type_node, endlink))); strlen_ftype /* strlen prototype */ = build_function_type (sizetype, tree_cons (NULL_TREE, const_string_type_node, endlink)); memcpy_ftype /* memcpy prototype */ = build_function_type (ptr_type_node, tree_cons (NULL_TREE, ptr_type_node, tree_cons (NULL_TREE, const_ptr_type_node, sizetype_endlink))); if (flag_huge_objects) delta_type_node = long_integer_type_node; else delta_type_node = short_integer_type_node; builtin_function ("__builtin_constant_p", default_function_type, BUILT_IN_CONSTANT_P, NULL_PTR); builtin_return_address_fndecl = builtin_function ("__builtin_return_address", ptr_ftype_unsigned, BUILT_IN_RETURN_ADDRESS, NULL_PTR); builtin_function ("__builtin_frame_address", ptr_ftype_unsigned, BUILT_IN_FRAME_ADDRESS, NULL_PTR); builtin_function ("__builtin_alloca", ptr_ftype_sizetype, BUILT_IN_ALLOCA, "alloca"); builtin_function ("__builtin_ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); /* Define alloca, ffs as builtins. Declare _exit just to mark it as volatile. */ if (! flag_no_builtin && !flag_no_nonansi_builtin) { temp = builtin_function ("alloca", ptr_ftype_sizetype, BUILT_IN_ALLOCA, NULL_PTR); /* Suppress error if redefined as a non-function. */ DECL_BUILT_IN_NONANSI (temp) = 1; temp = builtin_function ("ffs", int_ftype_int, BUILT_IN_FFS, NULL_PTR); /* Suppress error if redefined as a non-function. */ DECL_BUILT_IN_NONANSI (temp) = 1; temp = builtin_function ("_exit", void_ftype_int, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; /* Suppress error if redefined as a non-function. */ DECL_BUILT_IN_NONANSI (temp) = 1; } builtin_function ("__builtin_abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); builtin_function ("__builtin_fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); builtin_function ("__builtin_fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); builtin_function ("__builtin_fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, NULL_PTR); builtin_function ("__builtin_labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); builtin_function ("__builtin_saveregs", ptr_ftype, BUILT_IN_SAVEREGS, NULL_PTR); builtin_function ("__builtin_classify_type", default_function_type, BUILT_IN_CLASSIFY_TYPE, NULL_PTR); builtin_function ("__builtin_next_arg", ptr_ftype, BUILT_IN_NEXT_ARG, NULL_PTR); builtin_function ("__builtin_args_info", int_ftype_int, BUILT_IN_ARGS_INFO, NULL_PTR); builtin_function ("__builtin_setjmp", build_function_type (integer_type_node, tree_cons (NULL_TREE, ptr_type_node, endlink)), BUILT_IN_SETJMP, NULL_PTR); builtin_function ("__builtin_longjmp", build_function_type (integer_type_node, tree_cons (NULL_TREE, ptr_type_node, tree_cons (NULL_TREE, integer_type_node, endlink))), BUILT_IN_LONGJMP, NULL_PTR); /* Untyped call and return. */ builtin_function ("__builtin_apply_args", ptr_ftype, BUILT_IN_APPLY_ARGS, NULL_PTR); temp = tree_cons (NULL_TREE, build_pointer_type (build_function_type (void_type_node, NULL_TREE)), tree_cons (NULL_TREE, ptr_ftype_sizetype, NULL_TREE)); builtin_function ("__builtin_apply", build_function_type (ptr_type_node, temp), BUILT_IN_APPLY, NULL_PTR); builtin_function ("__builtin_return", void_ftype_ptr, BUILT_IN_RETURN, NULL_PTR); /* Currently under experimentation. */ builtin_function ("__builtin_memcpy", memcpy_ftype, BUILT_IN_MEMCPY, "memcpy"); builtin_function ("__builtin_memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, "memcmp"); builtin_function ("__builtin_strcmp", int_ftype_string_string, BUILT_IN_STRCMP, "strcmp"); builtin_function ("__builtin_strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, "strcpy"); builtin_function ("__builtin_strlen", strlen_ftype, BUILT_IN_STRLEN, "strlen"); builtin_function ("__builtin_sqrtf", float_ftype_float, BUILT_IN_FSQRT, "sqrtf"); builtin_function ("__builtin_fsqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, "sqrtl"); builtin_function ("__builtin_sinf", float_ftype_float, BUILT_IN_SIN, "sinf"); builtin_function ("__builtin_sin", double_ftype_double, BUILT_IN_SIN, "sin"); builtin_function ("__builtin_sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, "sinl"); builtin_function ("__builtin_cosf", float_ftype_float, BUILT_IN_COS, "cosf"); builtin_function ("__builtin_cos", double_ftype_double, BUILT_IN_COS, "cos"); builtin_function ("__builtin_cosl", ldouble_ftype_ldouble, BUILT_IN_COS, "cosl"); if (!flag_no_builtin) { builtin_function ("abs", int_ftype_int, BUILT_IN_ABS, NULL_PTR); builtin_function ("fabs", double_ftype_double, BUILT_IN_FABS, NULL_PTR); builtin_function ("labs", long_ftype_long, BUILT_IN_LABS, NULL_PTR); builtin_function ("fabsf", float_ftype_float, BUILT_IN_FABS, NULL_PTR); builtin_function ("fabsl", ldouble_ftype_ldouble, BUILT_IN_FABS, NULL_PTR); builtin_function ("memcpy", memcpy_ftype, BUILT_IN_MEMCPY, NULL_PTR); builtin_function ("memcmp", int_ftype_cptr_cptr_sizet, BUILT_IN_MEMCMP, NULL_PTR); builtin_function ("strcmp", int_ftype_string_string, BUILT_IN_STRCMP, NULL_PTR); builtin_function ("strcpy", string_ftype_ptr_ptr, BUILT_IN_STRCPY, NULL_PTR); builtin_function ("strlen", strlen_ftype, BUILT_IN_STRLEN, NULL_PTR); builtin_function ("sqrtf", float_ftype_float, BUILT_IN_FSQRT, NULL_PTR); builtin_function ("sqrt", double_ftype_double, BUILT_IN_FSQRT, NULL_PTR); builtin_function ("sqrtl", ldouble_ftype_ldouble, BUILT_IN_FSQRT, NULL_PTR); builtin_function ("sinf", float_ftype_float, BUILT_IN_SIN, NULL_PTR); builtin_function ("sin", double_ftype_double, BUILT_IN_SIN, NULL_PTR); builtin_function ("sinl", ldouble_ftype_ldouble, BUILT_IN_SIN, NULL_PTR); builtin_function ("cosf", float_ftype_float, BUILT_IN_COS, NULL_PTR); builtin_function ("cos", double_ftype_double, BUILT_IN_COS, NULL_PTR); builtin_function ("cosl", ldouble_ftype_ldouble, BUILT_IN_COS, NULL_PTR); /* Declare these functions volatile to avoid spurious "control drops through" warnings. */ temp = builtin_function ("abort", void_ftype, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; /* Well, these are actually ANSI, but we can't set DECL_BUILT_IN on them... */ DECL_BUILT_IN_NONANSI (temp) = 1; temp = builtin_function ("exit", void_ftype_int, NOT_BUILT_IN, NULL_PTR); TREE_THIS_VOLATILE (temp) = 1; TREE_SIDE_EFFECTS (temp) = 1; DECL_BUILT_IN_NONANSI (temp) = 1; } #if 0 /* Support for these has not been written in either expand_builtin or build_function_call. */ builtin_function ("__builtin_div", default_ftype, BUILT_IN_DIV, NULL_PTR); builtin_function ("__builtin_ldiv", default_ftype, BUILT_IN_LDIV, NULL_PTR); builtin_function ("__builtin_ffloor", double_ftype_double, BUILT_IN_FFLOOR, NULL_PTR); builtin_function ("__builtin_fceil", double_ftype_double, BUILT_IN_FCEIL, NULL_PTR); builtin_function ("__builtin_fmod", double_ftype_double_double, BUILT_IN_FMOD, NULL_PTR); builtin_function ("__builtin_frem", double_ftype_double_double, BUILT_IN_FREM, NULL_PTR); builtin_function ("__builtin_memset", ptr_ftype_ptr_int_int, BUILT_IN_MEMSET, NULL_PTR); builtin_function ("__builtin_getexp", double_ftype_double, BUILT_IN_GETEXP, NULL_PTR); builtin_function ("__builtin_getman", double_ftype_double, BUILT_IN_GETMAN, NULL_PTR); #endif /* C++ extensions */ unknown_type_node = make_node (UNKNOWN_TYPE); record_unknown_type (unknown_type_node, "unknown type"); /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */ TREE_TYPE (unknown_type_node) = unknown_type_node; TREE_TYPE (null_node) = type_for_size (POINTER_SIZE, 0); /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same result. */ TYPE_POINTER_TO (unknown_type_node) = unknown_type_node; TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node; /* This is for handling opaque types in signatures. */ opaque_type_node = copy_node (ptr_type_node); TYPE_MAIN_VARIANT (opaque_type_node) = opaque_type_node; record_builtin_type (RID_MAX, 0, opaque_type_node); /* This is special for C++ so functions can be overloaded. */ wchar_type_node = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (get_identifier (WCHAR_TYPE))); wchar_type_size = TYPE_PRECISION (wchar_type_node); signed_wchar_type_node = make_signed_type (wchar_type_size); unsigned_wchar_type_node = make_unsigned_type (wchar_type_size); wchar_type_node = TREE_UNSIGNED (wchar_type_node) ? unsigned_wchar_type_node : signed_wchar_type_node; record_builtin_type (RID_WCHAR, "__wchar_t", wchar_type_node); /* Artificial declaration of wchar_t -- can be bashed */ wchar_decl_node = build_decl (TYPE_DECL, get_identifier ("wchar_t"), wchar_type_node); pushdecl (wchar_decl_node); /* This is for wide string constants. */ wchar_array_type_node = build_array_type (wchar_type_node, array_domain_type); if (flag_vtable_thunks) { /* Make sure we get a unique function type, so we can give its pointer type a name. (This wins for gdb.) */ tree vfunc_type = make_node (FUNCTION_TYPE); TREE_TYPE (vfunc_type) = integer_type_node; TYPE_ARG_TYPES (vfunc_type) = NULL_TREE; layout_type (vfunc_type); vtable_entry_type = build_pointer_type (vfunc_type); } else { vtable_entry_type = make_lang_type (RECORD_TYPE); fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node); fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node); fields[2] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node); finish_builtin_type (vtable_entry_type, VTBL_PTR_TYPE, fields, 2, double_type_node); /* Make this part of an invisible union. */ fields[3] = copy_node (fields[2]); TREE_TYPE (fields[3]) = delta_type_node; DECL_NAME (fields[3]) = delta2_identifier; DECL_MODE (fields[3]) = TYPE_MODE (delta_type_node); DECL_SIZE (fields[3]) = TYPE_SIZE (delta_type_node); TREE_UNSIGNED (fields[3]) = 0; TREE_CHAIN (fields[2]) = fields[3]; vtable_entry_type = build_qualified_type (vtable_entry_type, TYPE_QUAL_CONST); } record_builtin_type (RID_MAX, VTBL_PTR_TYPE, vtable_entry_type); vtbl_type_node = build_cplus_array_type (vtable_entry_type, NULL_TREE); layout_type (vtbl_type_node); vtbl_type_node = build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST); record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node); vtbl_ptr_type_node = build_pointer_type (vtable_entry_type); layout_type (vtbl_ptr_type_node); record_builtin_type (RID_MAX, NULL_PTR, vtbl_ptr_type_node); + if (flag_vtable_thunks) + { + /* We need vlists only when using thunks; otherwise leave them + as NULL_TREE. That way, it doesn't get into the way of the + mangling. */ + vlist_type_node = build_pointer_type (vtbl_ptr_type_node); + vlist_zero_node = build_int_2 (0, 0); + TREE_TYPE (vlist_zero_node) = vlist_type_node; + } + /* Simplify life by making a "sigtable_entry_type". Give its fields names so that the debugger can use them. */ if (flag_handle_signatures) { sigtable_entry_type = make_lang_type (RECORD_TYPE); fields[0] = build_lang_field_decl (FIELD_DECL, tag_identifier, delta_type_node); fields[1] = build_lang_field_decl (FIELD_DECL, vb_off_identifier, delta_type_node); fields[2] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node); fields[3] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node); fields[4] = build_lang_field_decl (FIELD_DECL, pfn_identifier, ptr_type_node); /* Set the alignment to the max of the alignment of ptr_type_node and delta_type_node. Double alignment wastes a word on the Sparc. */ finish_builtin_type (sigtable_entry_type, SIGTABLE_PTR_TYPE, fields, 4, (TYPE_ALIGN (ptr_type_node) > TYPE_ALIGN (delta_type_node)) ? ptr_type_node : delta_type_node); /* Make this part of an invisible union. */ fields[5] = copy_node (fields[4]); TREE_TYPE (fields[5]) = delta_type_node; DECL_NAME (fields[5]) = vt_off_identifier; DECL_MODE (fields[5]) = TYPE_MODE (delta_type_node); DECL_SIZE (fields[5]) = TYPE_SIZE (delta_type_node); TREE_UNSIGNED (fields[5]) = 0; TREE_CHAIN (fields[4]) = fields[5]; sigtable_entry_type = build_qualified_type (sigtable_entry_type, TYPE_QUAL_CONST); record_builtin_type (RID_MAX, SIGTABLE_PTR_TYPE, sigtable_entry_type); } std_node = build_decl (NAMESPACE_DECL, get_identifier (flag_honor_std ? "fake std":"std"), void_type_node); pushdecl (std_node); global_type_node = make_node (LANG_TYPE); record_unknown_type (global_type_node, "global type"); /* Now, C++. */ current_lang_name = lang_name_cplusplus; { tree bad_alloc_type_node, newtype, deltype; if (flag_honor_std) push_namespace (get_identifier ("std")); bad_alloc_type_node = xref_tag (class_type_node, get_identifier ("bad_alloc"), 1); if (flag_honor_std) pop_namespace (); newtype = build_exception_variant (ptr_ftype_sizetype, build_tree_list (NULL_TREE, bad_alloc_type_node)); deltype = build_exception_variant (void_ftype_ptr, build_tree_list (NULL_TREE, NULL_TREE)); auto_function (ansi_opname[(int) NEW_EXPR], newtype, NOT_BUILT_IN); auto_function (ansi_opname[(int) VEC_NEW_EXPR], newtype, NOT_BUILT_IN); global_delete_fndecl = auto_function (ansi_opname[(int) DELETE_EXPR], deltype, NOT_BUILT_IN); auto_function (ansi_opname[(int) VEC_DELETE_EXPR], deltype, NOT_BUILT_IN); } abort_fndecl = define_function ("__pure_virtual", void_ftype, NOT_BUILT_IN, 0, 0); /* Perform other language dependent initializations. */ init_class_processing (); init_init_processing (); init_search_processing (); if (flag_rtti) init_rtti_processing (); if (flag_exceptions) init_exception_processing (); if (flag_no_inline) { flag_inline_functions = 0; } if (! supports_one_only ()) flag_weak = 0; /* Create the global bindings for __FUNCTION__ and __PRETTY_FUNCTION__. */ declare_function_name (); /* Prepare to check format strings against argument lists. */ init_function_format_info (); /* Show we use EH for cleanups. */ using_eh_for_cleanups (); print_error_function = lang_print_error_function; lang_get_alias_set = &c_get_alias_set; valid_lang_attribute = cp_valid_lang_attribute; /* Maintain consistency. Perhaps we should just complain if they say -fwritable-strings? */ if (flag_writable_strings) flag_const_strings = 0; } /* Function to print any language-specific context for an error message. */ static void lang_print_error_function (file) char *file; { default_print_error_function (file); maybe_print_template_context (); } /* Make a definition for a builtin function named NAME and whose data type is TYPE. TYPE should be a function type with argument types. FUNCTION_CODE tells later passes how to compile calls to this function. See tree.h for its possible values. If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME, the name to be called if we can't opencode the function. */ tree define_function (name, type, function_code, pfn, library_name) const char *name; tree type; enum built_in_function function_code; void (*pfn) PROTO((tree)); const char *library_name; { tree decl = build_lang_decl (FUNCTION_DECL, get_identifier (name), type); DECL_EXTERNAL (decl) = 1; TREE_PUBLIC (decl) = 1; DECL_ARTIFICIAL (decl) = 1; my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392); DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); /* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME, we cannot change DECL_ASSEMBLER_NAME until we have installed this function in the namespace. */ if (pfn) (*pfn) (decl); if (library_name) DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name); make_function_rtl (decl); if (function_code != NOT_BUILT_IN) { DECL_BUILT_IN (decl) = 1; DECL_FUNCTION_CODE (decl) = function_code; } return decl; } /* When we call finish_struct for an anonymous union, we create default copy constructors and such. But, an anonymous union shouldn't have such things; this function undoes the damage to the anonymous union type T. (The reason that we create the synthesized methods is that we don't distinguish `union { int i; }' from `typedef union { int i; } U'. The first is an anonymous union; the second is just an ordinary union type.) */ void fixup_anonymous_union (t) tree t; { tree *q; /* Wipe out memory of synthesized methods */ TYPE_HAS_CONSTRUCTOR (t) = 0; TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0; TYPE_HAS_INIT_REF (t) = 0; TYPE_HAS_CONST_INIT_REF (t) = 0; TYPE_HAS_ASSIGN_REF (t) = 0; TYPE_HAS_CONST_ASSIGN_REF (t) = 0; /* Splice the implicitly generated functions out of the TYPE_METHODS list. */ q = &TYPE_METHODS (t); while (*q) { if (DECL_ARTIFICIAL (*q)) *q = TREE_CHAIN (*q); else q = &TREE_CHAIN (*q); } /* ANSI C++ June 5 1992 WP 9.5.3. Anonymous unions may not have function members. */ if (TYPE_METHODS (t)) error ("an anonymous union cannot have function members"); } /* Make sure that a declaration with no declarator is well-formed, i.e. just defines a tagged type or anonymous union. Returns the type defined, if any. */ tree check_tag_decl (declspecs) tree declspecs; { int found_type = 0; tree ob_modifier = NULL_TREE; register tree link; register tree t = NULL_TREE; for (link = declspecs; link; link = TREE_CHAIN (link)) { register tree value = TREE_VALUE (link); if (TYPE_P (value)) { ++found_type; if (IS_AGGR_TYPE (value) || TREE_CODE (value) == ENUMERAL_TYPE) { my_friendly_assert (TYPE_MAIN_DECL (value) != NULL_TREE, 261); t = value; } } else if (value == ridpointers[(int) RID_FRIEND]) { if (current_class_type == NULL_TREE || current_scope () != current_class_type) ob_modifier = value; } else if (value == ridpointers[(int) RID_STATIC] || value == ridpointers[(int) RID_EXTERN] || value == ridpointers[(int) RID_AUTO] || value == ridpointers[(int) RID_REGISTER] || value == ridpointers[(int) RID_INLINE] || value == ridpointers[(int) RID_VIRTUAL] || value == ridpointers[(int) RID_CONST] || value == ridpointers[(int) RID_VOLATILE] || value == ridpointers[(int) RID_EXPLICIT]) ob_modifier = value; } if (found_type > 1) error ("multiple types in one declaration"); /* Inside a class, we might be in a friend or access declaration. Until we have a good way of detecting the latter, don't warn. */ if (t == NULL_TREE && ! current_class_type) pedwarn ("declaration does not declare anything"); /* Check for an anonymous union. We're careful accessing TYPE_IDENTIFIER because some built-in types, like pointer-to-member types, do not have TYPE_NAME. */ else if (t && TREE_CODE (t) == UNION_TYPE && TYPE_NAME (t) && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) { /* Anonymous unions are objects, so they can have specifiers. */; SET_ANON_UNION_TYPE_P (t); } else if (ob_modifier) { if (ob_modifier == ridpointers[(int) RID_INLINE] || ob_modifier == ridpointers[(int) RID_VIRTUAL]) cp_error ("`%D' can only be specified for functions", ob_modifier); else if (ob_modifier == ridpointers[(int) RID_FRIEND]) cp_error ("`%D' can only be specified inside a class", ob_modifier); else if (ob_modifier == ridpointers[(int) RID_EXPLICIT]) cp_error ("`%D' can only be specified for constructors", ob_modifier); else cp_error ("`%D' can only be specified for objects and functions", ob_modifier); } return t; } /* Called when a declaration is seen that contains no names to declare. If its type is a reference to a structure, union or enum inherited from a containing scope, shadow that tag name for the current scope with a forward reference. If its type defines a new named structure or union or defines an enum, it is valid but we need not do anything here. Otherwise, it is an error. C++: may have to grok the declspecs to learn about static, complain for anonymous unions. */ void shadow_tag (declspecs) tree declspecs; { tree t = check_tag_decl (declspecs); if (t) maybe_process_partial_specialization (t); /* This is where the variables in an anonymous union are declared. An anonymous union declaration looks like: union { ... } ; because there is no declarator after the union, the parser sends that declaration here. */ if (t && ANON_UNION_TYPE_P (t)) { fixup_anonymous_union (t); if (TYPE_FIELDS (t)) { tree decl = grokdeclarator (NULL_TREE, declspecs, NORMAL, 0, NULL_TREE); finish_anon_union (decl); } } } /* Decode a "typename", such as "int **", returning a ..._TYPE node. */ tree groktypename (typename) tree typename; { if (TREE_CODE (typename) != TREE_LIST) return typename; return grokdeclarator (TREE_VALUE (typename), TREE_PURPOSE (typename), TYPENAME, 0, NULL_TREE); } /* Decode a declarator in an ordinary declaration or data definition. This is called as soon as the type information and variable name have been parsed, before parsing the initializer if any. Here we create the ..._DECL node, fill in its type, and put it on the list of decls for the current context. The ..._DECL node is returned as the value. Exception: for arrays where the length is not specified, the type is left null, to be filled in by `cp_finish_decl'. Function definitions do not come here; they go to start_function instead. However, external and forward declarations of functions do go through here. Structure field declarations are done by grokfield and not through here. */ /* Set this to zero to debug not using the temporary obstack to parse initializers. */ int debug_temp_inits = 1; tree start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) tree declarator, declspecs; int initialized; tree attributes, prefix_attributes; { register tree decl; register tree type, tem; tree context; extern int have_extern_spec; extern int used_extern_spec; tree attrlist; #if 0 /* See code below that used this. */ int init_written = initialized; #endif /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); used_extern_spec = 1; } if (attributes || prefix_attributes) attrlist = build_scratch_list (attributes, prefix_attributes); else attrlist = NULL_TREE; decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, attrlist); if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE) return NULL_TREE; type = TREE_TYPE (decl); if (type == error_mark_node) return NULL_TREE; /* Don't lose if destructors must be executed at file-level. */ if (! processing_template_decl && TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (complete_type (type)) && !TREE_PERMANENT (decl)) { push_obstacks (&permanent_obstack, &permanent_obstack); decl = copy_node (decl); if (TREE_CODE (type) == ARRAY_TYPE) { tree itype = TYPE_DOMAIN (type); if (itype && ! TREE_PERMANENT (itype)) { itype = build_index_type (copy_to_permanent (TYPE_MAX_VALUE (itype))); type = build_cplus_array_type (TREE_TYPE (type), itype); TREE_TYPE (decl) = type; } } pop_obstacks (); } context = (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl)) ? DECL_CLASS_CONTEXT (decl) : DECL_CONTEXT (decl); if (initialized && context && TREE_CODE (context) == NAMESPACE_DECL && context != current_namespace && TREE_CODE (decl) == VAR_DECL) { /* When parsing the initializer, lookup should use the object's namespace. */ push_decl_namespace (context); } /* We are only interested in class contexts, later. */ if (context && TREE_CODE (context) == NAMESPACE_DECL) context = NULL_TREE; if (initialized) /* Is it valid for this decl to have an initializer at all? If not, set INITIALIZED to zero, which will indirectly tell `cp_finish_decl' to ignore the initializer once it is parsed. */ switch (TREE_CODE (decl)) { case TYPE_DECL: /* typedef foo = bar means give foo the same type as bar. We haven't parsed bar yet, so `cp_finish_decl' will fix that up. Any other case of an initialization in a TYPE_DECL is an error. */ if (pedantic || list_length (declspecs) > 1) { cp_error ("typedef `%D' is initialized", decl); initialized = 0; } break; case FUNCTION_DECL: cp_error ("function `%#D' is initialized like a variable", decl); initialized = 0; break; default: if (! processing_template_decl) { if (type != error_mark_node) { if (TYPE_SIZE (type) != NULL_TREE && ! TREE_CONSTANT (TYPE_SIZE (type))) { cp_error ("variable-sized object `%D' may not be initialized", decl); initialized = 0; } if (TREE_CODE (type) == ARRAY_TYPE && TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) { cp_error ("elements of array `%#D' have incomplete type", decl); initialized = 0; } } } } if (initialized) { if (! toplevel_bindings_p () && DECL_EXTERNAL (decl)) cp_warning ("declaration of `%#D' has `extern' and is initialized", decl); DECL_EXTERNAL (decl) = 0; if (toplevel_bindings_p ()) TREE_STATIC (decl) = 1; /* Tell `pushdecl' this is an initialized decl even though we don't yet have the initializer expression. Also tell `cp_finish_decl' it may store the real initializer. */ DECL_INITIAL (decl) = error_mark_node; } #ifdef SET_DEFAULT_DECL_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES (decl, attributes); #endif /* Set attributes here so if duplicate decl, will have proper attributes. */ cplus_decl_attributes (decl, attributes, prefix_attributes); if (context && TYPE_SIZE (complete_type (context)) != NULL_TREE) { push_nested_class (context, 2); if (TREE_CODE (decl) == VAR_DECL) { tree field = lookup_field (context, DECL_NAME (decl), 0, 0); if (field == NULL_TREE || TREE_CODE (field) != VAR_DECL) cp_error ("`%#D' is not a static member of `%#T'", decl, context); else { if (DECL_CONTEXT (field) != context) { cp_pedwarn ("ANSI C++ does not permit `%T::%D' to be defined as `%T::%D'", DECL_CONTEXT (field), DECL_NAME (decl), context, DECL_NAME (decl)); DECL_CONTEXT (decl) = DECL_CONTEXT (field); } /* Static data member are tricky; an in-class initialization still doesn't provide a definition, so the in-class declaration will have DECL_EXTERNAL set, but will have an initialization. Thus, duplicate_decls won't warn about this situation, and so we check here. */ if (DECL_INITIAL (decl) && DECL_INITIAL (field)) cp_error ("duplicate initialization of %D", decl); if (duplicate_decls (decl, field)) decl = field; } } else { tree field = check_classfn (context, decl); if (field && duplicate_decls (decl, field)) decl = field; } /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */ DECL_IN_AGGR_P (decl) = 0; if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl)) || CLASSTYPE_USE_TEMPLATE (context)) { SET_DECL_TEMPLATE_SPECIALIZATION (decl); /* [temp.expl.spec] An explicit specialization of a static data member of a template is a definition if the declaration includes an initializer; otherwise, it is a declaration. We check for processing_specialization so this only applies to the new specialization syntax. */ if (DECL_INITIAL (decl) == NULL_TREE && processing_specialization) DECL_EXTERNAL (decl) = 1; } if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)) cp_pedwarn ("declaration of `%#D' outside of class is not definition", decl); } /* Add this decl to the current binding level, but not if it comes from another scope, e.g. a static member variable. TEM may equal DECL or it may be a previous decl of the same name. */ if ((TREE_CODE (decl) != PARM_DECL && DECL_CONTEXT (decl) != NULL_TREE /* Definitions of namespace members outside their namespace are possible. */ && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL) || (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ()) || TREE_CODE (type) == LANG_TYPE /* The declaration of template specializations does not affect the functions available for overload resolution, so we do not call pushdecl. */ || (TREE_CODE (decl) == FUNCTION_DECL && DECL_TEMPLATE_SPECIALIZATION (decl))) tem = decl; else tem = pushdecl (decl); if (processing_template_decl) { if (! current_function_decl) tem = push_template_decl (tem); else if (minimal_parse_mode) DECL_VINDEX (tem) = build_min_nt (DECL_STMT, copy_to_permanent (declarator), copy_to_permanent (declspecs), NULL_TREE); } #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) /* Tell the back-end to use or not use .common as appropriate. If we say -fconserve-space, we want this to save .data space, at the expense of wrong semantics. If we say -fno-conserve-space, we want this to produce errors about redefs; to do this we force variables into the data segment. */ DECL_COMMON (tem) = flag_conserve_space || ! TREE_PUBLIC (tem); #endif if (! processing_template_decl) start_decl_1 (tem); /* Corresponding pop_obstacks is done in `cp_finish_decl'. */ push_obstacks_nochange (); #if 0 /* We have no way of knowing whether the initializer will need to be evaluated at run-time or not until we've parsed it, so let's just put it in the permanent obstack. (jason) */ if (init_written && ! (TREE_CODE (tem) == PARM_DECL || (TREE_READONLY (tem) && (TREE_CODE (tem) == VAR_DECL || TREE_CODE (tem) == FIELD_DECL)))) { /* When parsing and digesting the initializer, use temporary storage. Do this even if we will ignore the value. */ if (toplevel_bindings_p () && debug_temp_inits) { if (processing_template_decl || TYPE_NEEDS_CONSTRUCTING (type) || TREE_CODE (type) == REFERENCE_TYPE) /* In this case, the initializer must lay down in permanent storage, since it will be saved until `finish_file' is run. */ ; else temporary_allocation (); } } #endif return tem; } void start_decl_1 (decl) tree decl; { tree type = TREE_TYPE (decl); int initialized = (DECL_INITIAL (decl) != NULL_TREE); if (type == error_mark_node) return; /* If this type of object needs a cleanup, and control may jump past it, make a new binding level so that it is cleaned up only when it is initialized first. */ if (TYPE_NEEDS_DESTRUCTOR (type) && current_binding_level->more_cleanups_ok == 0) pushlevel_temporary (1); if (initialized) /* Is it valid for this decl to have an initializer at all? If not, set INITIALIZED to zero, which will indirectly tell `cp_finish_decl' to ignore the initializer once it is parsed. */ { /* Don't allow initializations for incomplete types except for arrays which might be completed by the initialization. */ if (TYPE_SIZE (complete_type (type)) != NULL_TREE) ; /* A complete type is ok. */ else if (TREE_CODE (type) != ARRAY_TYPE) { cp_error ("variable `%#D' has initializer but incomplete type", decl); initialized = 0; type = TREE_TYPE (decl) = error_mark_node; } else if (TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE) { if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)) cp_error ("elements of array `%#D' have incomplete type", decl); /* else we already gave an error in start_decl. */ initialized = 0; } } if (!initialized && TREE_CODE (decl) != TYPE_DECL && TREE_CODE (decl) != TEMPLATE_DECL && IS_AGGR_TYPE (type) && ! DECL_EXTERNAL (decl)) { if ((! processing_template_decl || ! uses_template_parms (type)) && TYPE_SIZE (complete_type (type)) == NULL_TREE) { cp_error ("aggregate `%#D' has incomplete type and cannot be initialized", decl); /* Change the type so that assemble_variable will give DECL an rtl we can live with: (mem (const_int 0)). */ type = TREE_TYPE (decl) = error_mark_node; } else { /* If any base type in the hierarchy of TYPE needs a constructor, then we set initialized to 1. This way any nodes which are created for the purposes of initializing this aggregate will live as long as it does. This is necessary for global aggregates which do not have their initializers processed until the end of the file. */ initialized = TYPE_NEEDS_CONSTRUCTING (type); } } #if 0 /* We don't do this yet for GNU C++. */ /* For a local variable, define the RTL now. */ if (! toplevel_bindings_p () /* But not if this is a duplicate decl and we preserved the rtl from the previous one (which may or may not happen). */ && DECL_RTL (tem) == NULL_RTX) { if (TYPE_SIZE (TREE_TYPE (tem)) != NULL_TREE) expand_decl (tem); else if (TREE_CODE (TREE_TYPE (tem)) == ARRAY_TYPE && DECL_INITIAL (tem) != NULL_TREE) expand_decl (tem); } #endif if (! initialized) DECL_INITIAL (decl) = NULL_TREE; } /* Handle initialization of references. These three arguments are from `cp_finish_decl', and have the same meaning here that they do there. Quotes on semantics can be found in ARM 8.4.3. */ static void grok_reference_init (decl, type, init) tree decl, type, init; { tree tmp; if (init == NULL_TREE) { if ((DECL_LANG_SPECIFIC (decl) == 0 || DECL_IN_AGGR_P (decl) == 0) && ! DECL_THIS_EXTERN (decl)) { cp_error ("`%D' declared as reference but not initialized", decl); if (TREE_CODE (decl) == VAR_DECL) SET_DECL_REFERENCE_SLOT (decl, error_mark_node); } return; } if (init == error_mark_node) return; if (TREE_CODE (type) == REFERENCE_TYPE && TREE_CODE (init) == CONSTRUCTOR) { cp_error ("ANSI C++ forbids use of initializer list to initialize reference `%D'", decl); return; } if (TREE_CODE (init) == TREE_LIST) init = build_compound_expr (init); if (TREE_CODE (TREE_TYPE (init)) == REFERENCE_TYPE) init = convert_from_reference (init); if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) { /* Note: default conversion is only called in very special cases. */ init = default_conversion (init); } tmp = convert_to_reference (type, init, CONV_IMPLICIT, LOOKUP_SPECULATIVELY|LOOKUP_NORMAL|DIRECT_BIND, decl); if (tmp == error_mark_node) goto fail; else if (tmp != NULL_TREE) { init = tmp; DECL_INITIAL (decl) = save_expr (init); } else { cp_error ("cannot initialize `%T' from `%T'", type, TREE_TYPE (init)); goto fail; } /* ?? Can this be optimized in some cases to hand back the DECL_INITIAL slot?? */ if (TYPE_SIZE (TREE_TYPE (type))) { init = convert_from_reference (decl); if (TREE_PERMANENT (decl)) init = copy_to_permanent (init); SET_DECL_REFERENCE_SLOT (decl, init); } if (TREE_STATIC (decl) && ! TREE_CONSTANT (DECL_INITIAL (decl))) { expand_static_init (decl, DECL_INITIAL (decl)); DECL_INITIAL (decl) = NULL_TREE; } return; fail: if (TREE_CODE (decl) == VAR_DECL) SET_DECL_REFERENCE_SLOT (decl, error_mark_node); return; } /* Fill in DECL_INITIAL with some magical value to prevent expand_decl from mucking with forces it does not comprehend (i.e. initialization with a constructor). If we are at global scope and won't go into COMMON, fill it in with a dummy CONSTRUCTOR to force the variable into .data; otherwise we can use error_mark_node. */ static tree obscure_complex_init (decl, init) tree decl, init; { if (! flag_no_inline && TREE_STATIC (decl)) { if (extract_init (decl, init)) return NULL_TREE; } #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS) if (toplevel_bindings_p () && ! DECL_COMMON (decl)) DECL_INITIAL (decl) = build (CONSTRUCTOR, TREE_TYPE (decl), NULL_TREE, NULL_TREE); else #endif DECL_INITIAL (decl) = error_mark_node; return init; } /* Issue an error message if DECL is an uninitialized const variable. */ static void check_for_uninitialized_const_var (decl) tree decl; { tree type = TREE_TYPE (decl); /* ``Unless explicitly declared extern, a const object does not have external linkage and must be initialized. ($8.4; $12.1)'' ARM 7.1.6 */ if (TREE_CODE (decl) == VAR_DECL && TREE_CODE (type) != REFERENCE_TYPE && CP_TYPE_CONST_P (type) && !TYPE_NEEDS_CONSTRUCTING (type) && !DECL_INITIAL (decl)) cp_error ("uninitialized const `%D'", decl); } /* Finish processing of a declaration; install its line number and initial value. If the length of an array type is not known before, it must be determined now, from the initial value, or it is an error. Call `pop_obstacks' iff NEED_POP is nonzero. For C++, `cp_finish_decl' must be fairly evasive: it must keep initializers for aggregates that have constructors alive on the permanent obstack, so that the global initializing functions can be written at the end. INIT0 holds the value of an initializer that should be allowed to escape the normal rules. FLAGS is LOOKUP_ONLYCONVERTING is the = init syntax was used, else 0 if the (init) syntax was used. For functions that take default parameters, DECL points to its "maximal" instantiation. `cp_finish_decl' must then also declared its subsequently lower and lower forms of instantiation, checking for ambiguity as it goes. This can be sped up later. */ void cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) tree decl, init; tree asmspec_tree; int need_pop; int flags; { register tree type; tree cleanup = NULL_TREE, ttype = NULL_TREE; int was_incomplete; int temporary = allocation_temporary_p (); char *asmspec = NULL; int was_readonly = 0; int already_used = 0; tree core_type; /* If this is 0, then we did not change obstacks. */ if (! decl) { if (init) error ("assignment (not initialization) in declaration"); return; } /* If a name was specified, get the string. */ if (asmspec_tree) asmspec = TREE_STRING_POINTER (asmspec_tree); if (init && TREE_CODE (init) == NAMESPACE_DECL) { cp_error ("Cannot initialize `%D' to namespace `%D'", decl, init); init = NULL_TREE; } if (current_class_type && DECL_REAL_CONTEXT (decl) == current_class_type && TYPE_BEING_DEFINED (current_class_type) && (DECL_INITIAL (decl) || init)) DECL_DEFINED_IN_CLASS_P (decl) = 1; if (TREE_CODE (decl) == VAR_DECL && DECL_CONTEXT (decl) && TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL && DECL_CONTEXT (decl) != current_namespace && init) { /* Leave the namespace of the object. */ pop_decl_namespace (); } /* If the type of the thing we are declaring either has a constructor, or has a virtual function table pointer, AND its initialization was accepted by `start_decl', then we stayed on the permanent obstack through the declaration, otherwise, changed obstacks as GCC would. */ type = TREE_TYPE (decl); if (type == error_mark_node) { if (toplevel_bindings_p () && temporary) end_temporary_allocation (); return; } if (TYPE_HAS_MUTABLE_P (type)) TREE_READONLY (decl) = 0; if (processing_template_decl) { if (init && DECL_INITIAL (decl)) DECL_INITIAL (decl) = init; if (minimal_parse_mode && ! DECL_ARTIFICIAL (decl)) { tree stmt = DECL_VINDEX (decl); /* If the decl is declaring a member of a local class (in a template function), the DECL_VINDEX will either be NULL, or it will be an actual virtual function index, not a DECL_STMT. */ if (stmt != NULL_TREE && TREE_CODE (stmt) == DECL_STMT) { DECL_VINDEX (decl) = NULL_TREE; TREE_OPERAND (stmt, 2) = copy_to_permanent (init); add_tree (stmt); } } goto finish_end0; } /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { if (init && DECL_INITIAL (decl)) { /* typedef foo = bar; store the type of bar as the type of foo. */ TREE_TYPE (decl) = type = TREE_TYPE (init); DECL_INITIAL (decl) = init = NULL_TREE; } if (type != error_mark_node && IS_AGGR_TYPE (type) && DECL_NAME (decl)) { if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type) cp_warning ("shadowing previous type declaration of `%#D'", decl); set_identifier_type_value (DECL_NAME (decl), type); CLASSTYPE_GOT_SEMICOLON (type) = 1; } GNU_xref_decl (current_function_decl, decl); /* If we have installed this as the canonical typedef for this type, and that type has not been defined yet, delay emitting the debug information for it, as we will emit it later. */ if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl && TYPE_SIZE (TREE_TYPE (decl)) == NULL_TREE) TYPE_DECL_SUPPRESS_DEBUG (decl) = 1; rest_of_decl_compilation (decl, NULL_PTR, DECL_CONTEXT (decl) == NULL_TREE, at_eof); goto finish_end; } if (TREE_CODE (decl) != FUNCTION_DECL) { ttype = target_type (type); } if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) && TYPE_NEEDS_CONSTRUCTING (type)) { /* Currently, GNU C++ puts constants in text space, making them impossible to initialize. In the future, one would hope for an operating system which understood the difference between initialization and the running of a program. */ was_readonly = 1; TREE_READONLY (decl) = 0; } if (TREE_CODE (decl) == FIELD_DECL) { if (init && init != error_mark_node) my_friendly_assert (TREE_PERMANENT (init), 147); if (asmspec) { /* This must override the asm specifier which was placed by grokclassfn. Lay this out fresh. */ DECL_RTL (TREE_TYPE (decl)) = NULL_RTX; DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); make_decl_rtl (decl, asmspec, 0); } } /* If `start_decl' didn't like having an initialization, ignore it now. */ else if (init != NULL_TREE && DECL_INITIAL (decl) == NULL_TREE) init = NULL_TREE; else if (DECL_EXTERNAL (decl)) ; else if (TREE_CODE (type) == REFERENCE_TYPE || (TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE_REFERENCE (type))) { if (TREE_STATIC (decl)) make_decl_rtl (decl, NULL_PTR, toplevel_bindings_p () || pseudo_global_level_p ()); grok_reference_init (decl, type, init); init = NULL_TREE; } GNU_xref_decl (current_function_decl, decl); core_type = type; while (TREE_CODE (core_type) == ARRAY_TYPE) core_type = TREE_TYPE (core_type); if (TREE_CODE (decl) == FIELD_DECL) ; else if (TREE_CODE (decl) == CONST_DECL) { my_friendly_assert (TREE_CODE (decl) != REFERENCE_TYPE, 148); DECL_INITIAL (decl) = init; /* This will keep us from needing to worry about our obstacks. */ my_friendly_assert (init != NULL_TREE, 149); init = NULL_TREE; } else if (init) { if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) { if (TREE_CODE (type) == ARRAY_TYPE) init = digest_init (type, init, (tree *) 0); else if (TREE_CODE (init) == CONSTRUCTOR && TREE_HAS_CONSTRUCTOR (init)) { if (TYPE_NON_AGGREGATE_CLASS (type)) { cp_error ("`%D' must be initialized by constructor, not by `{...}'", decl); init = error_mark_node; } else goto dont_use_constructor; } } else { dont_use_constructor: if (TREE_CODE (init) != TREE_VEC) init = store_init_value (decl, init); } if (init) /* We must hide the initializer so that expand_decl won't try to do something it does not understand. */ init = obscure_complex_init (decl, init); } else if (DECL_EXTERNAL (decl)) ; else if (TREE_CODE_CLASS (TREE_CODE (type)) == 't' && (IS_AGGR_TYPE (type) || TYPE_NEEDS_CONSTRUCTING (type))) { if (! TYPE_NEEDS_CONSTRUCTING (core_type)) { if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)) cp_error ("structure `%D' with uninitialized const members", decl); if (CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) cp_error ("structure `%D' with uninitialized reference members", decl); } check_for_uninitialized_const_var (decl); if (TYPE_SIZE (type) != NULL_TREE && TYPE_NEEDS_CONSTRUCTING (type)) init = obscure_complex_init (decl, NULL_TREE); } else check_for_uninitialized_const_var (decl); /* For top-level declaration, the initial value was read in the temporary obstack. MAXINDEX, rtl, etc. to be made below must go in the permanent obstack; but don't discard the temporary data yet. */ if (toplevel_bindings_p () && temporary) end_temporary_allocation (); /* Deduce size of array from initialization, if not already known. */ if (TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE && TREE_CODE (decl) != TYPE_DECL) { int do_default = (TREE_STATIC (decl) /* Even if pedantic, an external linkage array may have incomplete type at first. */ ? pedantic && ! DECL_EXTERNAL (decl) : !DECL_EXTERNAL (decl)); tree initializer = init ? init : DECL_INITIAL (decl); int failure = complete_array_type (type, initializer, do_default); if (failure == 1) cp_error ("initializer fails to determine size of `%D'", decl); if (failure == 2) { if (do_default) cp_error ("array size missing in `%D'", decl); /* If a `static' var's size isn't known, make it extern as well as static, so it does not get allocated. If it's not `static', then don't mark it extern; finish_incomplete_decl will give it a default size and it will get allocated. */ else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) DECL_EXTERNAL (decl) = 1; } if (pedantic && TYPE_DOMAIN (type) != NULL_TREE && tree_int_cst_lt (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), integer_zero_node)) cp_error ("zero-size array `%D'", decl); layout_decl (decl, 0); } if (TREE_CODE (decl) == VAR_DECL) { if (DECL_SIZE (decl) == NULL_TREE && TYPE_SIZE (complete_type (TREE_TYPE (decl))) != NULL_TREE) layout_decl (decl, 0); if (TREE_STATIC (decl) && DECL_SIZE (decl) == NULL_TREE) { /* A static variable with an incomplete type: that is an error if it is initialized. Otherwise, let it through, but if it is not `extern' then it may cause an error message later. */ if (DECL_INITIAL (decl) != NULL_TREE) cp_error ("storage size of `%D' isn't known", decl); init = NULL_TREE; } else if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE) { /* An automatic variable with an incomplete type: that is an error. Don't talk about array types here, since we took care of that message in grokdeclarator. */ cp_error ("storage size of `%D' isn't known", decl); TREE_TYPE (decl) = error_mark_node; } else if (!DECL_EXTERNAL (decl) && IS_AGGR_TYPE (ttype)) /* Let debugger know it should output info for this type. */ note_debug_info_needed (ttype); if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl)) note_debug_info_needed (DECL_CONTEXT (decl)); if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl)) && DECL_SIZE (decl) != NULL_TREE && ! TREE_CONSTANT (DECL_SIZE (decl))) { if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST) constant_expression_warning (DECL_SIZE (decl)); else cp_error ("storage size of `%D' isn't constant", decl); } if (! DECL_EXTERNAL (decl) && TYPE_NEEDS_DESTRUCTOR (type) /* Cleanups for static variables are handled by `finish_file'. */ && ! TREE_STATIC (decl)) { int yes = suspend_momentary (); cleanup = maybe_build_cleanup (decl); resume_momentary (yes); } } /* PARM_DECLs get cleanups, too. */ else if (TREE_CODE (decl) == PARM_DECL && TYPE_NEEDS_DESTRUCTOR (type)) { if (temporary) end_temporary_allocation (); cleanup = maybe_build_cleanup (decl); if (temporary) resume_temporary_allocation (); } /* Output the assembler code and/or RTL code for variables and functions, unless the type is an undefined structure or union. If not, it will get done when the type is completed. */ was_incomplete = (DECL_SIZE (decl) == NULL_TREE); if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == RESULT_DECL) { /* ??? FIXME: What about nested classes? */ int toplev = toplevel_bindings_p () || pseudo_global_level_p (); int was_temp = (TREE_STATIC (decl) && TYPE_NEEDS_DESTRUCTOR (type) && allocation_temporary_p ()); if (was_temp) end_temporary_allocation (); /* Static data in a function with comdat linkage also has comdat linkage. */ if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl) /* Don't mess with __FUNCTION__. */ && ! TREE_ASM_WRITTEN (decl) && current_function_decl && DECL_CONTEXT (decl) == current_function_decl && (DECL_THIS_INLINE (current_function_decl) || DECL_TEMPLATE_INSTANTIATION (current_function_decl)) && TREE_PUBLIC (current_function_decl)) { /* Rather than try to get this right with inlining, we suppress inlining of such functions. */ current_function_cannot_inline = "function with static variable cannot be inline"; /* If flag_weak, we don't need to mess with this, as we can just make the function weak, and let it refer to its unique local copy. This works because we don't allow the function to be inlined. */ if (! flag_weak) { if (DECL_INTERFACE_KNOWN (current_function_decl)) { TREE_PUBLIC (decl) = 1; DECL_EXTERNAL (decl) = DECL_EXTERNAL (current_function_decl); } else if (DECL_INITIAL (decl) == NULL_TREE || DECL_INITIAL (decl) == error_mark_node) { TREE_PUBLIC (decl) = 1; DECL_COMMON (decl) = 1; } /* else we lose. We can only do this if we can use common, which we can't if it has been initialized. */ if (TREE_PUBLIC (decl)) DECL_ASSEMBLER_NAME (decl) = build_static_name (current_function_decl, DECL_NAME (decl)); else if (! DECL_ARTIFICIAL (decl)) { cp_warning_at ("sorry: semantics of inline function static data `%#D' are wrong (you'll wind up with multiple copies)", decl); cp_warning_at (" you can work around this by removing the initializer", decl); } } } else if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl) && DECL_COMDAT (decl)) /* Set it up again; we might have set DECL_INITIAL since the last time. */ comdat_linkage (decl); if (TREE_CODE (decl) == VAR_DECL && DECL_VIRTUAL_P (decl)) make_decl_rtl (decl, NULL_PTR, toplev); else if (TREE_CODE (decl) == VAR_DECL && TREE_READONLY (decl) && DECL_INITIAL (decl) != NULL_TREE && DECL_INITIAL (decl) != error_mark_node && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))) { DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl)); if (asmspec) DECL_ASSEMBLER_NAME (decl) = get_identifier (asmspec); if (! toplev && TREE_STATIC (decl) && ! TREE_SIDE_EFFECTS (decl) && ! TREE_PUBLIC (decl) && ! DECL_EXTERNAL (decl) && ! TYPE_NEEDS_DESTRUCTOR (type) && DECL_MODE (decl) != BLKmode) { /* If this variable is really a constant, then fill its DECL_RTL slot with something which won't take up storage. If something later should take its address, we can always give it legitimate RTL at that time. */ DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0); TREE_ASM_WRITTEN (decl) = 1; } else if (toplev && ! TREE_PUBLIC (decl)) { /* If this is a static const, change its apparent linkage if it belongs to a #pragma interface. */ if (!interface_unknown) { TREE_PUBLIC (decl) = 1; DECL_EXTERNAL (decl) = interface_only; } make_decl_rtl (decl, asmspec, toplev); } else rest_of_decl_compilation (decl, asmspec, toplev, at_eof); } else if (TREE_CODE (decl) == VAR_DECL && DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl)) { if (TREE_STATIC (decl)) { if (init == NULL_TREE #ifdef DEFAULT_STATIC_DEFS /* If this code is dead, then users must explicitly declare static member variables outside the class def'n as well. */ && TYPE_NEEDS_CONSTRUCTING (type) #endif ) { DECL_EXTERNAL (decl) = 1; make_decl_rtl (decl, asmspec, 1); } else rest_of_decl_compilation (decl, asmspec, toplev, at_eof); } else /* Just a constant field. Should not need any rtl. */ goto finish_end0; } else rest_of_decl_compilation (decl, asmspec, toplev, at_eof); if (was_temp) resume_temporary_allocation (); if (type != error_mark_node && TYPE_LANG_SPECIFIC (core_type) && CLASSTYPE_ABSTRACT_VIRTUALS (core_type)) abstract_virtuals_error (decl, core_type); else if ((TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (type))) abstract_virtuals_error (decl, TREE_TYPE (type)); if (TYPE_LANG_SPECIFIC (core_type) && IS_SIGNATURE (core_type)) signature_error (decl, core_type); else if ((TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) && TYPE_LANG_SPECIFIC (TREE_TYPE (type)) && IS_SIGNATURE (TREE_TYPE (type))) signature_error (decl, TREE_TYPE (type)); if (TREE_CODE (decl) == FUNCTION_DECL) ; else if (DECL_EXTERNAL (decl) && ! (DECL_LANG_SPECIFIC (decl) && DECL_NOT_REALLY_EXTERN (decl))) { if (init) DECL_INITIAL (decl) = init; } else if (TREE_STATIC (decl) && type != error_mark_node) { /* Cleanups for static variables are handled by `finish_file'. */ if (TYPE_NEEDS_CONSTRUCTING (type) || init != NULL_TREE || TYPE_NEEDS_DESTRUCTOR (type)) expand_static_init (decl, init); } else if (! toplev) { /* This is a declared decl which must live until the end of the binding contour. It may need a cleanup. */ /* Recompute the RTL of a local array now if it used to be an incomplete type. */ if (was_incomplete && ! TREE_STATIC (decl)) { /* If we used it already as memory, it must stay in memory. */ TREE_ADDRESSABLE (decl) = TREE_USED (decl); /* If it's still incomplete now, no init will save it. */ if (DECL_SIZE (decl) == NULL_TREE) DECL_INITIAL (decl) = NULL_TREE; expand_decl (decl); } else if (! TREE_ASM_WRITTEN (decl) && (TYPE_SIZE (type) != NULL_TREE || TREE_CODE (type) == ARRAY_TYPE)) { /* Do this here, because we did not expand this decl's rtl in start_decl. */ if (DECL_RTL (decl) == NULL_RTX) expand_decl (decl); else if (cleanup) { /* XXX: Why don't we use decl here? */ /* Ans: Because it was already expanded? */ if (! expand_decl_cleanup (NULL_TREE, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); /* Cleanup used up here. */ cleanup = NULL_TREE; } } if (current_binding_level->is_for_scope) { struct binding_level *outer = current_binding_level->level_chain; /* Check to see if the same name is already bound at the outer level, either because it was directly declared, or because a dead for-decl got preserved. In either case, the code would not have been valid under the ARM scope rules, so clear is_for_scope for the current_binding_level. Otherwise, we need to preserve the temp slot for decl to last into the outer binding level. */ tree outer_binding = TREE_CHAIN (IDENTIFIER_BINDING (DECL_NAME (decl))); if (outer_binding && BINDING_LEVEL (outer_binding) == outer && (TREE_CODE (BINDING_VALUE (outer_binding)) == VAR_DECL) && DECL_DEAD_FOR_LOCAL (BINDING_VALUE (outer_binding))) { BINDING_VALUE (outer_binding) = DECL_SHADOWED_FOR_VAR (BINDING_VALUE (outer_binding)); current_binding_level->is_for_scope = 0; } else if (DECL_IN_MEMORY_P (decl)) preserve_temp_slots (DECL_RTL (decl)); } expand_start_target_temps (); if (DECL_SIZE (decl) && type != error_mark_node) { /* Compute and store the initial value. */ expand_decl_init (decl); already_used = TREE_USED (decl) || TREE_USED (type); if (init || TYPE_NEEDS_CONSTRUCTING (type)) { emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl)); expand_aggr_init (decl, init, flags); } /* Set this to 0 so we can tell whether an aggregate which was initialized was ever used. Don't do this if it has a destructor, so we don't complain about the 'resource allocation is initialization' idiom. */ /* Now set attribute((unused)) on types so decls of that type will be marked used. (see TREE_USED, above.) This avoids the warning problems this particular code tried to work around. */ if (TYPE_NEEDS_CONSTRUCTING (type) && ! already_used && cleanup == NULL_TREE && DECL_NAME (decl)) TREE_USED (decl) = 0; if (already_used) TREE_USED (decl) = 1; } /* Cleanup any temporaries needed for the initial value. */ expand_end_target_temps (); if (DECL_SIZE (decl) && type != error_mark_node) { /* Store the cleanup, if there was one. */ if (cleanup) { if (! expand_decl_cleanup (decl, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); } } } finish_end0: /* Undo call to `pushclass' that was done in `start_decl' due to initialization of qualified member variable. I.e., Foo::x = 10; */ { tree context = DECL_REAL_CONTEXT (decl); if (context && TREE_CODE_CLASS (TREE_CODE (context)) == 't' && (TREE_CODE (decl) == VAR_DECL /* We also have a pushclass done that we need to undo here if we're at top level and declare a method. */ || TREE_CODE (decl) == FUNCTION_DECL) /* If size hasn't been set, we're still defining it, and therefore inside the class body; don't pop the binding level.. */ && TYPE_SIZE (context) != NULL_TREE && context == current_class_type) pop_nested_class (); } } finish_end: /* If requested, warn about definitions of large data objects. */ if (warn_larger_than && ! processing_template_decl && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) && !DECL_EXTERNAL (decl)) { register tree decl_size = DECL_SIZE (decl); if (decl_size && TREE_CODE (decl_size) == INTEGER_CST) { unsigned units = TREE_INT_CST_LOW (decl_size) / BITS_PER_UNIT; if (units > larger_than_size) warning_with_decl (decl, "size of `%s' is %u bytes", units); } } if (need_pop) { /* Resume permanent allocation, if not within a function. */ /* The corresponding push_obstacks_nochange is in start_decl, start_method, groktypename, and in grokfield. */ pop_obstacks (); } if (was_readonly) TREE_READONLY (decl) = 1; } /* This is here for a midend callback from c-common.c */ void finish_decl (decl, init, asmspec_tree) tree decl, init; tree asmspec_tree; { cp_finish_decl (decl, init, asmspec_tree, 1, 0); } void expand_static_init (decl, init) tree decl; tree init; { tree oldstatic = value_member (decl, static_aggregates); if (oldstatic) { if (TREE_PURPOSE (oldstatic) && init != NULL_TREE) cp_error ("multiple initializations given for `%D'", decl); } else if (! toplevel_bindings_p ()) { /* Emit code to perform this initialization but once. */ tree temp; /* Remember this information until end of file. */ push_obstacks (&permanent_obstack, &permanent_obstack); /* Emit code to perform this initialization but once. This code looks like: static int temp = 0; if (!temp) { // Do initialization. temp = 1; // Register variable for destruction at end of program. } Note that the `temp' variable is only set to 1 *after* the initialization is complete. This ensures that an exception, thrown during the construction, will cause the variable to reinitialized when we pass through this code again, as per: [stmt.dcl] If the initialization exits by throwing an exception, the initialization is not complete, so it will be tried again the next time control enters the declaration. In theory, this process should be thread-safe, too; multiple threads should not be able to initialize the variable more than once. We don't yet attempt to ensure thread-safety. */ temp = get_temp_name (integer_type_node, 1); rest_of_decl_compilation (temp, NULL_PTR, 0, 0); /* Begin the conditional initialization. */ expand_start_cond (build_binary_op (EQ_EXPR, temp, integer_zero_node), 0); expand_start_target_temps (); /* Do the initialization itself. */ if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)) || (init && TREE_CODE (init) == TREE_LIST)) { expand_aggr_init (decl, init, 0); do_pending_stack_adjust (); } else if (init) expand_assignment (decl, init, 0, 0); /* Set TEMP to 1. */ expand_assignment (temp, integer_one_node, 0, 0); /* Cleanup any temporaries needed for the initial value. If destroying one of the temporaries causes an exception to be thrown, then the object itself has still been fully constructed. */ expand_end_target_temps (); /* Use atexit to register a function for destroying this static variable. */ if (TYPE_NEEDS_DESTRUCTOR (TREE_TYPE (decl))) { tree cleanup, fcall; static tree Atexit = 0; int saved_flag_access_control; if (Atexit == 0) { tree atexit_fndecl, PFV, pfvlist; /* Remember this information until end of file. */ push_obstacks (&permanent_obstack, &permanent_obstack); PFV = build_pointer_type (build_function_type (void_type_node, void_list_node)); pfvlist = tree_cons (NULL_TREE, PFV, void_list_node); push_lang_context (lang_name_c); atexit_fndecl = builtin_function ("atexit", build_function_type (void_type_node, pfvlist), NOT_BUILT_IN, NULL_PTR); mark_used (atexit_fndecl); Atexit = default_conversion (atexit_fndecl); pop_lang_context (); pop_obstacks (); } /* Call build_cleanup before we enter the anonymous function so that any access checks will be done relative to the current scope, rather than the scope of the anonymous function. */ build_cleanup (decl); /* Now start the function. */ cleanup = start_anon_func (); /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer to the original function, rather than the anonymous one. That will make the back-end think that nested functions are in use, which causes confusion. */ saved_flag_access_control = flag_access_control; flag_access_control = 0; fcall = build_cleanup (decl); flag_access_control = saved_flag_access_control; /* Finish off the function. */ expand_expr_stmt (fcall); end_anon_func (); /* Call atexit with the cleanup function. */ mark_addressable (cleanup); cleanup = build_unary_op (ADDR_EXPR, cleanup, 0); fcall = build_function_call (Atexit, expr_tree_cons (NULL_TREE, cleanup, NULL_TREE)); expand_expr_stmt (fcall); } expand_end_cond (); /* Resume old (possibly temporary) allocation. */ pop_obstacks (); } else { /* This code takes into account memory allocation policy of `start_decl'. Namely, if TYPE_NEEDS_CONSTRUCTING does not hold for this object, then we must make permanent the storage currently in the temporary obstack. */ if (!TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl))) preserve_initializer (); static_aggregates = perm_tree_cons (init, decl, static_aggregates); } } /* Make TYPE a complete type based on INITIAL_VALUE. Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered, 2 if there was no information (in which case assume 0 if DO_DEFAULT). */ int complete_array_type (type, initial_value, do_default) tree type, initial_value; int do_default; { register tree maxindex = NULL_TREE; int value = 0; /* Allocate on the same obstack as TYPE. */ push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); if (initial_value) { /* Note MAXINDEX is really the maximum index, one less than the size. */ if (TREE_CODE (initial_value) == STRING_CST) { int eltsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (initial_value))); maxindex = build_int_2 ((TREE_STRING_LENGTH (initial_value) / eltsize) - 1, 0); } else if (TREE_CODE (initial_value) == CONSTRUCTOR) { tree elts = CONSTRUCTOR_ELTS (initial_value); maxindex = size_binop (MINUS_EXPR, integer_zero_node, size_one_node); for (; elts; elts = TREE_CHAIN (elts)) { if (TREE_PURPOSE (elts)) maxindex = TREE_PURPOSE (elts); else maxindex = size_binop (PLUS_EXPR, maxindex, size_one_node); } maxindex = copy_node (maxindex); } else { /* Make an error message unless that happened already. */ if (initial_value != error_mark_node) value = 1; else initial_value = NULL_TREE; /* Prevent further error messages. */ maxindex = build_int_2 (0, 0); } } if (!maxindex) { if (do_default) maxindex = build_int_2 (0, 0); value = 2; } if (maxindex) { tree itype; tree domain; domain = build_index_type (maxindex); TYPE_DOMAIN (type) = domain; if (! TREE_TYPE (maxindex)) TREE_TYPE (maxindex) = domain; if (initial_value) itype = TREE_TYPE (initial_value); else itype = NULL; if (itype && !TYPE_DOMAIN (itype)) TYPE_DOMAIN (itype) = domain; /* The type of the main variant should never be used for arrays of different sizes. It should only ever be completed with the size of the array. */ if (! TYPE_DOMAIN (TYPE_MAIN_VARIANT (type))) TYPE_DOMAIN (TYPE_MAIN_VARIANT (type)) = domain; } pop_obstacks(); /* Lay out the type now that we can get the real answer. */ layout_type (type); return value; } /* Return zero if something is declared to be a member of type CTYPE when in the context of CUR_TYPE. STRING is the error message to print in that case. Otherwise, quietly return 1. */ static int member_function_or_else (ctype, cur_type, string) tree ctype, cur_type; const char *string; { if (ctype && ctype != cur_type) { error (string, TYPE_NAME_STRING (ctype)); return 0; } return 1; } /* Subroutine of `grokdeclarator'. */ /* Generate errors possibly applicable for a given set of specifiers. This is for ARM $7.1.2. */ static void bad_specifiers (object, type, virtualp, quals, inlinep, friendp, raises) tree object; const char *type; int virtualp, quals, friendp, raises, inlinep; { if (virtualp) cp_error ("`%D' declared as a `virtual' %s", object, type); if (inlinep) cp_error ("`%D' declared as an `inline' %s", object, type); if (quals) cp_error ("`const' and `volatile' function specifiers on `%D' invalid in %s declaration", object, type); if (friendp) cp_error_at ("invalid friend declaration", object); if (raises) cp_error_at ("invalid exception specifications", object); } /* CTYPE is class type, or null if non-class. TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE or METHOD_TYPE. DECLARATOR is the function's name. VIRTUALP is truthvalue of whether the function is virtual or not. FLAGS are to be passed through to `grokclassfn'. QUALS are qualifiers indicating whether the function is `const' or `volatile'. RAISES is a list of exceptions that this function can raise. CHECK is 1 if we must find this method in CTYPE, 0 if we should not look, and -1 if we should not call `grokclassfn' at all. Returns `NULL_TREE' if something goes wrong, after issuing applicable error messages. */ static tree grokfndecl (ctype, type, declarator, orig_declarator, virtualp, flags, quals, raises, check, friendp, publicp, inlinep, funcdef_flag, template_count, in_namespace) tree ctype, type; tree declarator; tree orig_declarator; int virtualp; enum overload_flags flags; tree quals, raises; int check, friendp, publicp, inlinep, funcdef_flag, template_count; tree in_namespace; { tree cname, decl; int staticp = ctype && TREE_CODE (type) == FUNCTION_TYPE; int has_default_arg = 0; tree t; if (ctype) cname = TREE_CODE (TYPE_NAME (ctype)) == TYPE_DECL ? TYPE_IDENTIFIER (ctype) : TYPE_NAME (ctype); else cname = NULL_TREE; if (raises) { type = build_exception_variant (type, raises); } decl = build_lang_decl (FUNCTION_DECL, declarator, type); /* Propagate volatile out from type to decl. */ if (TYPE_VOLATILE (type)) TREE_THIS_VOLATILE (decl) = 1; /* If this decl has namespace scope, set that up. */ if (in_namespace) set_decl_namespace (decl, in_namespace, friendp); else if (publicp && ! ctype) DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); /* `main' and builtins have implicit 'C' linkage. */ if ((MAIN_NAME_P (declarator) || (IDENTIFIER_LENGTH (declarator) > 10 && IDENTIFIER_POINTER (declarator)[0] == '_' && IDENTIFIER_POINTER (declarator)[1] == '_' && strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0)) && current_lang_name == lang_name_cplusplus && ctype == NULL_TREE /* NULL_TREE means global namespace. */ && DECL_CONTEXT (decl) == NULL_TREE) DECL_LANGUAGE (decl) = lang_c; /* Should probably propagate const out from type to decl I bet (mrs). */ if (staticp) { DECL_STATIC_FUNCTION_P (decl) = 1; DECL_CONTEXT (decl) = ctype; } if (ctype) DECL_CLASS_CONTEXT (decl) = ctype; if (ctype == NULL_TREE && DECL_MAIN_P (decl)) { if (processing_template_decl) error ("cannot declare `main' to be a template"); if (inlinep) error ("cannot declare `main' to be inline"); else if (! publicp) error ("cannot declare `main' to be static"); inlinep = 0; publicp = 1; } /* Members of anonymous types and local classes have no linkage; make them internal. */ if (ctype && (ANON_AGGRNAME_P (TYPE_IDENTIFIER (ctype)) || hack_decl_function_context (TYPE_MAIN_DECL (ctype)))) publicp = 0; if (publicp) { /* [basic.link]: A name with no linkage (notably, the name of a class or enumeration declared in a local scope) shall not be used to declare an entity with linkage. Only check this for public decls for now. */ t = no_linkage_check (TREE_TYPE (decl)); if (t) { if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) { if (DECL_LANGUAGE (decl) == lang_c) /* Allow this; it's pretty common in C. */; else cp_pedwarn ("non-local function `%#D' uses anonymous type", decl); } else cp_pedwarn ("non-local function `%#D' uses local type `%T'", decl, t); } } TREE_PUBLIC (decl) = publicp; if (! publicp) { DECL_INTERFACE_KNOWN (decl) = 1; DECL_NOT_REALLY_EXTERN (decl) = 1; } if (inlinep) DECL_THIS_INLINE (decl) = DECL_INLINE (decl) = 1; DECL_EXTERNAL (decl) = 1; if (quals != NULL_TREE && TREE_CODE (type) == FUNCTION_TYPE) { cp_error ("%smember function `%D' cannot have `%T' method qualifier", (ctype ? "static " : "non-"), decl, TREE_VALUE (quals)); quals = NULL_TREE; } if (IDENTIFIER_OPNAME_P (DECL_NAME (decl))) grok_op_properties (decl, virtualp, check < 0); if (ctype && hack_decl_function_context (decl)) DECL_NO_STATIC_CHAIN (decl) = 1; for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) if (TREE_PURPOSE (t) && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) { has_default_arg = 1; break; } if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR) { if (funcdef_flag) cp_error ("defining explicit specialization `%D' in friend declaration", orig_declarator); else { if (PROCESSING_REAL_TEMPLATE_DECL_P ()) { /* Something like `template friend void f()'. */ cp_error ("template-id `%D' in declaration of primary template", orig_declarator); return NULL_TREE; } /* A friend declaration of the form friend void f<>(). Record the information in the TEMPLATE_ID_EXPR. */ SET_DECL_IMPLICIT_INSTANTIATION (decl); DECL_TEMPLATE_INFO (decl) = perm_tree_cons (TREE_OPERAND (orig_declarator, 0), TREE_OPERAND (orig_declarator, 1), NULL_TREE); if (has_default_arg) { cp_error ("default arguments are not allowed in declaration of friend template specialization `%D'", decl); return NULL_TREE; } if (inlinep) { cp_error ("`inline' is not allowed in declaration of friend template specialization `%D'", decl); return NULL_TREE; } } } if (has_default_arg) add_defarg_fn (decl); /* Plain overloading: will not be grok'd by grokclassfn. */ if (! ctype && ! processing_template_decl && DECL_LANGUAGE (decl) != lang_c && (! DECL_USE_TEMPLATE (decl) || name_mangling_version < 1)) set_mangled_name_for_decl (decl); if (funcdef_flag) /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced later with the BLOCK. */ DECL_INITIAL (decl) = error_mark_node; /* Caller will do the rest of this. */ if (check < 0) return decl; if (check && funcdef_flag) DECL_INITIAL (decl) = error_mark_node; if (flags == NO_SPECIAL && ctype && constructor_name (cname) == declarator) { tree tmp; /* Just handle constructors here. We could do this inside the following if stmt, but I think that the code is more legible by breaking this case out. See comments below for what each of the following calls is supposed to do. */ DECL_CONSTRUCTOR_P (decl) = 1; grokclassfn (ctype, decl, flags, quals); decl = check_explicit_specialization (orig_declarator, decl, template_count, 2 * (funcdef_flag != 0) + 4 * (friendp != 0)); if (decl == error_mark_node) return NULL_TREE; if ((! TYPE_FOR_JAVA (ctype) || check_java_method (decl)) && check) { tmp = check_classfn (ctype, decl); if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) tmp = DECL_TEMPLATE_RESULT(tmp); if (tmp && DECL_ARTIFICIAL (tmp)) cp_error ("definition of implicitly-declared `%D'", tmp); if (tmp && duplicate_decls (decl, tmp)) return tmp; } if (! grok_ctor_properties (ctype, decl)) return NULL_TREE; } else { tree tmp; /* Function gets the ugly name, field gets the nice one. This call may change the type of the function (because of default parameters)! */ if (ctype != NULL_TREE) grokclassfn (ctype, decl, flags, quals); decl = check_explicit_specialization (orig_declarator, decl, template_count, 2 * (funcdef_flag != 0) + 4 * (friendp != 0)); if (decl == error_mark_node) return NULL_TREE; if (ctype != NULL_TREE && (! TYPE_FOR_JAVA (ctype) || check_java_method (decl)) && check) { tmp = check_classfn (ctype, decl); if (tmp && TREE_CODE (tmp) == TEMPLATE_DECL) tmp = DECL_TEMPLATE_RESULT (tmp); if (tmp && DECL_STATIC_FUNCTION_P (tmp) && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) { /* Remove the `this' parm added by grokclassfn. XXX Isn't this done in start_function, too? */ revert_static_member_fn (&decl, NULL, NULL); last_function_parms = TREE_CHAIN (last_function_parms); } if (tmp && DECL_ARTIFICIAL (tmp)) cp_error ("definition of implicitly-declared `%D'", tmp); if (tmp) { /* Attempt to merge the declarations. This can fail, in the case of some illegal specialization declarations. */ if (!duplicate_decls (decl, tmp)) cp_error ("no `%#D' member function declared in class `%T'", decl, ctype); return tmp; } } if (ctype == NULL_TREE || check) return decl; if (virtualp) { DECL_VIRTUAL_P (decl) = 1; if (DECL_VINDEX (decl) == NULL_TREE) DECL_VINDEX (decl) = error_mark_node; IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1; } } return decl; } static tree grokvardecl (type, declarator, specbits_in, initialized, constp, in_namespace) tree type; tree declarator; RID_BIT_TYPE *specbits_in; int initialized; int constp; tree in_namespace; { tree decl; RID_BIT_TYPE specbits; specbits = *specbits_in; if (TREE_CODE (type) == OFFSET_TYPE) { /* If you declare a static member so that it can be initialized, the code will reach here. */ tree basetype = TYPE_OFFSET_BASETYPE (type); type = TREE_TYPE (type); decl = build_lang_field_decl (VAR_DECL, declarator, type); DECL_CONTEXT (decl) = basetype; DECL_CLASS_CONTEXT (decl) = basetype; DECL_ASSEMBLER_NAME (decl) = build_static_name (basetype, declarator); } else { tree context; if (in_namespace) context = in_namespace; else if (namespace_bindings_p () || RIDBIT_SETP (RID_EXTERN, specbits)) context = current_namespace; else context = NULL_TREE; decl = build_decl (VAR_DECL, declarator, complete_type (type)); if (context) set_decl_namespace (decl, context, 0); context = DECL_CONTEXT (decl); if (declarator && context && current_lang_name != lang_name_c) DECL_ASSEMBLER_NAME (decl) = build_static_name (context, declarator); } if (in_namespace) set_decl_namespace (decl, in_namespace, 0); if (RIDBIT_SETP (RID_EXTERN, specbits)) { DECL_THIS_EXTERN (decl) = 1; DECL_EXTERNAL (decl) = !initialized; } /* In class context, static means one per class, public access, and static storage. */ if (DECL_CLASS_SCOPE_P (decl)) { TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; DECL_EXTERNAL (decl) = 0; } /* At top level, either `static' or no s.c. makes a definition (perhaps tentative), and absence of `static' makes it public. */ else if (toplevel_bindings_p ()) { TREE_PUBLIC (decl) = (RIDBIT_NOTSETP (RID_STATIC, specbits) && (DECL_THIS_EXTERN (decl) || ! constp)); TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); } /* Not at top level, only `static' makes a static definition. */ else { TREE_STATIC (decl) = !! RIDBIT_SETP (RID_STATIC, specbits); TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); } if (TREE_PUBLIC (decl)) { /* [basic.link]: A name with no linkage (notably, the name of a class or enumeration declared in a local scope) shall not be used to declare an entity with linkage. Only check this for public decls for now. */ tree t = no_linkage_check (TREE_TYPE (decl)); if (t) { if (ANON_AGGRNAME_P (TYPE_IDENTIFIER (t))) /* Ignore for now; `enum { foo } e' is pretty common. */; else cp_pedwarn ("non-local variable `%#D' uses local type `%T'", decl, t); } } return decl; } /* Create and return a canonical pointer to member function type, for TYPE, which is a POINTER_TYPE to a METHOD_TYPE. */ tree build_ptrmemfunc_type (type) tree type; { tree fields[4]; tree t; tree u; /* If a canonical type already exists for this type, use it. We use this method instead of type_hash_canon, because it only does a simple equality check on the list of field members. */ if ((t = TYPE_GET_PTRMEMFUNC_TYPE (type))) return t; push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); u = make_lang_type (UNION_TYPE); SET_IS_AGGR_TYPE (u, 0); fields[0] = build_lang_field_decl (FIELD_DECL, pfn_identifier, type); fields[1] = build_lang_field_decl (FIELD_DECL, delta2_identifier, delta_type_node); finish_builtin_type (u, "__ptrmemfunc_type", fields, 1, ptr_type_node); TYPE_NAME (u) = NULL_TREE; t = make_lang_type (RECORD_TYPE); /* Let the front-end know this is a pointer to member function... */ TYPE_PTRMEMFUNC_FLAG (t) = 1; /* ... and not really an aggregate. */ SET_IS_AGGR_TYPE (t, 0); fields[0] = build_lang_field_decl (FIELD_DECL, delta_identifier, delta_type_node); fields[1] = build_lang_field_decl (FIELD_DECL, index_identifier, delta_type_node); fields[2] = build_lang_field_decl (FIELD_DECL, pfn_or_delta2_identifier, u); finish_builtin_type (t, "__ptrmemfunc_type", fields, 2, ptr_type_node); pop_obstacks (); /* Zap out the name so that the back-end will give us the debugging information for this anonymous RECORD_TYPE. */ TYPE_NAME (t) = NULL_TREE; TYPE_SET_PTRMEMFUNC_TYPE (type, t); /* Seems to be wanted. */ CLASSTYPE_GOT_SEMICOLON (t) = 1; return t; } /* DECL is a VAR_DECL defined in-class, whose TYPE is also given. Check to see that the definition is valid. Issue appropriate error messages. Return 1 if the definition is particularly bad, or 0 otherwise. */ int check_static_variable_definition (decl, type) tree decl; tree type; { /* Motion 10 at San Diego: If a static const integral data member is initialized with an integral constant expression, the initializer may appear either in the declaration (within the class), or in the definition, but not both. If it appears in the class, the member is a member constant. The file-scope definition is always required. */ if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE) { cp_error ("in-class initialization of static data member of non-integral type `%T'", type); /* If we just return the declaration, crashes will sometimes occur. We therefore return void_type_node, as if this was a friend declaration, to cause callers to completely ignore this declaration. */ return 1; } else if (!CP_TYPE_CONST_P (type)) cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", decl); else if (pedantic && !INTEGRAL_TYPE_P (type)) cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type); return 0; } /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. (In one case we can return a ..._TYPE node instead. For invalid input we sometimes return 0.) DECLSPECS is a chain of tree_list nodes whose value fields are the storage classes and type specifiers. DECL_CONTEXT says which syntactic context this declaration is in: NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL. FUNCDEF for a function definition. Like NORMAL but a few different error messages in each case. Return value may be zero meaning this definition is too screwy to try to parse. MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to handle member functions (which have FIELD context). Return value may be zero meaning this definition is too screwy to try to parse. PARM for a parameter declaration (either within a function prototype or before a function body). Make a PARM_DECL, or return void_type_node. CATCHPARM for a parameter declaration before a catch clause. TYPENAME if for a typename (in a cast or sizeof). Don't make a DECL node; just return the ..._TYPE node. FIELD for a struct or union field; make a FIELD_DECL. BITFIELD for a field with specified width. INITIALIZED is 1 if the decl has an initializer. ATTRLIST is a TREE_LIST node with prefix attributes in TREE_VALUE and normal attributes in TREE_PURPOSE, or NULL_TREE. In the TYPENAME case, DECLARATOR is really an absolute declarator. It may also be so in the PARM case, for a prototype where the argument type is specified but not the name. This function is where the complicated C meanings of `static' and `extern' are interpreted. For C++, if there is any monkey business to do, the function which calls this one must do it, i.e., prepending instance variables, renaming overloaded function names, etc. Note that for this C++, it is an error to define a method within a class which does not belong to that class. Except in the case where SCOPE_REFs are implicitly known (such as methods within a class being redundantly qualified), declarations which involve SCOPE_REFs are returned as SCOPE_REFs (class_name::decl_name). The caller must also deal with this. If a constructor or destructor is seen, and the context is FIELD, then the type gains the attribute TREE_HAS_x. If such a declaration is erroneous, NULL_TREE is returned. QUALS is used only for FUNCDEF and MEMFUNCDEF cases. For a member function, these are the qualifiers to give to the `this' pointer. May return void_type_node if the declarator turned out to be a friend. See grokfield for details. */ enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; tree grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) tree declspecs; tree declarator; enum decl_context decl_context; int initialized; tree attrlist; { RID_BIT_TYPE specbits; int nclasses = 0; tree spec; tree type = NULL_TREE; int longlong = 0; int constp; int restrictp; int volatilep; int type_quals; int virtualp, explicitp, friendp, inlinep, staticp; int explicit_int = 0; int explicit_char = 0; int defaulted_int = 0; int opaque_typedef = 0; tree typedef_decl = NULL_TREE; char *name; tree typedef_type = NULL_TREE; int funcdef_flag = 0; enum tree_code innermost_code = ERROR_MARK; int bitfield = 0; #if 0 /* See the code below that used this. */ tree decl_machine_attr = NULL_TREE; #endif /* Set this to error_mark_node for FIELD_DECLs we could not handle properly. All FIELD_DECLs we build here have `init' put into their DECL_INITIAL. */ tree init = NULL_TREE; /* Keep track of what sort of function is being processed so that we can warn about default return values, or explicit return values which do not match prescribed defaults. */ enum return_types return_type = return_normal; tree dname = NULL_TREE; tree ctype = current_class_type; tree ctor_return_type = NULL_TREE; enum overload_flags flags = NO_SPECIAL; tree quals = NULL_TREE; tree raises = NULL_TREE; int template_count = 0; tree in_namespace = NULL_TREE; tree inner_attrs; int ignore_attrs; RIDBIT_RESET_ALL (specbits); if (decl_context == FUNCDEF) funcdef_flag = 1, decl_context = NORMAL; else if (decl_context == MEMFUNCDEF) funcdef_flag = -1, decl_context = FIELD; else if (decl_context == BITFIELD) bitfield = 1, decl_context = FIELD; /* Look inside a declarator for the name being declared and get it as a string, for an error message. */ { tree *next = &declarator; register tree decl; name = NULL; while (next && *next) { decl = *next; switch (TREE_CODE (decl)) { case TREE_LIST: /* For attributes. */ next = &TREE_VALUE (decl); break; case COND_EXPR: ctype = NULL_TREE; next = &TREE_OPERAND (decl, 0); break; case BIT_NOT_EXPR: /* For C++ destructors! */ { tree name = TREE_OPERAND (decl, 0); tree rename = NULL_TREE; my_friendly_assert (flags == NO_SPECIAL, 152); flags = DTOR_FLAG; return_type = return_dtor; if (TREE_CODE (name) == TYPE_DECL) TREE_OPERAND (decl, 0) = name = constructor_name (name); my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 153); if (ctype == NULL_TREE) { if (current_class_type == NULL_TREE) { error ("destructors must be member functions"); flags = NO_SPECIAL; } else { tree t = constructor_name (current_class_name); if (t != name) rename = t; } } else { tree t = constructor_name (ctype); if (t != name) rename = t; } if (rename) { cp_error ("destructor `%T' must match class name `%T'", name, rename); TREE_OPERAND (decl, 0) = rename; } next = &name; } break; case ADDR_EXPR: /* C++ reference declaration */ /* Fall through. */ case ARRAY_REF: case INDIRECT_REF: ctype = NULL_TREE; innermost_code = TREE_CODE (decl); next = &TREE_OPERAND (decl, 0); break; case CALL_EXPR: if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) { /* This is actually a variable declaration using constructor syntax. We need to call start_decl and cp_finish_decl so we can get the variable initialized... */ tree attributes, prefix_attributes; *next = TREE_OPERAND (decl, 0); init = TREE_OPERAND (decl, 1); if (attrlist) { attributes = TREE_PURPOSE (attrlist); prefix_attributes = TREE_VALUE (attrlist); } else { attributes = NULL_TREE; prefix_attributes = NULL_TREE; } decl = start_decl (declarator, declspecs, 1, attributes, prefix_attributes); if (decl) { /* Look for __unused__ attribute */ if (TREE_USED (TREE_TYPE (decl))) TREE_USED (decl) = 1; finish_decl (decl, init, NULL_TREE); } else cp_error ("invalid declarator"); return 0; } innermost_code = TREE_CODE (decl); if (decl_context == FIELD && ctype == NULL_TREE) ctype = current_class_type; if (ctype && TREE_OPERAND (decl, 0) && (TREE_CODE (TREE_OPERAND (decl, 0)) == TYPE_DECL && ((DECL_NAME (TREE_OPERAND (decl, 0)) == constructor_name_full (ctype)) || (DECL_NAME (TREE_OPERAND (decl, 0)) == constructor_name (ctype))))) TREE_OPERAND (decl, 0) = constructor_name (ctype); next = &TREE_OPERAND (decl, 0); decl = *next; if (ctype != NULL_TREE && decl != NULL_TREE && flags != DTOR_FLAG && decl == constructor_name (ctype)) { return_type = return_ctor; ctor_return_type = ctype; } ctype = NULL_TREE; break; case TEMPLATE_ID_EXPR: { tree fns = TREE_OPERAND (decl, 0); if (TREE_CODE (fns) == LOOKUP_EXPR) fns = TREE_OPERAND (fns, 0); dname = fns; if (TREE_CODE (dname) == COMPONENT_REF) dname = TREE_OPERAND (dname, 1); if (TREE_CODE (dname) != IDENTIFIER_NODE) { my_friendly_assert (is_overloaded_fn (dname), 19990331); dname = DECL_NAME (get_first_fn (dname)); } } /* Fall through. */ case IDENTIFIER_NODE: if (TREE_CODE (decl) == IDENTIFIER_NODE) dname = decl; next = 0; if (is_rid (dname)) { cp_error ("declarator-id missing; using reserved word `%D'", dname); name = IDENTIFIER_POINTER (dname); } if (! IDENTIFIER_OPNAME_P (dname) /* GNU/Linux headers use '__op'. Arrgh. */ || (IDENTIFIER_TYPENAME_P (dname) && ! TREE_TYPE (dname))) name = IDENTIFIER_POINTER (dname); else { if (IDENTIFIER_TYPENAME_P (dname)) { my_friendly_assert (flags == NO_SPECIAL, 154); flags = TYPENAME_FLAG; ctor_return_type = TREE_TYPE (dname); return_type = return_conversion; } name = operator_name_string (dname); } break; /* C++ extension */ case SCOPE_REF: { /* Perform error checking, and decide on a ctype. */ tree cname = TREE_OPERAND (decl, 0); if (cname == NULL_TREE) ctype = NULL_TREE; else if (TREE_CODE (cname) == NAMESPACE_DECL) { ctype = NULL_TREE; in_namespace = TREE_OPERAND (decl, 0); TREE_OPERAND (decl, 0) = NULL_TREE; } else if (! is_aggr_type (cname, 1)) TREE_OPERAND (decl, 0) = NULL_TREE; /* Must test TREE_OPERAND (decl, 1), in case user gives us `typedef (class::memfunc)(int); memfunc *memfuncptr;' */ else if (TREE_OPERAND (decl, 1) && TREE_CODE (TREE_OPERAND (decl, 1)) == INDIRECT_REF) ctype = cname; else if (TREE_CODE (cname) == TEMPLATE_TYPE_PARM || TREE_CODE (cname) == TEMPLATE_TEMPLATE_PARM) { cp_error ("`%T::%D' is not a valid declarator", cname, TREE_OPERAND (decl, 1)); cp_error (" perhaps you want `typename %T::%D' to make it a type", cname, TREE_OPERAND (decl, 1)); return void_type_node; } else if (ctype == NULL_TREE) ctype = cname; else if (TREE_COMPLEXITY (decl) == current_class_depth) TREE_OPERAND (decl, 0) = ctype; else { if (! UNIQUELY_DERIVED_FROM_P (cname, ctype)) { cp_error ("type `%T' is not derived from type `%T'", cname, ctype); TREE_OPERAND (decl, 0) = NULL_TREE; } else ctype = cname; } if (ctype && TREE_CODE (TREE_OPERAND (decl, 1)) == TYPE_DECL && ((DECL_NAME (TREE_OPERAND (decl, 1)) == constructor_name_full (ctype)) || (DECL_NAME (TREE_OPERAND (decl, 1)) == constructor_name (ctype)))) TREE_OPERAND (decl, 1) = constructor_name (ctype); next = &TREE_OPERAND (decl, 1); decl = *next; if (ctype) { if (TREE_CODE (decl) == IDENTIFIER_NODE && constructor_name (ctype) == decl) { return_type = return_ctor; ctor_return_type = ctype; } else if (TREE_CODE (decl) == BIT_NOT_EXPR && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE && (constructor_name (ctype) == TREE_OPERAND (decl, 0) || constructor_name_full (ctype) == TREE_OPERAND (decl, 0))) { return_type = return_dtor; ctor_return_type = ctype; flags = DTOR_FLAG; TREE_OPERAND (decl, 0) = constructor_name (ctype); next = &TREE_OPERAND (decl, 0); } } } break; case ERROR_MARK: next = 0; break; case TYPE_DECL: /* Parse error puts this typespec where a declarator should go. */ cp_error ("`%T' specified as declarator-id", DECL_NAME (decl)); if (TREE_TYPE (decl) == current_class_type) cp_error (" perhaps you want `%T' for a constructor", current_class_name); dname = DECL_NAME (decl); name = IDENTIFIER_POINTER (dname); /* Avoid giving two errors for this. */ IDENTIFIER_CLASS_VALUE (dname) = NULL_TREE; declspecs = temp_tree_cons (NULL_TREE, integer_type_node, declspecs); *next = dname; next = 0; break; default: cp_compiler_error ("`%D' as declarator", decl); return 0; /* We used to do a 155 abort here. */ } } if (name == NULL) name = "type name"; } /* A function definition's declarator must have the form of a function declarator. */ if (funcdef_flag && innermost_code != CALL_EXPR) return 0; if (((dname && IDENTIFIER_OPNAME_P (dname)) || flags == TYPENAME_FLAG) && innermost_code != CALL_EXPR && ! (ctype && declspecs == NULL_TREE)) { cp_error ("declaration of `%D' as non-function", dname); return void_type_node; } /* Anything declared one level down from the top level must be one of the parameters of a function (because the body is at least two levels down). */ /* This heuristic cannot be applied to C++ nodes! Fixed, however, by not allowing C++ class definitions to specify their parameters with xdecls (must be spec.d in the parmlist). Since we now wait to push a class scope until we are sure that we are in a legitimate method context, we must set oldcname explicitly (since current_class_name is not yet alive). We also want to avoid calling this a PARM if it is in a namespace. */ if (decl_context == NORMAL && ! namespace_bindings_p () && ! pseudo_global_level_p ()) { struct binding_level *b = current_binding_level; current_binding_level = b->level_chain; if (current_binding_level != 0 && toplevel_bindings_p ()) decl_context = PARM; current_binding_level = b; } /* Look through the decl specs and record which ones appear. Some typespecs are defined as built-in typenames. Others, the ones that are modifiers of other types, are represented by bits in SPECBITS: set the bits for the modifiers that appear. Storage class keywords are also in SPECBITS. If there is a typedef name or a type, store the type in TYPE. This includes builtin typedefs such as `int'. Set EXPLICIT_INT if the type is `int' or `char' and did not come from a user typedef. Set LONGLONG if `long' is mentioned twice. For C++, constructors and destructors have their own fast treatment. */ for (spec = declspecs; spec; spec = TREE_CHAIN (spec)) { register int i; register tree id; /* Certain parse errors slip through. For example, `int class;' is not caught by the parser. Try weakly to recover here. */ if (TREE_CODE (spec) != TREE_LIST) return 0; id = TREE_VALUE (spec); if (TREE_CODE (id) == IDENTIFIER_NODE) { if (id == ridpointers[(int) RID_INT] || id == ridpointers[(int) RID_CHAR] || id == ridpointers[(int) RID_BOOL] || id == ridpointers[(int) RID_WCHAR]) { if (type) { if (id == ridpointers[(int) RID_BOOL]) error ("`bool' is now a keyword"); else cp_error ("extraneous `%T' ignored", id); } else { if (id == ridpointers[(int) RID_INT]) explicit_int = 1; else if (id == ridpointers[(int) RID_CHAR]) explicit_char = 1; type = TREE_TYPE (IDENTIFIER_GLOBAL_VALUE (id)); } goto found; } /* C++ aggregate types. */ if (IDENTIFIER_HAS_TYPE_VALUE (id)) { if (type) cp_error ("multiple declarations `%T' and `%T'", type, id); else type = IDENTIFIER_TYPE_VALUE (id); goto found; } for (i = (int) RID_FIRST_MODIFIER; i <= (int) RID_LAST_MODIFIER; i++) { if (ridpointers[i] == id) { if (i == (int) RID_LONG && RIDBIT_SETP (i, specbits)) { if (pedantic && ! in_system_header && warn_long_long) pedwarn ("ANSI C++ does not support `long long'"); if (longlong) error ("`long long long' is too long for GCC"); else longlong = 1; } else if (RIDBIT_SETP (i, specbits)) pedwarn ("duplicate `%s'", IDENTIFIER_POINTER (id)); RIDBIT_SET (i, specbits); goto found; } } } /* C++ aggregate types. */ else if (TREE_CODE (id) == TYPE_DECL || TREE_CODE (id) == TEMPLATE_DECL) { if (type) cp_error ("multiple declarations `%T' and `%T'", type, TREE_TYPE (id)); else { type = TREE_TYPE (id); TREE_VALUE (spec) = type; } goto found; } if (type) error ("two or more data types in declaration of `%s'", name); else if (TREE_CODE (id) == IDENTIFIER_NODE) { register tree t = lookup_name (id, 1); if (!t || TREE_CODE (t) != TYPE_DECL) error ("`%s' fails to be a typedef or built in type", IDENTIFIER_POINTER (id)); else { type = TREE_TYPE (t); #if 0 /* See the code below that used this. */ decl_machine_attr = DECL_MACHINE_ATTRIBUTES (id); #endif typedef_decl = t; } } else if (id != error_mark_node) /* Can't change CLASS nodes into RECORD nodes here! */ type = id; found: ; } typedef_type = type; /* No type at all: default to `int', and set DEFAULTED_INT because it was not a user-defined typedef. Except when we have a `typedef' inside a signature, in which case the type defaults to `unknown type' and is instantiated when assigning to a signature pointer or ref. */ if (type == NULL_TREE && (RIDBIT_SETP (RID_SIGNED, specbits) || RIDBIT_SETP (RID_UNSIGNED, specbits) || RIDBIT_SETP (RID_LONG, specbits) || RIDBIT_SETP (RID_SHORT, specbits))) { /* These imply 'int'. */ type = integer_type_node; defaulted_int = 1; } if (type == NULL_TREE) { explicit_int = -1; if (return_type == return_dtor) type = void_type_node; else if (return_type == return_ctor) type = build_pointer_type (ctor_return_type); else if (return_type == return_conversion) type = ctor_return_type; else if (current_class_type && IS_SIGNATURE (current_class_type) && RIDBIT_SETP (RID_TYPEDEF, specbits) && (decl_context == FIELD || decl_context == NORMAL)) { explicit_int = 0; opaque_typedef = 1; type = copy_node (opaque_type_node); } else { /* We handle `main' specially here, because 'main () { }' is so common. With no options, it is allowed. With -Wreturn-type, it is a warning. It is only an error with -pedantic-errors. */ int is_main = (funcdef_flag && MAIN_NAME_P (dname) && ctype == NULL_TREE && in_namespace == NULL_TREE && current_namespace == global_namespace); if (in_system_header) /* Allow it, sigh. */; else if (pedantic || ! is_main) cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type", dname); else if (warn_return_type) cp_warning ("ANSI C++ forbids declaration `%D' with no type", dname); type = integer_type_node; } } else if (return_type == return_dtor) { error ("return type specification for destructor invalid"); type = void_type_node; } else if (return_type == return_ctor) { error ("return type specification for constructor invalid"); type = build_pointer_type (ctor_return_type); } else if (return_type == return_conversion) { if (!same_type_p (type, ctor_return_type)) cp_error ("operator `%T' declared to return `%T'", ctor_return_type, type); else cp_pedwarn ("return type specified for `operator %T'", ctor_return_type); type = ctor_return_type; } ctype = NULL_TREE; /* Now process the modifiers that were specified and check for invalid combinations. */ /* Long double is a special combination. */ if (RIDBIT_SETP (RID_LONG, specbits) && TYPE_MAIN_VARIANT (type) == double_type_node) { RIDBIT_RESET (RID_LONG, specbits); type = build_qualified_type (long_double_type_node, CP_TYPE_QUALS (type)); } /* Check all other uses of type modifiers. */ if (RIDBIT_SETP (RID_UNSIGNED, specbits) || RIDBIT_SETP (RID_SIGNED, specbits) || RIDBIT_SETP (RID_LONG, specbits) || RIDBIT_SETP (RID_SHORT, specbits)) { int ok = 0; if (TREE_CODE (type) == REAL_TYPE) error ("short, signed or unsigned invalid for `%s'", name); else if (TREE_CODE (type) != INTEGER_TYPE) error ("long, short, signed or unsigned invalid for `%s'", name); else if (RIDBIT_SETP (RID_LONG, specbits) && RIDBIT_SETP (RID_SHORT, specbits)) error ("long and short specified together for `%s'", name); else if ((RIDBIT_SETP (RID_LONG, specbits) || RIDBIT_SETP (RID_SHORT, specbits)) && explicit_char) error ("long or short specified with char for `%s'", name); else if ((RIDBIT_SETP (RID_LONG, specbits) || RIDBIT_SETP (RID_SHORT, specbits)) && TREE_CODE (type) == REAL_TYPE) error ("long or short specified with floating type for `%s'", name); else if (RIDBIT_SETP (RID_SIGNED, specbits) && RIDBIT_SETP (RID_UNSIGNED, specbits)) error ("signed and unsigned given together for `%s'", name); else { ok = 1; if (!explicit_int && !defaulted_int && !explicit_char && pedantic) { pedwarn ("long, short, signed or unsigned used invalidly for `%s'", name); if (flag_pedantic_errors) ok = 0; } } /* Discard the type modifiers if they are invalid. */ if (! ok) { RIDBIT_RESET (RID_UNSIGNED, specbits); RIDBIT_RESET (RID_SIGNED, specbits); RIDBIT_RESET (RID_LONG, specbits); RIDBIT_RESET (RID_SHORT, specbits); longlong = 0; } } if (RIDBIT_SETP (RID_COMPLEX, specbits) && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) { error ("complex invalid for `%s'", name); RIDBIT_RESET (RID_COMPLEX, specbits); } /* Decide whether an integer type is signed or not. Optionally treat bitfields as signed by default. */ if (RIDBIT_SETP (RID_UNSIGNED, specbits) || (bitfield && ! flag_signed_bitfields && (explicit_int || defaulted_int || explicit_char /* A typedef for plain `int' without `signed' can be controlled just like plain `int'. */ || ! (typedef_decl != NULL_TREE && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) && TREE_CODE (type) != ENUMERAL_TYPE && RIDBIT_NOTSETP (RID_SIGNED, specbits))) { if (longlong) type = long_long_unsigned_type_node; else if (RIDBIT_SETP (RID_LONG, specbits)) type = long_unsigned_type_node; else if (RIDBIT_SETP (RID_SHORT, specbits)) type = short_unsigned_type_node; else if (type == char_type_node) type = unsigned_char_type_node; else if (typedef_decl) type = unsigned_type (type); else type = unsigned_type_node; } else if (RIDBIT_SETP (RID_SIGNED, specbits) && type == char_type_node) type = signed_char_type_node; else if (longlong) type = long_long_integer_type_node; else if (RIDBIT_SETP (RID_LONG, specbits)) type = long_integer_type_node; else if (RIDBIT_SETP (RID_SHORT, specbits)) type = short_integer_type_node; if (RIDBIT_SETP (RID_COMPLEX, specbits)) { /* If we just have "complex", it is equivalent to "complex double", but if any modifiers at all are specified it is the complex form of TYPE. E.g, "complex short" is "complex short int". */ if (defaulted_int && ! longlong && ! (RIDBIT_SETP (RID_LONG, specbits) || RIDBIT_SETP (RID_SHORT, specbits) || RIDBIT_SETP (RID_SIGNED, specbits) || RIDBIT_SETP (RID_UNSIGNED, specbits))) type = complex_double_type_node; else if (type == integer_type_node) type = complex_integer_type_node; else if (type == float_type_node) type = complex_float_type_node; else if (type == double_type_node) type = complex_double_type_node; else if (type == long_double_type_node) type = complex_long_double_type_node; else type = build_complex_type (type); } if (return_type == return_conversion && (RIDBIT_SETP (RID_CONST, specbits) || RIDBIT_SETP (RID_VOLATILE, specbits) || RIDBIT_SETP (RID_RESTRICT, specbits))) cp_error ("qualifiers are not allowed on declaration of `operator %T'", ctor_return_type); /* Set CONSTP if this declaration is `const', whether by explicit specification or via a typedef. Likewise for VOLATILEP. */ constp = !! RIDBIT_SETP (RID_CONST, specbits) + CP_TYPE_CONST_P (type); restrictp = !! RIDBIT_SETP (RID_RESTRICT, specbits) + CP_TYPE_RESTRICT_P (type); volatilep = !! RIDBIT_SETP (RID_VOLATILE, specbits) + CP_TYPE_VOLATILE_P (type); type_quals = ((constp ? TYPE_QUAL_CONST : 0) | (restrictp ? TYPE_QUAL_RESTRICT : 0) | (volatilep ? TYPE_QUAL_VOLATILE : 0)); type = cp_build_qualified_type (type, type_quals); staticp = 0; inlinep = !! RIDBIT_SETP (RID_INLINE, specbits); virtualp = RIDBIT_SETP (RID_VIRTUAL, specbits); RIDBIT_RESET (RID_VIRTUAL, specbits); explicitp = RIDBIT_SETP (RID_EXPLICIT, specbits) != 0; RIDBIT_RESET (RID_EXPLICIT, specbits); if (RIDBIT_SETP (RID_STATIC, specbits)) staticp = 1 + (decl_context == FIELD); if (virtualp && staticp == 2) { cp_error ("member `%D' cannot be declared both virtual and static", dname); staticp = 0; } friendp = RIDBIT_SETP (RID_FRIEND, specbits); RIDBIT_RESET (RID_FRIEND, specbits); /* $7.1.2, Function specifiers */ if (friendp && explicitp) error ("only declarations of constructors can be `explicit'"); if (RIDBIT_SETP (RID_MUTABLE, specbits)) { if (decl_context == PARM) { error ("non-member `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } else if (friendp || decl_context == TYPENAME) { error ("non-object member `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } } /* Warn if two storage classes are given. Default to `auto'. */ if (RIDBIT_ANY_SET (specbits)) { if (RIDBIT_SETP (RID_STATIC, specbits)) nclasses++; if (RIDBIT_SETP (RID_EXTERN, specbits)) nclasses++; if (decl_context == PARM && nclasses > 0) error ("storage class specifiers invalid in parameter declarations"); if (RIDBIT_SETP (RID_TYPEDEF, specbits)) { if (decl_context == PARM) error ("typedef declaration invalid in parameter declaration"); nclasses++; } if (RIDBIT_SETP (RID_AUTO, specbits)) nclasses++; if (RIDBIT_SETP (RID_REGISTER, specbits)) nclasses++; } /* Give error if `virtual' is used outside of class declaration. */ if (virtualp && (current_class_name == NULL_TREE || decl_context != FIELD)) { error ("virtual outside class declaration"); virtualp = 0; } if (current_class_name == NULL_TREE && RIDBIT_SETP (RID_MUTABLE, specbits)) { error ("only members can be declared mutable"); RIDBIT_RESET (RID_MUTABLE, specbits); } /* Static anonymous unions are dealt with here. */ if (staticp && decl_context == TYPENAME && TREE_CODE (declspecs) == TREE_LIST && ANON_UNION_TYPE_P (TREE_VALUE (declspecs))) decl_context = FIELD; /* Give error if `const,' `volatile,' `inline,' `friend,' or `virtual' is used in a signature member function declaration. */ if (decl_context == FIELD && IS_SIGNATURE (current_class_type) && RIDBIT_NOTSETP (RID_TYPEDEF, specbits)) { if (type_quals != TYPE_UNQUALIFIED) { error ("type qualifiers specified for signature member function `%s'", name); type_quals = TYPE_UNQUALIFIED; } if (inlinep) { error ("`inline' specified for signature member function `%s'", name); /* Later, we'll make signature member functions inline. */ inlinep = 0; } if (friendp) { error ("`friend' declaration in signature definition"); friendp = 0; } if (virtualp) { error ("`virtual' specified for signature member function `%s'", name); /* Later, we'll make signature member functions virtual. */ virtualp = 0; } } /* Warn about storage classes that are invalid for certain kinds of declarations (parameters, typenames, etc.). */ if (nclasses > 1) error ("multiple storage classes in declaration of `%s'", name); else if (decl_context != NORMAL && nclasses > 0) { if ((decl_context == PARM || decl_context == CATCHPARM) && (RIDBIT_SETP (RID_REGISTER, specbits) || RIDBIT_SETP (RID_AUTO, specbits))) ; else if (RIDBIT_SETP (RID_TYPEDEF, specbits)) ; else if (decl_context == FIELD && ! IS_SIGNATURE (current_class_type) /* C++ allows static class elements */ && RIDBIT_SETP (RID_STATIC, specbits)) /* C++ also allows inlines and signed and unsigned elements, but in those cases we don't come in here. */ ; else { if (decl_context == FIELD) { tree tmp = NULL_TREE; register int op = 0; if (declarator) { /* Avoid trying to get an operand off an identifier node. */ if (TREE_CODE (declarator) == IDENTIFIER_NODE) tmp = declarator; else tmp = TREE_OPERAND (declarator, 0); op = IDENTIFIER_OPNAME_P (tmp); } error ("storage class specified for %s `%s'", IS_SIGNATURE (current_class_type) ? (op ? "signature member operator" : "signature member function") : (op ? "member operator" : "field"), op ? operator_name_string (tmp) : name); } else error (((decl_context == PARM || decl_context == CATCHPARM) ? "storage class specified for parameter `%s'" : "storage class specified for typename"), name); RIDBIT_RESET (RID_REGISTER, specbits); RIDBIT_RESET (RID_AUTO, specbits); RIDBIT_RESET (RID_EXTERN, specbits); if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) { RIDBIT_RESET (RID_STATIC, specbits); staticp = 0; } } } else if (RIDBIT_SETP (RID_EXTERN, specbits) && initialized && !funcdef_flag) { if (toplevel_bindings_p ()) { /* It's common practice (and completely valid) to have a const be initialized and declared extern. */ if (!(type_quals & TYPE_QUAL_CONST)) warning ("`%s' initialized and declared `extern'", name); } else error ("`%s' has both `extern' and initializer", name); } else if (RIDBIT_SETP (RID_EXTERN, specbits) && funcdef_flag && ! toplevel_bindings_p ()) error ("nested function `%s' declared `extern'", name); else if (toplevel_bindings_p ()) { if (RIDBIT_SETP (RID_AUTO, specbits)) error ("top-level declaration of `%s' specifies `auto'", name); } if (nclasses > 0 && friendp) error ("storage class specifiers invalid in friend function declarations"); /* Now figure out the structure of the declarator proper. Descend through it, creating more complex types, until we reach the declared identifier (or NULL_TREE, in an absolute declarator). */ inner_attrs = NULL_TREE; ignore_attrs = 0; while (declarator && TREE_CODE (declarator) != IDENTIFIER_NODE && TREE_CODE (declarator) != TEMPLATE_ID_EXPR) { /* Each level of DECLARATOR is either an ARRAY_REF (for ...[..]), an INDIRECT_REF (for *...), a CALL_EXPR (for ...(...)), an identifier (for the name being declared) or a null pointer (for the place in an absolute declarator where the name was omitted). For the last two cases, we have just exited the loop. For C++ it could also be a SCOPE_REF (for class :: ...). In this case, we have converted sensible names to types, and those are the values we use to qualify the member name. an ADDR_EXPR (for &...), a BIT_NOT_EXPR (for destructors) At this point, TYPE is the type of elements of an array, or for a function to return, or for a pointer to point to. After this sequence of ifs, TYPE is the type of the array or function or pointer, and DECLARATOR has had its outermost layer removed. */ if (type == error_mark_node) { if (TREE_CODE (declarator) == SCOPE_REF) declarator = TREE_OPERAND (declarator, 1); else declarator = TREE_OPERAND (declarator, 0); continue; } if (quals != NULL_TREE && (declarator == NULL_TREE || TREE_CODE (declarator) != SCOPE_REF)) { if (ctype == NULL_TREE && TREE_CODE (type) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (type); if (ctype != NULL_TREE) { tree dummy = build_decl (TYPE_DECL, NULL_TREE, type); ctype = grok_method_quals (ctype, dummy, quals); type = TREE_TYPE (dummy); quals = NULL_TREE; } } /* See the comment for the TREE_LIST case, below. */ if (ignore_attrs) ignore_attrs = 0; else if (inner_attrs) { decl_attributes (type, inner_attrs, NULL_TREE); inner_attrs = NULL_TREE; } switch (TREE_CODE (declarator)) { case TREE_LIST: { /* We encode a declarator with embedded attributes using a TREE_LIST. The attributes apply to the declarator directly inside them, so we have to skip an iteration before applying them to the type. If the declarator just inside is the declarator-id, we apply the attrs to the decl itself. */ inner_attrs = TREE_PURPOSE (declarator); ignore_attrs = 1; declarator = TREE_VALUE (declarator); } break; case ARRAY_REF: { register tree itype = NULL_TREE; register tree size = TREE_OPERAND (declarator, 1); /* The index is a signed object `sizetype' bits wide. */ tree index_type = signed_type (sizetype); declarator = TREE_OPERAND (declarator, 0); /* Check for some types that there cannot be arrays of. */ if (TREE_CODE (type) == VOID_TYPE) { cp_error ("declaration of `%D' as array of voids", dname); type = error_mark_node; } if (TREE_CODE (type) == FUNCTION_TYPE) { cp_error ("declaration of `%D' as array of functions", dname); type = error_mark_node; } /* ARM $8.4.3: Since you can't have a pointer to a reference, you can't have arrays of references. If we allowed them, then we'd be saying x[i] is valid for an array x, but then you'd have to ask: what does `*(x + i)' mean? */ if (TREE_CODE (type) == REFERENCE_TYPE) { if (decl_context == TYPENAME) cp_error ("cannot make arrays of references"); else cp_error ("declaration of `%D' as array of references", dname); type = error_mark_node; } if (TREE_CODE (type) == OFFSET_TYPE) { cp_error ("declaration of `%D' as array of data members", dname); type = error_mark_node; } if (TREE_CODE (type) == METHOD_TYPE) { cp_error ("declaration of `%D' as array of function members", dname); type = error_mark_node; } if (size == error_mark_node) type = error_mark_node; else if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) { /* [dcl.array] the constant expressions that specify the bounds of the arrays can be omitted only for the first member of the sequence. */ cp_error ("declaration of `%D' as multidimensional array", dname); cp_error ("must have bounds for all dimensions except the first"); type = error_mark_node; } if (type == error_mark_node) continue; /* VC++ spells a zero-sized array with []. */ if (size == NULL_TREE && decl_context == FIELD && ! staticp && ! RIDBIT_SETP (RID_TYPEDEF, specbits)) size = integer_zero_node; if (size) { /* Must suspend_momentary here because the index type may need to live until the end of the function. For example, it is used in the declaration of a variable which requires destructing at the end of the function; then build_vec_delete will need this value. */ int yes = suspend_momentary (); /* Might be a cast. */ if (TREE_CODE (size) == NOP_EXPR && TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0))) size = TREE_OPERAND (size, 0); /* If this involves a template parameter, it will be a constant at instantiation time, but we don't know what the value is yet. Even if no template parameters are involved, we may an expression that is not a constant; we don't even simplify `1 + 2' when processing a template. */ if (processing_template_decl) { /* Resolve a qualified reference to an enumerator or static const data member of ours. */ if (TREE_CODE (size) == SCOPE_REF && TREE_OPERAND (size, 0) == current_class_type) { tree t = lookup_field (current_class_type, TREE_OPERAND (size, 1), 0, 0); if (t) size = t; } itype = build_index_type (build_min (MINUS_EXPR, sizetype, size, integer_one_node)); goto dont_grok_size; } if (TREE_CODE (TREE_TYPE (size)) != INTEGER_TYPE && TREE_CODE (TREE_TYPE (size)) != ENUMERAL_TYPE && TREE_CODE (TREE_TYPE (size)) != BOOLEAN_TYPE) { cp_error ("size of array `%D' has non-integer type", dname); size = integer_one_node; } if (TREE_READONLY_DECL_P (size)) size = decl_constant_value (size); if (pedantic && integer_zerop (size)) cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname); if (TREE_CONSTANT (size)) { int old_flag_pedantic_errors = flag_pedantic_errors; int old_pedantic = pedantic; pedantic = flag_pedantic_errors = 1; /* Always give overflow errors on array subscripts. */ constant_expression_warning (size); pedantic = old_pedantic; flag_pedantic_errors = old_flag_pedantic_errors; if (INT_CST_LT (size, integer_zero_node)) { cp_error ("size of array `%D' is negative", dname); size = integer_one_node; } } else { if (pedantic) { if (dname) cp_pedwarn ("ANSI C++ forbids variable-size array `%D'", dname); else cp_pedwarn ("ANSI C++ forbids variable-size array"); } } itype = fold (build_binary_op (MINUS_EXPR, cp_convert (index_type, size), cp_convert (index_type, integer_one_node))); if (! TREE_CONSTANT (itype)) itype = variable_size (itype); else if (TREE_OVERFLOW (itype)) { error ("overflow in array dimension"); TREE_OVERFLOW (itype) = 0; } /* If we're a parm, we need to have a permanent type so mangling checks for re-use will work right. If both the element and index types are permanent, the array type will be, too. */ if (decl_context == PARM && allocation_temporary_p () && TREE_PERMANENT (type)) { push_obstacks (&permanent_obstack, &permanent_obstack); itype = build_index_type (itype); pop_obstacks (); } else itype = build_index_type (itype); dont_grok_size: resume_momentary (yes); } type = build_cplus_array_type (type, itype); ctype = NULL_TREE; } break; case CALL_EXPR: { tree arg_types; int funcdecl_p; tree inner_parms = TREE_OPERAND (declarator, 1); tree inner_decl = TREE_OPERAND (declarator, 0); /* Declaring a function type. Make sure we have a valid type for the function to return. */ /* We now know that the TYPE_QUALS don't apply to the decl, but to its return type. */ type_quals = TYPE_UNQUALIFIED; /* Warn about some types functions can't return. */ if (TREE_CODE (type) == FUNCTION_TYPE) { error ("`%s' declared as function returning a function", name); type = integer_type_node; } if (TREE_CODE (type) == ARRAY_TYPE) { error ("`%s' declared as function returning an array", name); type = integer_type_node; } if (inner_decl && TREE_CODE (inner_decl) == SCOPE_REF) inner_decl = TREE_OPERAND (inner_decl, 1); if (inner_decl && TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR) inner_decl = dname; /* Pick up type qualifiers which should be applied to `this'. */ quals = TREE_OPERAND (declarator, 2); /* Pick up the exception specifications. */ raises = TREE_TYPE (declarator); /* Say it's a definition only for the CALL_EXPR closest to the identifier. */ funcdecl_p = inner_decl && (TREE_CODE (inner_decl) == IDENTIFIER_NODE || TREE_CODE (inner_decl) == TEMPLATE_ID_EXPR || TREE_CODE (inner_decl) == BIT_NOT_EXPR); if (ctype == NULL_TREE && decl_context == FIELD && funcdecl_p && (friendp == 0 || dname == current_class_name)) ctype = current_class_type; if (ctype && return_type == return_conversion) TYPE_HAS_CONVERSION (ctype) = 1; if (ctype && constructor_name (ctype) == dname) { /* We are within a class's scope. If our declarator name is the same as the class name, and we are defining a function, then it is a constructor/destructor, and therefore returns a void type. */ if (flags == DTOR_FLAG) { /* ANSI C++ June 5 1992 WP 12.4.1. A destructor may not be declared const or volatile. A destructor may not be static. */ if (staticp == 2) error ("destructor cannot be static member function"); if (quals) { cp_error ("destructors may not be `%s'", IDENTIFIER_POINTER (TREE_VALUE (quals))); quals = NULL_TREE; } if (decl_context == FIELD) { if (! member_function_or_else (ctype, current_class_type, "destructor for alien class `%s' cannot be a member")) return void_type_node; } } else /* It's a constructor. */ { if (explicitp == 1) explicitp = 2; /* ANSI C++ June 5 1992 WP 12.1.2. A constructor may not be declared const or volatile. A constructor may not be virtual. A constructor may not be static. */ if (staticp == 2) error ("constructor cannot be static member function"); if (virtualp) { pedwarn ("constructors cannot be declared virtual"); virtualp = 0; } if (quals) { cp_error ("constructors may not be `%s'", IDENTIFIER_POINTER (TREE_VALUE (quals))); quals = NULL_TREE; } { RID_BIT_TYPE tmp_bits; bcopy ((void*)&specbits, (void*)&tmp_bits, sizeof (RID_BIT_TYPE)); RIDBIT_RESET (RID_INLINE, tmp_bits); RIDBIT_RESET (RID_STATIC, tmp_bits); if (RIDBIT_ANY_SET (tmp_bits)) error ("return value type specifier for constructor ignored"); } type = build_pointer_type (ctype); if (decl_context == FIELD && IS_SIGNATURE (current_class_type)) { error ("constructor not allowed in signature"); return void_type_node; } else if (decl_context == FIELD) { if (! member_function_or_else (ctype, current_class_type, "constructor for alien class `%s' cannot be member")) return void_type_node; TYPE_HAS_CONSTRUCTOR (ctype) = 1; if (return_type != return_ctor) return NULL_TREE; } } if (decl_context == FIELD) staticp = 0; } else if (friendp) { if (initialized) error ("can't initialize friend function `%s'", name); if (virtualp) { /* Cannot be both friend and virtual. */ error ("virtual functions cannot be friends"); RIDBIT_RESET (RID_FRIEND, specbits); friendp = 0; } if (decl_context == NORMAL) error ("friend declaration not in class definition"); if (current_function_decl && funcdef_flag) cp_error ("can't define friend function `%s' in a local class definition", name); } /* Construct the function type and go to the next inner layer of declarator. */ declarator = TREE_OPERAND (declarator, 0); /* FIXME: This is where default args should be fully processed. */ arg_types = grokparms (inner_parms, funcdecl_p ? funcdef_flag : 0); if (declarator && flags == DTOR_FLAG) { /* A destructor declared in the body of a class will be represented as a BIT_NOT_EXPR. But, we just want the underlying IDENTIFIER. */ if (TREE_CODE (declarator) == BIT_NOT_EXPR) declarator = TREE_OPERAND (declarator, 0); if (strict_prototype == 0 && arg_types == NULL_TREE) arg_types = void_list_node; else if (arg_types == NULL_TREE || arg_types != void_list_node) { cp_error ("destructors may not have parameters"); arg_types = void_list_node; last_function_parms = NULL_TREE; } } /* ANSI says that `const int foo ();' does not make the function foo const. */ type = build_function_type (type, arg_types); { tree t; for (t = arg_types; t; t = TREE_CHAIN (t)) if (TREE_PURPOSE (t) && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) { add_defarg_fn (type); break; } } } break; case ADDR_EXPR: case INDIRECT_REF: /* Filter out pointers-to-references and references-to-references. We can get these if a TYPE_DECL is used. */ if (TREE_CODE (type) == REFERENCE_TYPE) { error ("cannot declare %s to references", TREE_CODE (declarator) == ADDR_EXPR ? "references" : "pointers"); declarator = TREE_OPERAND (declarator, 0); continue; } if (TREE_CODE (type) == OFFSET_TYPE && (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE || TREE_CODE (TREE_TYPE (type)) == REFERENCE_TYPE)) { cp_error ("cannot declare pointer to `%#T' member", TREE_TYPE (type)); type = TREE_TYPE (type); } /* Merge any constancy or volatility into the target type for the pointer. */ /* We now know that the TYPE_QUALS don't apply to the decl, but to the target of the pointer. */ type_quals = TYPE_UNQUALIFIED; if (IS_SIGNATURE (type)) { if (TREE_CODE (declarator) == ADDR_EXPR) { if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE && TYPE_SIZE (type)) cp_warning ("empty signature `%T' used in signature reference declaration", type); #if 0 type = build_signature_reference_type (type); #else sorry ("signature reference"); return NULL_TREE; #endif } else { if (CLASSTYPE_METHOD_VEC (type) == NULL_TREE && TYPE_SIZE (type)) cp_warning ("empty signature `%T' used in signature pointer declaration", type); type = build_signature_pointer_type (type); } } else if (TREE_CODE (declarator) == ADDR_EXPR) { if (TREE_CODE (type) == VOID_TYPE) error ("invalid type: `void &'"); else type = build_reference_type (type); } else if (TREE_CODE (type) == METHOD_TYPE) type = build_ptrmemfunc_type (build_pointer_type (type)); else type = build_pointer_type (type); /* Process a list of type modifier keywords (such as const or volatile) that were given inside the `*' or `&'. */ if (TREE_TYPE (declarator)) { register tree typemodlist; int erred = 0; constp = 0; volatilep = 0; restrictp = 0; for (typemodlist = TREE_TYPE (declarator); typemodlist; typemodlist = TREE_CHAIN (typemodlist)) { tree qualifier = TREE_VALUE (typemodlist); if (qualifier == ridpointers[(int) RID_CONST]) constp++; else if (qualifier == ridpointers[(int) RID_VOLATILE]) volatilep++; else if (qualifier == ridpointers[(int) RID_RESTRICT]) restrictp++; else if (!erred) { erred = 1; error ("invalid type modifier within pointer declarator"); } } if (constp > 1) pedwarn ("duplicate `const'"); if (volatilep > 1) pedwarn ("duplicate `volatile'"); if (restrictp > 1) pedwarn ("duplicate `restrict'"); type_quals = ((constp ? TYPE_QUAL_CONST : 0) | (restrictp ? TYPE_QUAL_RESTRICT : 0) | (volatilep ? TYPE_QUAL_VOLATILE : 0)); if (TREE_CODE (declarator) == ADDR_EXPR && (constp || volatilep)) { if (constp) pedwarn ("discarding `const' applied to a reference"); if (volatilep) pedwarn ("discarding `volatile' applied to a reference"); type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); } type = cp_build_qualified_type (type, type_quals); } declarator = TREE_OPERAND (declarator, 0); ctype = NULL_TREE; break; case SCOPE_REF: { /* We have converted type names to NULL_TREE if the name was bogus, or to a _TYPE node, if not. The variable CTYPE holds the type we will ultimately resolve to. The code here just needs to build up appropriate member types. */ tree sname = TREE_OPERAND (declarator, 1); tree t; /* Destructors can have their visibilities changed as well. */ if (TREE_CODE (sname) == BIT_NOT_EXPR) sname = TREE_OPERAND (sname, 0); if (TREE_COMPLEXITY (declarator) == 0) /* This needs to be here, in case we are called multiple times. */ ; else if (TREE_COMPLEXITY (declarator) == -1) /* Namespace member. */ pop_decl_namespace (); else if (friendp && (TREE_COMPLEXITY (declarator) < 2)) /* Don't fall out into global scope. Hides real bug? --eichin */ ; else if (! IS_AGGR_TYPE_CODE (TREE_CODE (TREE_OPERAND (declarator, 0)))) ; else if (TREE_COMPLEXITY (declarator) == current_class_depth) { /* Resolve any TYPENAME_TYPEs from the decl-specifier-seq that refer to ctype. They couldn't be resolved earlier because we hadn't pushed into the class yet. Example: resolve 'B::type' in 'B::type> B::f () { }'. */ if (current_template_parms && uses_template_parms (type) && uses_template_parms (current_class_type)) { tree args = current_template_args (); type = tsubst (type, args, /*complain=*/1, NULL_TREE); } /* This pop_nested_class corresponds to the push_nested_class used to push into class scope for parsing the argument list of a function decl, in qualified_id. */ pop_nested_class (); TREE_COMPLEXITY (declarator) = current_class_depth; } else my_friendly_abort (16); if (TREE_OPERAND (declarator, 0) == NULL_TREE) { /* We had a reference to a global decl, or perhaps we were given a non-aggregate typedef, in which case we cleared this out, and should just keep going as though it wasn't there. */ declarator = sname; continue; } ctype = TREE_OPERAND (declarator, 0); t = ctype; while (t != NULL_TREE && CLASS_TYPE_P (t)) { if (CLASSTYPE_TEMPLATE_INFO (t) && !CLASSTYPE_TEMPLATE_SPECIALIZATION (t)) template_count += 1; t = TYPE_MAIN_DECL (t); if (DECL_LANG_SPECIFIC (t)) t = DECL_CLASS_CONTEXT (t); else t = NULL_TREE; } if (sname == NULL_TREE) goto done_scoping; if (TREE_CODE (sname) == IDENTIFIER_NODE) { /* This is the `standard' use of the scoping operator: basetype :: member . */ if (ctype == current_class_type) { /* class A { void A::f (); }; Is this ill-formed? */ if (pedantic) cp_pedwarn ("extra qualification `%T::' on member `%s' ignored", ctype, name); } else if (TREE_CODE (type) == FUNCTION_TYPE) { if (current_class_type == NULL_TREE || friendp) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); else { cp_error ("cannot declare member function `%T::%s' within `%T'", ctype, name, current_class_type); return void_type_node; } } else if (RIDBIT_SETP (RID_TYPEDEF, specbits) || TYPE_SIZE (complete_type (ctype)) != NULL_TREE) { /* Have to move this code elsewhere in this function. this code is used for i.e., typedef int A::M; M *pm; It is? How? jason 10/2/94 */ if (current_class_type) { cp_error ("cannot declare member `%T::%s' within `%T'", ctype, name, current_class_type); return void_type_node; } type = build_offset_type (ctype, type); } else if (uses_template_parms (ctype)) { if (TREE_CODE (type) == FUNCTION_TYPE) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); } else { cp_error ("structure `%T' not yet defined", ctype); return error_mark_node; } declarator = sname; } else if (TREE_CODE (sname) == SCOPE_REF) my_friendly_abort (17); else { done_scoping: declarator = TREE_OPERAND (declarator, 1); if (declarator && TREE_CODE (declarator) == CALL_EXPR) /* In this case, we will deal with it later. */ ; else { if (TREE_CODE (type) == FUNCTION_TYPE) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); else type = build_offset_type (ctype, type); } } } break; case BIT_NOT_EXPR: declarator = TREE_OPERAND (declarator, 0); break; case RECORD_TYPE: case UNION_TYPE: case ENUMERAL_TYPE: declarator = NULL_TREE; break; case ERROR_MARK: declarator = NULL_TREE; break; default: my_friendly_abort (158); } } /* See the comment for the TREE_LIST case, above. */ if (inner_attrs) { if (! ignore_attrs) decl_attributes (type, inner_attrs, NULL_TREE); else if (attrlist) TREE_VALUE (attrlist) = chainon (inner_attrs, TREE_VALUE (attrlist)); else attrlist = build_decl_list (NULL_TREE, inner_attrs); } /* Now TYPE has the actual type. */ if (explicitp == 1) { error ("only constructors can be declared `explicit'"); explicitp = 0; } if (RIDBIT_SETP (RID_MUTABLE, specbits)) { if (type_quals & TYPE_QUAL_CONST) { error ("const `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } else if (staticp) { error ("static `%s' cannot be declared `mutable'", name); RIDBIT_RESET (RID_MUTABLE, specbits); } } if (declarator == NULL_TREE || TREE_CODE (declarator) == IDENTIFIER_NODE || (TREE_CODE (declarator) == TEMPLATE_ID_EXPR && (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE))) /* OK */; else if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) { cp_error ("template-id `%D' used as a declarator", declarator); declarator = dname; } else /* Unexpected declarator format. */ my_friendly_abort (990210); /* If this is declaring a typedef name, return a TYPE_DECL. */ if (RIDBIT_SETP (RID_TYPEDEF, specbits) && decl_context != TYPENAME) { tree decl; /* Note that the grammar rejects storage classes in typenames, fields or parameters. */ if (current_lang_name == lang_name_java) TYPE_FOR_JAVA (type) = 1; if (decl_context == FIELD) { if (declarator == constructor_name (current_class_type)) cp_pedwarn ("ANSI C++ forbids nested type `%D' with same name as enclosing class", declarator); decl = build_lang_decl (TYPE_DECL, declarator, type); if (IS_SIGNATURE (current_class_type) && opaque_typedef) SIGNATURE_HAS_OPAQUE_TYPEDECLS (current_class_type) = 1; } else { /* Make sure this typedef lives as long as its type, since it might be used as a template parameter. */ if (type != error_mark_node) push_obstacks (TYPE_OBSTACK (type), TYPE_OBSTACK (type)); decl = build_decl (TYPE_DECL, declarator, type); if (type != error_mark_node) pop_obstacks (); } /* If the user declares "struct {...} foo" then `foo' will have an anonymous name. Fill that name in now. Nothing can refer to it, so nothing needs know about the name change. The TYPE_NAME field was filled in by build_struct_xref. */ if (type != error_mark_node && TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL && ANON_AGGRNAME_P (TYPE_IDENTIFIER (type))) { tree oldname = TYPE_NAME (type); tree t; /* FIXME: This is bogus; we should not be doing this for cv-qualified types. */ /* Replace the anonymous name with the real name everywhere. */ lookup_tag_reverse (type, declarator); for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) if (TYPE_NAME (t) == oldname) TYPE_NAME (t) = decl; if (TYPE_LANG_SPECIFIC (type)) TYPE_WAS_ANONYMOUS (type) = 1; /* If this is a typedef within a template class, the nested type is a (non-primary) template. The name for the template needs updating as well. */ if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type)) DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = TYPE_IDENTIFIER (type); /* XXX Temporarily set the scope. When returning, start_decl expects it as NULL_TREE, and will then then set it using pushdecl. */ my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 980404); if (current_class_type) DECL_CONTEXT (decl) = current_class_type; else DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl); DECL_ASSEMBLER_NAME (decl) = get_identifier (build_overload_name (type, 1, 1)); DECL_CONTEXT (decl) = NULL_TREE; /* FIXME remangle member functions; member functions of a type with external linkage have external linkage. */ } if (TREE_CODE (type) == OFFSET_TYPE || TREE_CODE (type) == METHOD_TYPE) { cp_error_at ("typedef name may not be class-qualified", decl); return NULL_TREE; } else if (quals) { if (ctype == NULL_TREE) { if (TREE_CODE (type) != METHOD_TYPE) cp_error_at ("invalid type qualifier for non-method type", decl); else ctype = TYPE_METHOD_BASETYPE (type); } if (ctype != NULL_TREE) grok_method_quals (ctype, decl, quals); } if (RIDBIT_SETP (RID_SIGNED, specbits) || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))) C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1; if (RIDBIT_SETP (RID_MUTABLE, specbits)) error ("non-object member `%s' cannot be declared mutable", name); bad_specifiers (decl, "type", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); if (initialized) error ("typedef declaration includes an initializer"); return decl; } /* Detect the case of an array type of unspecified size which came, as such, direct from a typedef name. We must copy the type, so that each identifier gets a distinct type, so that each identifier's size can be controlled separately by its own initializer. */ if (type == typedef_type && TREE_CODE (type) == ARRAY_TYPE && TYPE_DOMAIN (type) == NULL_TREE) { type = build_cplus_array_type (TREE_TYPE (type), TYPE_DOMAIN (type)); } /* If this is a type name (such as, in a cast or sizeof), compute the type and return it now. */ if (decl_context == TYPENAME) { /* Note that the grammar rejects storage classes in typenames, fields or parameters. */ if (type_quals != TYPE_UNQUALIFIED) { if (IS_SIGNATURE (type)) error ("type qualifiers specified for signature type"); type_quals = TYPE_UNQUALIFIED; } /* Special case: "friend class foo" looks like a TYPENAME context. */ if (friendp) { if (type_quals != TYPE_UNQUALIFIED) { cp_error ("type qualifiers specified for friend class declaration"); type_quals = TYPE_UNQUALIFIED; } if (inlinep) { cp_error ("`inline' specified for friend class declaration"); inlinep = 0; } /* Only try to do this stuff if we didn't already give up. */ if (type != integer_type_node) { /* A friendly class? */ if (current_class_type) make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type)); else error ("trying to make class `%s' a friend of global scope", TYPE_NAME_STRING (type)); type = void_type_node; } } else if (quals) { tree dummy = build_decl (TYPE_DECL, declarator, type); if (ctype == NULL_TREE) { my_friendly_assert (TREE_CODE (type) == METHOD_TYPE, 159); ctype = TYPE_METHOD_BASETYPE (type); } grok_method_quals (ctype, dummy, quals); type = TREE_TYPE (dummy); } return type; } else if (declarator == NULL_TREE && decl_context != PARM && decl_context != CATCHPARM && TREE_CODE (type) != UNION_TYPE && ! bitfield) { cp_error ("abstract declarator `%T' used as declaration", type); declarator = make_anon_name (); } /* `void' at top level (not within pointer) is allowed only in typedefs or type names. We don't complain about parms either, but that is because a better error message can be made later. */ if (TREE_CODE (type) == VOID_TYPE && decl_context != PARM) { if (! declarator) error ("unnamed variable or field declared void"); else if (TREE_CODE (declarator) == IDENTIFIER_NODE) { if (IDENTIFIER_OPNAME_P (declarator)) my_friendly_abort (356); else error ("variable or field `%s' declared void", name); } else error ("variable or field declared void"); type = integer_type_node; } /* Now create the decl, which may be a VAR_DECL, a PARM_DECL or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */ if (decl_context == PARM || decl_context == CATCHPARM) { if (ctype || in_namespace) error ("cannot use `::' in parameter declaration"); /* A parameter declared as an array of T is really a pointer to T. One declared as a function is really a pointer to a function. One declared as a member is really a pointer to member. */ if (TREE_CODE (type) == ARRAY_TYPE) { /* Transfer const-ness of array into that of type pointed to. */ type = build_pointer_type (TREE_TYPE (type)); type_quals = TYPE_UNQUALIFIED; } else if (TREE_CODE (type) == FUNCTION_TYPE) type = build_pointer_type (type); else if (TREE_CODE (type) == OFFSET_TYPE) type = build_pointer_type (type); else if (TREE_CODE (type) == VOID_TYPE && declarator) { error ("declaration of `%s' as void", name); return NULL_TREE; } } { register tree decl; if (decl_context == PARM) { decl = build_decl (PARM_DECL, declarator, type); bad_specifiers (decl, "parameter", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); if (current_class_type && IS_SIGNATURE (current_class_type)) { if (inlinep) error ("parameter of signature member function declared `inline'"); if (RIDBIT_SETP (RID_AUTO, specbits)) error ("parameter of signature member function declared `auto'"); if (RIDBIT_SETP (RID_REGISTER, specbits)) error ("parameter of signature member function declared `register'"); } /* Compute the type actually passed in the parmlist, for the case where there is no prototype. (For example, shorts and chars are passed as ints.) When there is a prototype, this is overridden later. */ DECL_ARG_TYPE (decl) = type_promotes_to (type); } else if (decl_context == FIELD) { if (type == error_mark_node) { /* Happens when declaring arrays of sizes which are error_mark_node, for example. */ decl = NULL_TREE; } else if (in_namespace && !friendp) { /* Something like struct S { int N::j; }; */ cp_error ("invalid use of `::'"); decl = NULL_TREE; } else if (TREE_CODE (type) == FUNCTION_TYPE) { int publicp = 0; tree function_context; /* We catch the others as conflicts with the builtin typedefs. */ if (friendp && declarator == ridpointers[(int) RID_SIGNED]) { cp_error ("function `%D' cannot be declared friend", declarator); friendp = 0; } if (friendp == 0) { if (ctype == NULL_TREE) ctype = current_class_type; if (ctype == NULL_TREE) { cp_error ("can't make `%D' into a method -- not in a class", declarator); return void_type_node; } /* ``A union may [ ... ] not [ have ] virtual functions.'' ARM 9.5 */ if (virtualp && TREE_CODE (ctype) == UNION_TYPE) { cp_error ("function `%D' declared virtual inside a union", declarator); return void_type_node; } if (declarator == ansi_opname[(int) NEW_EXPR] || declarator == ansi_opname[(int) VEC_NEW_EXPR] || declarator == ansi_opname[(int) DELETE_EXPR] || declarator == ansi_opname[(int) VEC_DELETE_EXPR]) { if (virtualp) { cp_error ("`%D' cannot be declared virtual, since it is always static", declarator); virtualp = 0; } } else if (staticp < 2) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); } /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ function_context = (ctype != NULL_TREE) ? hack_decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; publicp = (! friendp || ! staticp) && function_context == NULL_TREE; decl = grokfndecl (ctype, type, TREE_CODE (declarator) != TEMPLATE_ID_EXPR ? declarator : dname, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0, friendp, publicp, inlinep, funcdef_flag, template_count, in_namespace); if (decl == NULL_TREE) return decl; #if 0 /* This clobbers the attrs stored in `decl' from `attrlist'. */ /* The decl and setting of decl_machine_attr is also turned off. */ decl = build_decl_attribute_variant (decl, decl_machine_attr); #endif /* [class.conv.ctor] A constructor declared without the function-specifier explicit that can be called with a single parameter specifies a conversion from the type of its first parameter to the type of its class. Such a constructor is called a converting constructor. */ if (explicitp == 2) DECL_NONCONVERTING_P (decl) = 1; else if (DECL_CONSTRUCTOR_P (decl)) { /* The constructor can be called with exactly one parameter if there is at least one parameter, and any subsequent parameters have default arguments. We don't look at the first parameter, which is really just the `this' parameter for the new object. */ tree arg_types = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))); /* Skip the `in_chrg' argument too, if present. */ if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (decl))) arg_types = TREE_CHAIN (arg_types); + /* And the `vlist' argument. */ + if (TYPE_USES_PVBASES (DECL_CONTEXT (decl))) + arg_types = TREE_CHAIN (arg_types); + if (arg_types == void_list_node || (arg_types && TREE_CHAIN (arg_types) && TREE_CHAIN (arg_types) != void_list_node && !TREE_PURPOSE (TREE_CHAIN (arg_types)))) DECL_NONCONVERTING_P (decl) = 1; } } else if (TREE_CODE (type) == METHOD_TYPE) { /* We only get here for friend declarations of members of other classes. */ /* All method decls are public, so tell grokfndecl to set TREE_PUBLIC, also. */ decl = grokfndecl (ctype, type, declarator, declarator, virtualp, flags, quals, raises, friendp ? -1 : 0, friendp, 1, 0, funcdef_flag, template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; } else if (!staticp && ! processing_template_decl && TYPE_SIZE (complete_type (type)) == NULL_TREE && (TREE_CODE (type) != ARRAY_TYPE || initialized == 0)) { if (declarator) cp_error ("field `%D' has incomplete type", declarator); else cp_error ("name `%T' has incomplete type", type); /* If we're instantiating a template, tell them which instantiation made the field's type be incomplete. */ if (current_class_type && TYPE_NAME (current_class_type) && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)) && declspecs && TREE_VALUE (declspecs) && TREE_TYPE (TREE_VALUE (declspecs)) == type) cp_error (" in instantiation of template `%T'", current_class_type); type = error_mark_node; decl = NULL_TREE; } else { if (friendp) { error ("`%s' is neither function nor method; cannot be declared friend", IDENTIFIER_POINTER (declarator)); friendp = 0; } decl = NULL_TREE; } if (friendp) { /* Friends are treated specially. */ if (ctype == current_class_type) warning ("member functions are implicitly friends of their class"); else { tree t = NULL_TREE; if (decl && DECL_NAME (decl)) { if (template_class_depth (current_class_type) == 0) { decl = check_explicit_specialization (declarator, decl, template_count, 2 * (funcdef_flag != 0) + 4); if (decl == error_mark_node) return error_mark_node; } t = do_friend (ctype, declarator, decl, last_function_parms, attrlist, flags, quals, funcdef_flag); } if (t && funcdef_flag) return t; return void_type_node; } } /* Structure field. It may not be a function, except for C++ */ if (decl == NULL_TREE) { if (initialized) { if (!staticp) { /* An attempt is being made to initialize a non-static member. But, from [class.mem]: 4 A member-declarator can contain a constant-initializer only if it declares a static member (_class.static_) of integral or enumeration type, see _class.static.data_. This used to be relatively common practice, but the rest of the compiler does not correctly handle the initialization unless the member is static so we make it static below. */ cp_pedwarn ("ANSI C++ forbids initialization of member `%D'", declarator); cp_pedwarn ("making `%D' static", declarator); staticp = 1; } if (uses_template_parms (type)) /* We'll check at instantiation time. */ ; else if (check_static_variable_definition (declarator, type)) /* If we just return the declaration, crashes will sometimes occur. We therefore return void_type_node, as if this was a friend declaration, to cause callers to completely ignore this declaration. */ return void_type_node; } /* 9.2p13 [class.mem] */ if (declarator == constructor_name (current_class_type) /* Divergence from the standard: In extern "C", we allow non-static data members here, because C does and /usr/include/netinet/in.h uses that. */ && (staticp || ! in_system_header)) cp_pedwarn ("ANSI C++ forbids data member `%D' with same name as enclosing class", declarator); if (staticp) { /* C++ allows static class members. All other work for this is done by grokfield. This VAR_DCL is built by build_lang_field_decl. All other VAR_DECLs are built by build_decl. */ decl = build_lang_field_decl (VAR_DECL, declarator, type); TREE_STATIC (decl) = 1; /* In class context, 'static' means public access. */ TREE_PUBLIC (decl) = DECL_EXTERNAL (decl) = 1; } else { decl = build_lang_field_decl (FIELD_DECL, declarator, type); if (RIDBIT_SETP (RID_MUTABLE, specbits)) { DECL_MUTABLE_P (decl) = 1; RIDBIT_RESET (RID_MUTABLE, specbits); } } bad_specifiers (decl, "field", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); } } else if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) { tree original_name; int publicp = 0; if (! declarator) return NULL_TREE; if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) original_name = dname; else original_name = declarator; if (RIDBIT_SETP (RID_AUTO, specbits)) error ("storage class `auto' invalid for function `%s'", name); else if (RIDBIT_SETP (RID_REGISTER, specbits)) error ("storage class `register' invalid for function `%s'", name); /* Function declaration not at top level. Storage classes other than `extern' are not allowed and `extern' makes no difference. */ if (! toplevel_bindings_p () && (RIDBIT_SETP (RID_STATIC, specbits) || RIDBIT_SETP (RID_INLINE, specbits)) && pedantic) { if (RIDBIT_SETP (RID_STATIC, specbits)) pedwarn ("storage class `static' invalid for function `%s' declared out of global scope", name); else pedwarn ("storage class `inline' invalid for function `%s' declared out of global scope", name); } if (ctype == NULL_TREE) { if (virtualp) { error ("virtual non-class function `%s'", name); virtualp = 0; } } else if (TREE_CODE (type) == FUNCTION_TYPE && staticp < 2) type = build_cplus_method_type (ctype, TREE_TYPE (type), TYPE_ARG_TYPES (type)); /* Record presence of `static'. */ publicp = (ctype != NULL_TREE || RIDBIT_SETP (RID_EXTERN, specbits) || !RIDBIT_SETP (RID_STATIC, specbits)); decl = grokfndecl (ctype, type, original_name, declarator, virtualp, flags, quals, raises, 1, friendp, publicp, inlinep, funcdef_flag, template_count, in_namespace); if (decl == NULL_TREE) return NULL_TREE; if (staticp == 1) { int illegal_static = 0; /* Don't allow a static member function in a class, and forbid declaring main to be static. */ if (TREE_CODE (type) == METHOD_TYPE) { cp_pedwarn ("cannot declare member function `%D' to have static linkage", decl); illegal_static = 1; } else if (current_function_decl) { /* FIXME need arm citation */ error ("cannot declare static function inside another function"); illegal_static = 1; } if (illegal_static) { staticp = 0; RIDBIT_RESET (RID_STATIC, specbits); } } } else { /* It's a variable. */ /* An uninitialized decl with `extern' is a reference. */ decl = grokvardecl (type, declarator, &specbits, initialized, (type_quals & TYPE_QUAL_CONST) != 0, in_namespace); bad_specifiers (decl, "variable", virtualp, quals != NULL_TREE, inlinep, friendp, raises != NULL_TREE); if (ctype) { DECL_CONTEXT (decl) = ctype; if (staticp == 1) { cp_pedwarn ("static member `%D' re-declared as static", decl); staticp = 0; RIDBIT_RESET (RID_STATIC, specbits); } if (RIDBIT_SETP (RID_REGISTER, specbits) && TREE_STATIC (decl)) { cp_error ("static member `%D' declared `register'", decl); RIDBIT_RESET (RID_REGISTER, specbits); } if (RIDBIT_SETP (RID_EXTERN, specbits) && pedantic) { cp_pedwarn ("cannot explicitly declare member `%#D' to have extern linkage", decl); RIDBIT_RESET (RID_EXTERN, specbits); } } } if (RIDBIT_SETP (RID_MUTABLE, specbits)) { error ("`%s' cannot be declared mutable", name); } /* Record `register' declaration for warnings on & and in case doing stupid register allocation. */ if (RIDBIT_SETP (RID_REGISTER, specbits)) DECL_REGISTER (decl) = 1; if (RIDBIT_SETP (RID_EXTERN, specbits)) DECL_THIS_EXTERN (decl) = 1; if (RIDBIT_SETP (RID_STATIC, specbits)) DECL_THIS_STATIC (decl) = 1; /* Record constancy and volatility. */ /* FIXME: Disallow `restrict' pointer-to-member declarations. */ c_apply_type_quals_to_decl (type_quals, decl); return decl; } } /* Tell if a parmlist/exprlist looks like an exprlist or a parmlist. An empty exprlist is a parmlist. An exprlist which contains only identifiers at the global level is a parmlist. Otherwise, it is an exprlist. */ int parmlist_is_exprlist (exprs) tree exprs; { if (exprs == NULL_TREE || TREE_PARMLIST (exprs)) return 0; if (toplevel_bindings_p ()) { /* At the global level, if these are all identifiers, then it is a parmlist. */ while (exprs) { if (TREE_CODE (TREE_VALUE (exprs)) != IDENTIFIER_NODE) return 1; exprs = TREE_CHAIN (exprs); } return 0; } return 1; } /* Subroutine of start_function. Ensure that each of the parameter types (as listed in PARMS) is complete, as is required for a function definition. */ static void require_complete_types_for_parms (parms) tree parms; { while (parms) { tree type = TREE_TYPE (parms); if (TYPE_SIZE (complete_type (type)) == NULL_TREE) { if (DECL_NAME (parms)) error ("parameter `%s' has incomplete type", IDENTIFIER_POINTER (DECL_NAME (parms))); else error ("parameter has incomplete type"); TREE_TYPE (parms) = error_mark_node; } else layout_decl (parms, 0); parms = TREE_CHAIN (parms); } } /* Returns DECL if DECL is a local variable (or parameter). Returns NULL_TREE otherwise. */ static tree local_variable_p (t) tree t; { if ((TREE_CODE (t) == VAR_DECL /* A VAR_DECL with a context that is a _TYPE is a static data member. */ && !TYPE_P (CP_DECL_CONTEXT (t)) /* Any other non-local variable must be at namespace scope. */ && TREE_CODE (CP_DECL_CONTEXT (t)) != NAMESPACE_DECL) || (TREE_CODE (t) == PARM_DECL)) return t; return NULL_TREE; } /* Check that ARG, which is a default-argument expression for a parameter DECL, is legal. Returns ARG, or ERROR_MARK_NODE, if something goes wrong. DECL may also be a _TYPE node, rather than a DECL, if there is no DECL available. */ tree check_default_argument (decl, arg) tree decl; tree arg; { tree var; tree decl_type; if (TREE_CODE (arg) == DEFAULT_ARG) /* We get a DEFAULT_ARG when looking at an in-class declaration with a default argument. Ignore the argument for now; we'll deal with it after the class is complete. */ return arg; if (processing_template_decl || uses_template_parms (arg)) /* We don't do anything checking until instantiation-time. Note that there may be uninstantiated arguments even for an instantiated function, since default arguments are not instantiated until they are needed. */ return arg; if (TYPE_P (decl)) { decl_type = decl; decl = NULL_TREE; } else decl_type = TREE_TYPE (decl); if (arg == error_mark_node || decl == error_mark_node || TREE_TYPE (arg) == error_mark_node || decl_type == error_mark_node) /* Something already went wrong. There's no need to check further. */ return error_mark_node; /* [dcl.fct.default] A default argument expression is implicitly converted to the parameter type. */ if (!TREE_TYPE (arg) || !can_convert_arg (decl_type, TREE_TYPE (arg), arg)) { if (decl) cp_error ("default argument for `%#D' has type `%T'", decl, TREE_TYPE (arg)); else cp_error ("default argument for paramter of type `%T' has type `%T'", decl_type, TREE_TYPE (arg)); return error_mark_node; } /* [dcl.fct.default] Local variables shall not be used in default argument expressions. The keyword `this' shall not be used in a default argument of a member function. */ var = search_tree (arg, local_variable_p); if (var) { cp_error ("default argument `%E' uses local variable `%D'", arg, var); return error_mark_node; } /* All is well. */ return arg; } /* Decode the list of parameter types for a function type. Given the list of things declared inside the parens, return a list of types. The list we receive can have three kinds of elements: an IDENTIFIER_NODE for names given without types, a TREE_LIST node for arguments given as typespecs or names with typespecs, or void_type_node, to mark the end of an argument list when additional arguments are not permitted (... was not used). FUNCDEF_FLAG is nonzero for a function definition, 0 for a mere declaration. A nonempty identifier-list gets an error message when FUNCDEF_FLAG is zero. If FUNCDEF_FLAG is 1, then parameter types must be complete. If FUNCDEF_FLAG is -1, then parameter types may be incomplete. If all elements of the input list contain types, we return a list of the types. If all elements contain no type (except perhaps a void_type_node at the end), we return a null list. If some have types and some do not, it is an error, and we return a null list. Also set last_function_parms to either a list of names (IDENTIFIER_NODEs) or a chain of PARM_DECLs. A list of names is converted to a chain of PARM_DECLs by store_parm_decls so that ultimately it is always a chain of decls. Note that in C++, parameters can take default values. These default values are in the TREE_PURPOSE field of the TREE_LIST. It is an error to specify default values which are followed by parameters that have no default values, or an ELLIPSES. For simplicities sake, only parameters which are specified with their types can take on default values. */ static tree grokparms (first_parm, funcdef_flag) tree first_parm; int funcdef_flag; { tree result = NULL_TREE; tree decls = NULL_TREE; if (first_parm != NULL_TREE && TREE_CODE (TREE_VALUE (first_parm)) == IDENTIFIER_NODE) { if (! funcdef_flag) pedwarn ("parameter names (without types) in function declaration"); last_function_parms = first_parm; return NULL_TREE; } else if (first_parm != NULL_TREE && TREE_CODE (TREE_VALUE (first_parm)) != TREE_LIST && TREE_CODE (TREE_VALUE (first_parm)) != VOID_TYPE) my_friendly_abort (145); else { /* Types were specified. This is a list of declarators each represented as a TREE_LIST node. */ register tree parm, chain; int any_init = 0, any_error = 0; if (first_parm != NULL_TREE) { tree last_result = NULL_TREE; tree last_decl = NULL_TREE; for (parm = first_parm; parm != NULL_TREE; parm = chain) { tree type = NULL_TREE, list_node = parm; register tree decl = TREE_VALUE (parm); tree init = TREE_PURPOSE (parm); chain = TREE_CHAIN (parm); /* @@ weak defense against parse errors. */ if (TREE_CODE (decl) != VOID_TYPE && TREE_CODE (decl) != TREE_LIST) { /* Give various messages as the need arises. */ if (TREE_CODE (decl) == STRING_CST) cp_error ("invalid string constant `%E'", decl); else if (TREE_CODE (decl) == INTEGER_CST) error ("invalid integer constant in parameter list, did you forget to give parameter name?"); continue; } if (TREE_CODE (decl) != VOID_TYPE) { decl = grokdeclarator (TREE_VALUE (decl), TREE_PURPOSE (decl), PARM, init != NULL_TREE, NULL_TREE); if (! decl || TREE_TYPE (decl) == error_mark_node) continue; /* Top-level qualifiers on the parameters are ignored for function types. */ type = TYPE_MAIN_VARIANT (TREE_TYPE (decl)); if (TREE_CODE (type) == VOID_TYPE) decl = void_type_node; else if (TREE_CODE (type) == METHOD_TYPE) { if (DECL_NAME (decl)) /* Cannot use the decl here because we don't have DECL_CONTEXT set up yet. */ cp_error ("parameter `%D' invalidly declared method type", DECL_NAME (decl)); else error ("parameter invalidly declared method type"); type = build_pointer_type (type); TREE_TYPE (decl) = type; } else if (TREE_CODE (type) == OFFSET_TYPE) { if (DECL_NAME (decl)) cp_error ("parameter `%D' invalidly declared offset type", DECL_NAME (decl)); else error ("parameter invalidly declared offset type"); type = build_pointer_type (type); TREE_TYPE (decl) = type; } else if (TREE_CODE (type) == RECORD_TYPE && TYPE_LANG_SPECIFIC (type) && CLASSTYPE_ABSTRACT_VIRTUALS (type)) { abstract_virtuals_error (decl, type); any_error = 1; /* Seems like a good idea. */ } else if (TREE_CODE (type) == RECORD_TYPE && TYPE_LANG_SPECIFIC (type) && IS_SIGNATURE (type)) { signature_error (decl, type); any_error = 1; /* Seems like a good idea. */ } else if (POINTER_TYPE_P (type)) { tree t = type; while (POINTER_TYPE_P (t) || (TREE_CODE (t) == ARRAY_TYPE && TYPE_DOMAIN (t) != NULL_TREE)) t = TREE_TYPE (t); if (TREE_CODE (t) == ARRAY_TYPE) cp_error ("parameter type `%T' includes %s to array of unknown bound", type, TYPE_PTR_P (type) ? "pointer" : "reference"); } } if (TREE_CODE (decl) == VOID_TYPE) { if (result == NULL_TREE) { result = void_list_node; last_result = result; } else { TREE_CHAIN (last_result) = void_list_node; last_result = void_list_node; } if (chain && (chain != void_list_node || TREE_CHAIN (chain))) error ("`void' in parameter list must be entire list"); break; } /* Since there is a prototype, args are passed in their own types. */ DECL_ARG_TYPE (decl) = TREE_TYPE (decl); #ifdef PROMOTE_PROTOTYPES if ((TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == ENUMERAL_TYPE) && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) DECL_ARG_TYPE (decl) = integer_type_node; #endif if (!any_error && init) { any_init++; init = check_default_argument (decl, init); } else init = NULL_TREE; if (decls == NULL_TREE) { decls = decl; last_decl = decls; } else { TREE_CHAIN (last_decl) = decl; last_decl = decl; } if (! current_function_decl && TREE_PERMANENT (list_node)) { TREE_PURPOSE (list_node) = init; TREE_VALUE (list_node) = type; TREE_CHAIN (list_node) = NULL_TREE; } else list_node = saveable_tree_cons (init, type, NULL_TREE); if (result == NULL_TREE) { result = list_node; last_result = result; } else { TREE_CHAIN (last_result) = list_node; last_result = list_node; } } if (last_result) TREE_CHAIN (last_result) = NULL_TREE; /* If there are no parameters, and the function does not end with `...', then last_decl will be NULL_TREE. */ if (last_decl != NULL_TREE) TREE_CHAIN (last_decl) = NULL_TREE; } } last_function_parms = decls; return result; } /* Called from the parser to update an element of TYPE_ARG_TYPES for some FUNCTION_TYPE with the newly parsed version of its default argument, which was previously digested as text. See snarf_defarg et al in lex.c. */ void replace_defarg (arg, init) tree arg, init; { if (! processing_template_decl && ! can_convert_arg (TREE_VALUE (arg), TREE_TYPE (init), init)) cp_pedwarn ("invalid type `%T' for default argument to `%T'", TREE_TYPE (init), TREE_VALUE (arg)); TREE_PURPOSE (arg) = init; } +/* Return 1 if D copies its arguments. This is used to test for copy + constructors and copy assignment operators. */ + int copy_args_p (d) tree d; { tree t = FUNCTION_ARG_CHAIN (d); if (DECL_CONSTRUCTOR_P (d) && TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (d))) - t = TREE_CHAIN (t); + { + t = TREE_CHAIN (t); + if (TYPE_USES_PVBASES (DECL_CONTEXT (d))) + t = TREE_CHAIN (t); + } + if (t && TREE_CODE (TREE_VALUE (t)) == REFERENCE_TYPE && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (t))) == DECL_CLASS_CONTEXT (d)) && (TREE_CHAIN (t) == NULL_TREE || TREE_CHAIN (t) == void_list_node || TREE_PURPOSE (TREE_CHAIN (t)))) return 1; return 0; } /* These memoizing functions keep track of special properties which a class may have. `grok_ctor_properties' notices whether a class has a constructor of the form X(X&), and also complains if the class has a constructor of the form X(X). `grok_op_properties' takes notice of the various forms of operator= which are defined, as well as what sorts of type conversion may apply. Both functions take a FUNCTION_DECL as an argument. */ int grok_ctor_properties (ctype, decl) tree ctype, decl; { tree parmtypes = FUNCTION_ARG_CHAIN (decl); tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node; /* When a type has virtual baseclasses, a magical first int argument is added to any ctor so we can tell if the class has been initialized yet. This could screw things up in this function, so we deliberately ignore the leading int if we're in that situation. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (ctype)) + if (TYPE_USES_VIRTUAL_BASECLASSES (ctype) + && !CLASSTYPE_IS_TEMPLATE (ctype)) { my_friendly_assert (parmtypes && TREE_VALUE (parmtypes) == integer_type_node, 980529); parmtypes = TREE_CHAIN (parmtypes); parmtype = TREE_VALUE (parmtypes); } + if (TYPE_USES_PVBASES (ctype)) + { + my_friendly_assert (parmtypes + && TREE_VALUE (parmtypes) == vlist_type_node, + 980529); + parmtypes = TREE_CHAIN (parmtypes); + parmtype = TREE_VALUE (parmtypes); + } + /* [class.copy] A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments. */ if (TREE_CODE (parmtype) == REFERENCE_TYPE && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == ctype && (TREE_CHAIN (parmtypes) == NULL_TREE || TREE_CHAIN (parmtypes) == void_list_node || TREE_PURPOSE (TREE_CHAIN (parmtypes))) && !(DECL_TEMPLATE_INSTANTIATION (decl) && is_member_template (DECL_TI_TEMPLATE (decl)))) { TYPE_HAS_INIT_REF (ctype) = 1; if (CP_TYPE_CONST_P (TREE_TYPE (parmtype))) TYPE_HAS_CONST_INIT_REF (ctype) = 1; } /* [class.copy] A declaration of a constructor for a class X is ill-formed if its first parameter is of type (optionally cv-qualified) X and either there are no other parameters or else all other parameters have default arguments. We *don't* complain about member template instantiations that have this form, though; they can occur as we try to decide what constructor to use during overload resolution. Since overload resolution will never prefer such a constructor to the non-template copy constructor (which is either explicitly or implicitly defined), there's no need to worry about their existence. Theoretically, they should never even be instantiated, but that's hard to forestall. */ else if (TYPE_MAIN_VARIANT (parmtype) == ctype && (TREE_CHAIN (parmtypes) == NULL_TREE || TREE_CHAIN (parmtypes) == void_list_node || TREE_PURPOSE (TREE_CHAIN (parmtypes))) && !(DECL_TEMPLATE_INSTANTIATION (decl) && is_member_template (DECL_TI_TEMPLATE (decl)))) { cp_error ("invalid constructor; you probably meant `%T (const %T&)'", ctype, ctype); SET_IDENTIFIER_ERROR_LOCUS (DECL_NAME (decl), ctype); return 0; } else if (TREE_CODE (parmtype) == VOID_TYPE || TREE_PURPOSE (parmtypes) != NULL_TREE) TYPE_HAS_DEFAULT_CONSTRUCTOR (ctype) = 1; return 1; } /* An operator with this name can be either unary or binary. */ static int ambi_op_p (name) tree name; { return (name == ansi_opname [(int) INDIRECT_REF] || name == ansi_opname [(int) ADDR_EXPR] || name == ansi_opname [(int) NEGATE_EXPR] || name == ansi_opname[(int) POSTINCREMENT_EXPR] || name == ansi_opname[(int) POSTDECREMENT_EXPR] || name == ansi_opname [(int) CONVERT_EXPR]); } /* An operator with this name can only be unary. */ static int unary_op_p (name) tree name; { return (name == ansi_opname [(int) TRUTH_NOT_EXPR] || name == ansi_opname [(int) BIT_NOT_EXPR] || name == ansi_opname [(int) COMPONENT_REF] || IDENTIFIER_TYPENAME_P (name)); } /* Do a little sanity-checking on how they declared their operator. */ void grok_op_properties (decl, virtualp, friendp) tree decl; int virtualp, friendp; { tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl)); int methodp = (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE); tree name = DECL_NAME (decl); if (current_class_type == NULL_TREE) friendp = 1; if (! friendp) { /* [class.copy] A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&, const X&, volatile X& or const volatile X&. */ if (name == ansi_opname[(int) MODIFY_EXPR] && !(DECL_TEMPLATE_INSTANTIATION (decl) && is_member_template (DECL_TI_TEMPLATE (decl)))) ; else if (name == ansi_opname[(int) CALL_EXPR]) TYPE_OVERLOADS_CALL_EXPR (current_class_type) = 1; else if (name == ansi_opname[(int) ARRAY_REF]) TYPE_OVERLOADS_ARRAY_REF (current_class_type) = 1; else if (name == ansi_opname[(int) COMPONENT_REF] || name == ansi_opname[(int) MEMBER_REF]) TYPE_OVERLOADS_ARROW (current_class_type) = 1; else if (name == ansi_opname[(int) NEW_EXPR]) TYPE_GETS_NEW (current_class_type) |= 1; else if (name == ansi_opname[(int) DELETE_EXPR]) TYPE_GETS_DELETE (current_class_type) |= 1; else if (name == ansi_opname[(int) VEC_NEW_EXPR]) TYPE_GETS_NEW (current_class_type) |= 2; else if (name == ansi_opname[(int) VEC_DELETE_EXPR]) TYPE_GETS_DELETE (current_class_type) |= 2; } if (name == ansi_opname[(int) NEW_EXPR] || name == ansi_opname[(int) VEC_NEW_EXPR]) { /* When the compiler encounters the definition of A::operator new, it doesn't look at the class declaration to find out if it's static. */ if (methodp) revert_static_member_fn (&decl, NULL, NULL); /* Take care of function decl if we had syntax errors. */ if (argtypes == NULL_TREE) TREE_TYPE (decl) = build_function_type (ptr_type_node, hash_tree_chain (integer_type_node, void_list_node)); else TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl)); } else if (name == ansi_opname[(int) DELETE_EXPR] || name == ansi_opname[(int) VEC_DELETE_EXPR]) { if (methodp) revert_static_member_fn (&decl, NULL, NULL); if (argtypes == NULL_TREE) TREE_TYPE (decl) = build_function_type (void_type_node, hash_tree_chain (ptr_type_node, void_list_node)); else { TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl)); if (! friendp && name == ansi_opname[(int) VEC_DELETE_EXPR] && (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) != void_list_node)) TYPE_VEC_DELETE_TAKES_SIZE (current_class_type) = 1; } } else { /* An operator function must either be a non-static member function or have at least one parameter of a class, a reference to a class, an enumeration, or a reference to an enumeration. 13.4.0.6 */ if (! methodp || DECL_STATIC_FUNCTION_P (decl)) { if (IDENTIFIER_TYPENAME_P (name) || name == ansi_opname[(int) CALL_EXPR] || name == ansi_opname[(int) MODIFY_EXPR] || name == ansi_opname[(int) COMPONENT_REF] || name == ansi_opname[(int) ARRAY_REF]) cp_error ("`%D' must be a nonstatic member function", decl); else { tree p = argtypes; if (DECL_STATIC_FUNCTION_P (decl)) cp_error ("`%D' must be either a non-static member function or a non-member function", decl); if (p) for (; TREE_CODE (TREE_VALUE (p)) != VOID_TYPE ; p = TREE_CHAIN (p)) { tree arg = TREE_VALUE (p); if (TREE_CODE (arg) == REFERENCE_TYPE) arg = TREE_TYPE (arg); /* This lets bad template code slip through. */ if (IS_AGGR_TYPE (arg) || TREE_CODE (arg) == ENUMERAL_TYPE || TREE_CODE (arg) == TEMPLATE_TYPE_PARM || TREE_CODE (arg) == TEMPLATE_TEMPLATE_PARM) goto foundaggr; } cp_error ("`%D' must have an argument of class or enumerated type", decl); foundaggr: ; } } if (name == ansi_opname[(int) CALL_EXPR]) return; /* No restrictions on args. */ if (IDENTIFIER_TYPENAME_P (name) && ! DECL_TEMPLATE_INFO (decl)) { tree t = TREE_TYPE (name); if (TREE_CODE (t) == VOID_TYPE) pedwarn ("void is not a valid type conversion operator"); else if (! friendp) { int ref = (TREE_CODE (t) == REFERENCE_TYPE); const char *what = 0; if (ref) t = TYPE_MAIN_VARIANT (TREE_TYPE (t)); if (t == current_class_type) what = "the same type"; /* Don't force t to be complete here. */ else if (IS_AGGR_TYPE (t) && TYPE_SIZE (t) && DERIVED_FROM_P (t, current_class_type)) what = "a base class"; if (what) warning ("conversion to %s%s will never use a type conversion operator", ref ? "a reference to " : "", what); } } if (name == ansi_opname[(int) MODIFY_EXPR]) { tree parmtype; if (list_length (argtypes) != 3 && methodp) { cp_error ("`%D' must take exactly one argument", decl); return; } parmtype = TREE_VALUE (TREE_CHAIN (argtypes)); if (copy_assignment_arg_p (parmtype, virtualp) && ! friendp) { TYPE_HAS_ASSIGN_REF (current_class_type) = 1; if (TREE_CODE (parmtype) != REFERENCE_TYPE || CP_TYPE_CONST_P (TREE_TYPE (parmtype))) TYPE_HAS_CONST_ASSIGN_REF (current_class_type) = 1; } } else if (name == ansi_opname[(int) COND_EXPR]) { /* 13.4.0.3 */ pedwarn ("ANSI C++ prohibits overloading operator ?:"); if (list_length (argtypes) != 4) cp_error ("`%D' must take exactly three arguments", decl); } else if (ambi_op_p (name)) { if (list_length (argtypes) == 2) /* prefix */; else if (list_length (argtypes) == 3) { if ((name == ansi_opname[(int) POSTINCREMENT_EXPR] || name == ansi_opname[(int) POSTDECREMENT_EXPR]) && ! processing_template_decl && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)), integer_type_node)) { if (methodp) cp_error ("postfix `%D' must take `int' as its argument", decl); else cp_error ("postfix `%D' must take `int' as its second argument", decl); } } else { if (methodp) cp_error ("`%D' must take either zero or one argument", decl); else cp_error ("`%D' must take either one or two arguments", decl); } /* More Effective C++ rule 6. */ if (warn_ecpp && (name == ansi_opname[(int) POSTINCREMENT_EXPR] || name == ansi_opname[(int) POSTDECREMENT_EXPR])) { tree arg = TREE_VALUE (argtypes); tree ret = TREE_TYPE (TREE_TYPE (decl)); if (methodp || TREE_CODE (arg) == REFERENCE_TYPE) arg = TREE_TYPE (arg); arg = TYPE_MAIN_VARIANT (arg); if (list_length (argtypes) == 2) { if (TREE_CODE (ret) != REFERENCE_TYPE || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg)) cp_warning ("prefix `%D' should return `%T'", decl, build_reference_type (arg)); } else { if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg)) cp_warning ("postfix `%D' should return `%T'", decl, arg); } } } else if (unary_op_p (name)) { if (list_length (argtypes) != 2) { if (methodp) cp_error ("`%D' must take `void'", decl); else cp_error ("`%D' must take exactly one argument", decl); } } else /* if (binary_op_p (name)) */ { if (list_length (argtypes) != 3) { if (methodp) cp_error ("`%D' must take exactly one argument", decl); else cp_error ("`%D' must take exactly two arguments", decl); } /* More Effective C++ rule 7. */ if (warn_ecpp && (name == ansi_opname [TRUTH_ANDIF_EXPR] || name == ansi_opname [TRUTH_ORIF_EXPR] || name == ansi_opname [COMPOUND_EXPR])) cp_warning ("user-defined `%D' always evaluates both arguments", decl); } /* Effective C++ rule 23. */ if (warn_ecpp && list_length (argtypes) == 3 && (name == ansi_opname [PLUS_EXPR] || name == ansi_opname [MINUS_EXPR] || name == ansi_opname [TRUNC_DIV_EXPR] || name == ansi_opname [MULT_EXPR]) && TREE_CODE (TREE_TYPE (TREE_TYPE (decl))) == REFERENCE_TYPE) cp_warning ("`%D' should return by value", decl); /* 13.4.0.8 */ if (argtypes) for (; argtypes != void_list_node ; argtypes = TREE_CHAIN (argtypes)) if (TREE_PURPOSE (argtypes)) { TREE_PURPOSE (argtypes) = NULL_TREE; if (name == ansi_opname[(int) POSTINCREMENT_EXPR] || name == ansi_opname[(int) POSTDECREMENT_EXPR]) { if (pedantic) cp_pedwarn ("`%D' cannot have default arguments", decl); } else cp_error ("`%D' cannot have default arguments", decl); } } } static const char * tag_name (code) enum tag_types code; { switch (code) { case record_type: return "struct"; case class_type: return "class"; case union_type: return "union "; case enum_type: return "enum"; case signature_type: return "signature"; default: my_friendly_abort (981122); } } /* Get the struct, enum or union (CODE says which) with tag NAME. Define the tag as a forward-reference if it is not defined. C++: If a class derivation is given, process it here, and report an error if multiple derivation declarations are not identical. If this is a definition, come in through xref_tag and only look in the current frame for the name (since C++ allows new names in any scope.) */ tree xref_tag (code_type_node, name, globalize) tree code_type_node; tree name; int globalize; { enum tag_types tag_code; enum tree_code code; int temp = 0; register tree ref, t; struct binding_level *b = current_binding_level; int got_type = 0; tree attributes = NULL_TREE; tree context = NULL_TREE; /* If we are called from the parser, code_type_node will sometimes be a TREE_LIST. This indicates that the user wrote "class __attribute__ ((foo)) bar". Extract the attributes so we can use them later. */ if (TREE_CODE (code_type_node) == TREE_LIST) { attributes = TREE_PURPOSE (code_type_node); code_type_node = TREE_VALUE (code_type_node); } tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); switch (tag_code) { case record_type: case class_type: case signature_type: code = RECORD_TYPE; break; case union_type: code = UNION_TYPE; break; case enum_type: code = ENUMERAL_TYPE; break; default: my_friendly_abort (18); } /* If a cross reference is requested, look up the type already defined for this tag and return it. */ if (TREE_CODE_CLASS (TREE_CODE (name)) == 't') { t = name; name = TYPE_IDENTIFIER (t); got_type = 1; } else t = IDENTIFIER_TYPE_VALUE (name); if (t && TREE_CODE (t) != code && TREE_CODE (t) != TEMPLATE_TYPE_PARM && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM) t = NULL_TREE; if (! globalize) { /* If we know we are defining this tag, only look it up in this scope and don't try to find it as a type. */ ref = lookup_tag (code, name, b, 1); } else { if (t) { /* [dcl.type.elab] If the identifier resolves to a typedef-name or a template type-parameter, the elaborated-type-specifier is ill-formed. */ if (t != TYPE_MAIN_VARIANT (t) || (CLASS_TYPE_P (t) && TYPE_WAS_ANONYMOUS (t))) cp_pedwarn ("using typedef-name `%D' after `%s'", TYPE_NAME (t), tag_name (tag_code)); else if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) cp_error ("using template type parameter `%T' after `%s'", t, tag_name (tag_code)); ref = t; } else ref = lookup_tag (code, name, b, 0); if (! ref) { /* Try finding it as a type declaration. If that wins, use it. */ ref = lookup_name (name, 1); if (ref != NULL_TREE && processing_template_decl && DECL_CLASS_TEMPLATE_P (ref) && template_class_depth (current_class_type) == 0) /* Since GLOBALIZE is true, we're declaring a global template, so we want this type. */ ref = DECL_RESULT (ref); if (ref && TREE_CODE (ref) == TYPE_DECL && TREE_CODE (TREE_TYPE (ref)) == code) ref = TREE_TYPE (ref); else ref = NULL_TREE; } if (ref && current_class_type && template_class_depth (current_class_type) && PROCESSING_REAL_TEMPLATE_DECL_P ()) { /* Since GLOBALIZE is non-zero, we are not looking at a definition of this tag. Since, in addition, we are currently processing a (member) template declaration of a template class, we must be very careful; consider: template struct S1 template struct S2 { template friend struct S1; }; Here, the S2::S1 declaration should not be confused with the outer declaration. In particular, the inner version should have a template parameter of level 2, not level 1. This would be particularly important if the member declaration were instead: template friend struct S1; say, when we should tsubst into `U' when instantiating S2. On the other hand, when presented with: template struct S1 { template struct S2 {}; template friend struct S2; }; we must find the inner binding eventually. We accomplish this by making sure that the new type we create to represent this declaration has the right TYPE_CONTEXT. */ context = TYPE_CONTEXT (ref); ref = NULL_TREE; } } push_obstacks_nochange (); if (! ref) { /* If no such tag is yet defined, create a forward-reference node and record it as the "definition". When a real declaration of this type is found, the forward-reference will be altered into a real type. */ /* In C++, since these migrate into the global scope, we must build them on the permanent obstack. */ temp = allocation_temporary_p (); if (temp) end_temporary_allocation (); if (code == ENUMERAL_TYPE) { cp_error ("use of enum `%#D' without previous declaration", name); ref = make_node (ENUMERAL_TYPE); /* Give the type a default layout like unsigned int to avoid crashing if it does not get defined. */ TYPE_MODE (ref) = TYPE_MODE (unsigned_type_node); TYPE_ALIGN (ref) = TYPE_ALIGN (unsigned_type_node); TREE_UNSIGNED (ref) = 1; TYPE_PRECISION (ref) = TYPE_PRECISION (unsigned_type_node); TYPE_MIN_VALUE (ref) = TYPE_MIN_VALUE (unsigned_type_node); TYPE_MAX_VALUE (ref) = TYPE_MAX_VALUE (unsigned_type_node); /* Enable us to recognize when a type is created in class context. To do nested classes correctly, this should probably be cleared out when we leave this classes scope. Currently this in only done in `start_enum'. */ pushtag (name, ref, globalize); } else { struct binding_level *old_b = class_binding_level; ref = make_lang_type (code); TYPE_CONTEXT (ref) = context; if (tag_code == signature_type) { SET_SIGNATURE (ref); /* Since a signature type will be turned into the type of signature tables, it's not only an interface. */ CLASSTYPE_INTERFACE_ONLY (ref) = 0; SET_CLASSTYPE_INTERFACE_KNOWN (ref); /* A signature doesn't have a vtable. */ CLASSTYPE_VTABLE_NEEDS_WRITING (ref) = 0; } #ifdef NONNESTED_CLASSES /* Class types don't nest the way enums do. */ class_binding_level = (struct binding_level *)0; #endif pushtag (name, ref, globalize); class_binding_level = old_b; } } else { /* If it no longer looks like a nested type, make sure it's in global scope. If it is not an IDENTIFIER, this is not a declaration */ if (b->namespace_p && !class_binding_level && TREE_CODE (name) == IDENTIFIER_NODE) { if (IDENTIFIER_NAMESPACE_VALUE (name) == NULL_TREE) SET_IDENTIFIER_NAMESPACE_VALUE (name, TYPE_NAME (ref)); } if (!globalize && processing_template_decl && IS_AGGR_TYPE (ref)) redeclare_class_template (ref, current_template_parms); } /* Until the type is defined, tentatively accept whatever structure tag the user hands us. */ if (TYPE_SIZE (ref) == NULL_TREE && ref != current_class_type /* Have to check this, in case we have contradictory tag info. */ && IS_AGGR_TYPE_CODE (TREE_CODE (ref))) { if (tag_code == class_type) CLASSTYPE_DECLARED_CLASS (ref) = 1; else if (tag_code == record_type || tag_code == signature_type) CLASSTYPE_DECLARED_CLASS (ref) = 0; } pop_obstacks (); TREE_TYPE (ref) = attributes; return ref; } tree xref_tag_from_type (old, id, globalize) tree old, id; int globalize; { tree code_type_node; if (TREE_CODE (old) == RECORD_TYPE) code_type_node = (CLASSTYPE_DECLARED_CLASS (old) ? class_type_node : record_type_node); else code_type_node = union_type_node; if (id == NULL_TREE) id = TYPE_IDENTIFIER (old); return xref_tag (code_type_node, id, globalize); } /* REF is a type (named NAME), for which we have just seen some baseclasses. BINFO is a list of those baseclasses; the TREE_PURPOSE is an access_* node, and the TREE_VALUE is the type of the base-class. CODE_TYPE_NODE indicates whether REF is a class, struct, or union. */ void xref_basetypes (code_type_node, name, ref, binfo) tree code_type_node; tree name, ref; tree binfo; { /* In the declaration `A : X, Y, ... Z' we mark all the types (A, X, Y, ..., Z) so we can check for duplicates. */ tree binfos; tree base; int i, len; enum tag_types tag_code = (enum tag_types) TREE_INT_CST_LOW (code_type_node); if (tag_code == union_type) { cp_error ("derived union `%T' invalid", ref); return; } len = list_length (binfo); push_obstacks (TYPE_OBSTACK (ref), TYPE_OBSTACK (ref)); /* First, make sure that any templates in base-classes are instantiated. This ensures that if we call ourselves recursively we do not get confused about which classes are marked and which are not. */ for (base = binfo; base; base = TREE_CHAIN (base)) complete_type (TREE_VALUE (base)); SET_CLASSTYPE_MARKED (ref); BINFO_BASETYPES (TYPE_BINFO (ref)) = binfos = make_tree_vec (len); for (i = 0; binfo; binfo = TREE_CHAIN (binfo)) { /* The base of a derived struct is public by default. */ int via_public = (TREE_PURPOSE (binfo) == access_public_node || TREE_PURPOSE (binfo) == access_public_virtual_node || (tag_code != class_type && (TREE_PURPOSE (binfo) == access_default_node || TREE_PURPOSE (binfo) == access_default_virtual_node))); int via_protected = (TREE_PURPOSE (binfo) == access_protected_node || TREE_PURPOSE (binfo) == access_protected_virtual_node); int via_virtual = (TREE_PURPOSE (binfo) == access_private_virtual_node || TREE_PURPOSE (binfo) == access_protected_virtual_node || TREE_PURPOSE (binfo) == access_public_virtual_node || TREE_PURPOSE (binfo) == access_default_virtual_node); tree basetype = TREE_VALUE (binfo); tree base_binfo; if (basetype && TREE_CODE (basetype) == TYPE_DECL) basetype = TREE_TYPE (basetype); if (!basetype || (TREE_CODE (basetype) != RECORD_TYPE && TREE_CODE (basetype) != TYPENAME_TYPE && TREE_CODE (basetype) != TEMPLATE_TYPE_PARM && TREE_CODE (basetype) != TEMPLATE_TEMPLATE_PARM)) { cp_error ("base type `%T' fails to be a struct or class type", TREE_VALUE (binfo)); continue; } GNU_xref_hier (name, basetype, via_public, via_virtual, 0); /* This code replaces similar code in layout_basetypes. We put the complete_type first for implicit `typename'. */ if (TYPE_SIZE (basetype) == NULL_TREE && ! (current_template_parms && uses_template_parms (basetype))) { cp_error ("base class `%T' has incomplete type", basetype); continue; } else { if (CLASSTYPE_MARKED (basetype)) { if (basetype == ref) cp_error ("recursive type `%T' undefined", basetype); else cp_error ("duplicate base type `%T' invalid", basetype); continue; } if (TYPE_FOR_JAVA (basetype) && current_lang_stack == current_lang_base) TYPE_FOR_JAVA (ref) = 1; /* Note that the BINFO records which describe individual inheritances are *not* shared in the lattice! They cannot be shared because a given baseclass may be inherited with different `accessibility' by different derived classes. (Each BINFO record describing an individual inheritance contains flags which say what the `accessibility' of that particular inheritance is.) */ base_binfo = make_binfo (integer_zero_node, basetype, CLASS_TYPE_P (basetype) ? TYPE_BINFO_VTABLE (basetype) : NULL_TREE, CLASS_TYPE_P (basetype) ? TYPE_BINFO_VIRTUALS (basetype) : NULL_TREE); TREE_VEC_ELT (binfos, i) = base_binfo; TREE_VIA_PUBLIC (base_binfo) = via_public; TREE_VIA_PROTECTED (base_binfo) = via_protected; TREE_VIA_VIRTUAL (base_binfo) = via_virtual; BINFO_INHERITANCE_CHAIN (base_binfo) = TYPE_BINFO (ref); /* We need to unshare the binfos now so that lookups during class definition work. */ unshare_base_binfos (base_binfo); SET_CLASSTYPE_MARKED (basetype); /* We are free to modify these bits because they are meaningless at top level, and BASETYPE is a top-level type. */ if (via_virtual || TYPE_USES_VIRTUAL_BASECLASSES (basetype)) { TYPE_USES_VIRTUAL_BASECLASSES (ref) = 1; TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; + /* The PVBASES flag is never set for templates; we know + only for instantiations whether the virtual bases are + polymorphic. */ + if (flag_vtable_thunks >= 2 && !CLASSTYPE_IS_TEMPLATE (ref)) + { + if (via_virtual && TYPE_VIRTUAL_P (basetype)) + TYPE_USES_PVBASES (ref) = 1; + else if (TYPE_USES_PVBASES (basetype)) + TYPE_USES_PVBASES (ref) = 1; + } } if (CLASS_TYPE_P (basetype)) { TYPE_GETS_NEW (ref) |= TYPE_GETS_NEW (basetype); TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype); } i += 1; } } if (i) TREE_VEC_LENGTH (binfos) = i; else BINFO_BASETYPES (TYPE_BINFO (ref)) = NULL_TREE; if (i > 1) TYPE_USES_MULTIPLE_INHERITANCE (ref) = 1; else if (i == 1) { tree basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, 0)); if (CLASS_TYPE_P (basetype)) TYPE_USES_MULTIPLE_INHERITANCE (ref) = TYPE_USES_MULTIPLE_INHERITANCE (basetype); } if (TYPE_USES_MULTIPLE_INHERITANCE (ref)) TYPE_USES_COMPLEX_INHERITANCE (ref) = 1; /* Unmark all the types. */ while (--i >= 0) CLEAR_CLASSTYPE_MARKED (BINFO_TYPE (TREE_VEC_ELT (binfos, i))); CLEAR_CLASSTYPE_MARKED (ref); /* Now that we know all the base-classes, set up the list of virtual bases. */ CLASSTYPE_VBASECLASSES (ref) = get_vbase_types (ref); pop_obstacks (); } /* Begin compiling the definition of an enumeration type. NAME is its name (or null if anonymous). Returns the type object, as yet incomplete. Also records info about it so that build_enumerator may be used to declare the individual values as they are read. */ tree start_enum (name) tree name; { register tree enumtype = NULL_TREE; struct binding_level *b = current_binding_level; /* We are wasting space here and putting these on the permanent_obstack so that typeid(local enum) will work correctly. */ push_obstacks (&permanent_obstack, &permanent_obstack); /* If this is the real definition for a previous forward reference, fill in the contents in the same object that used to be the forward reference. */ if (name != NULL_TREE) enumtype = lookup_tag (ENUMERAL_TYPE, name, b, 1); if (enumtype != NULL_TREE && TREE_CODE (enumtype) == ENUMERAL_TYPE) cp_error ("multiple definition of `%#T'", enumtype); else { enumtype = make_node (ENUMERAL_TYPE); pushtag (name, enumtype, 0); } if (current_class_type) TREE_ADDRESSABLE (b->tags) = 1; /* We don't copy this value because build_enumerator needs to do it. */ enum_next_value = integer_zero_node; enum_overflow = 0; GNU_xref_decl (current_function_decl, enumtype); return enumtype; } /* After processing and defining all the values of an enumeration type, install their decls in the enumeration type and finish it off. ENUMTYPE is the type object and VALUES a list of name-value pairs. Returns ENUMTYPE. */ tree finish_enum (enumtype) tree enumtype; { register tree minnode = NULL_TREE, maxnode = NULL_TREE; /* Calculate the maximum value of any enumerator in this type. */ tree values = TYPE_VALUES (enumtype); if (values) { tree pair; for (pair = values; pair; pair = TREE_CHAIN (pair)) { tree decl; tree value; /* The TREE_VALUE is a CONST_DECL for this enumeration constant. */ decl = TREE_VALUE (pair); /* The DECL_INITIAL will be NULL if we are processing a template declaration and this enumeration constant had no explicit initializer. */ value = DECL_INITIAL (decl); if (value && !processing_template_decl) { /* Set the TREE_TYPE for the VALUE as well. That's so that when we call decl_constant_value we get an entity of the right type (but with the constant value). Since we shouldn't ever call decl_constant_value on a template type, there's no reason to do that when processing_template_decl. And, if the expression is something like a TEMPLATE_PARM_INDEX or a CAST_EXPR doing so will wreak havoc on the intended type of the expression. Of course, there's also no point in trying to compute minimum or maximum values if we're in a template. */ TREE_TYPE (value) = enumtype; if (!minnode) minnode = maxnode = value; else if (tree_int_cst_lt (maxnode, value)) maxnode = value; else if (tree_int_cst_lt (value, minnode)) minnode = value; } if (processing_template_decl) /* If this is just a template, leave the CONST_DECL alone. That way tsubst_copy will find CONST_DECLs for CONST_DECLs, and not INTEGER_CSTs. */ ; else /* In the list we're building up, we want the enumeration values, not the CONST_DECLs. */ TREE_VALUE (pair) = value; } } else maxnode = minnode = integer_zero_node; TYPE_VALUES (enumtype) = nreverse (values); if (processing_template_decl) { tree scope = current_scope (); if (scope && TREE_CODE (scope) == FUNCTION_DECL) add_tree (build_min (TAG_DEFN, enumtype)); } else { int unsignedp = tree_int_cst_sgn (minnode) >= 0; int lowprec = min_precision (minnode, unsignedp); int highprec = min_precision (maxnode, unsignedp); int precision = MAX (lowprec, highprec); tree tem; TYPE_SIZE (enumtype) = NULL_TREE; /* Set TYPE_MIN_VALUE and TYPE_MAX_VALUE according to `precision'. */ TYPE_PRECISION (enumtype) = precision; if (unsignedp) fixup_unsigned_type (enumtype); else fixup_signed_type (enumtype); if (flag_short_enums || (precision > TYPE_PRECISION (integer_type_node))) /* Use the width of the narrowest normal C type which is wide enough. */ TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1)); else TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node); TYPE_SIZE (enumtype) = 0; layout_type (enumtype); /* Fix up all variant types of this enum type. */ for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem)) { TYPE_VALUES (tem) = TYPE_VALUES (enumtype); TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype); TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype); TYPE_SIZE (tem) = TYPE_SIZE (enumtype); TYPE_SIZE_UNIT (tem) = TYPE_SIZE_UNIT (enumtype); TYPE_MODE (tem) = TYPE_MODE (enumtype); TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype); TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype); TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype); } /* Finish debugging output for this type. */ rest_of_type_compilation (enumtype, namespace_bindings_p ()); } /* In start_enum we pushed obstacks. Here, we must pop them. */ pop_obstacks (); return enumtype; } /* Build and install a CONST_DECL for an enumeration constant of the enumeration type TYPE whose NAME and VALUE (if any) are provided. Assignment of sequential values by default is handled here. */ tree build_enumerator (name, value, type) tree name; tree value; tree type; { tree decl, result; tree context; /* Remove no-op casts from the value. */ if (value) STRIP_TYPE_NOPS (value); if (! processing_template_decl) { /* Validate and default VALUE. */ if (value != NULL_TREE) { if (TREE_READONLY_DECL_P (value)) value = decl_constant_value (value); if (TREE_CODE (value) == INTEGER_CST) { value = default_conversion (value); constant_expression_warning (value); } else { cp_error ("enumerator value for `%D' not integer constant", name); value = NULL_TREE; } } /* Default based on previous value. */ if (value == NULL_TREE && ! processing_template_decl) { value = enum_next_value; if (enum_overflow) cp_error ("overflow in enumeration values at `%D'", name); } /* Remove no-op casts from the value. */ if (value) STRIP_TYPE_NOPS (value); #if 0 /* To fix MAX_VAL enum consts. (bkoz) */ TREE_TYPE (value) = integer_type_node; #endif } /* We always have to copy here; not all INTEGER_CSTs are unshared. Even in other cases, we will later (in finish_enum) be setting the type of VALUE. */ if (value != NULL_TREE) value = copy_node (value); /* C++ associates enums with global, function, or class declarations. */ context = current_scope (); if (context && context == current_class_type) /* This enum declaration is local to the class. */ decl = build_lang_field_decl (CONST_DECL, name, type); else /* It's a global enum, or it's local to a function. (Note local to a function could mean local to a class method. */ decl = build_decl (CONST_DECL, name, type); DECL_CONTEXT (decl) = FROB_CONTEXT (context); DECL_INITIAL (decl) = value; TREE_READONLY (decl) = 1; if (context && context == current_class_type) /* In something like `struct S { enum E { i = 7 }; };' we put `i' on the TYPE_FIELDS list for `S'. (That's so that you can say things like `S::i' later.) */ finish_member_declaration (decl); else { pushdecl (decl); GNU_xref_decl (current_function_decl, decl); } if (! processing_template_decl) { /* Set basis for default for next value. */ enum_next_value = build_binary_op_nodefault (PLUS_EXPR, value, integer_one_node, PLUS_EXPR); enum_overflow = tree_int_cst_lt (enum_next_value, value); } result = saveable_tree_cons (name, decl, NULL_TREE); return result; } static int function_depth; /* Create the FUNCTION_DECL for a function definition. DECLSPECS and DECLARATOR are the parts of the declaration; they describe the function's name and the type it returns, but twisted together in a fashion that parallels the syntax of C. If PRE_PARSED_P is non-zero then DECLARATOR is really the DECL for the function we are about to process; DECLSPECS are ignored. For example, we set PRE_PARSED_P when processing the definition of inline function that was defined in-class; the definition is actually processed when the class is complete. In this case, PRE_PARSED_P is 2. We also set PRE_PARSED_P when instanting the body of a template function, and when constructing thunk functions and such; in these cases PRE_PARSED_P is 1. This function creates a binding context for the function body as well as setting up the FUNCTION_DECL in current_function_decl. Returns 1 on success. If the DECLARATOR is not suitable for a function (it defines a datum instead), we return 0, which tells yyparse to report a parse error. For C++, we must first check whether that datum makes any sense. For example, "class A local_a(1,2);" means that variable local_a is an aggregate of type A, which should have a constructor applied to it with the argument list [1, 2]. @@ There is currently no way to retrieve the storage @@ allocated to FUNCTION (or all of its parms) if we return @@ something we had previously. */ int start_function (declspecs, declarator, attrs, pre_parsed_p) tree declspecs, declarator, attrs; int pre_parsed_p; { tree decl1; tree ctype = NULL_TREE; tree fntype; tree restype; extern int have_extern_spec; extern int used_extern_spec; int doing_friend = 0; /* Sanity check. */ my_friendly_assert (TREE_CODE (TREE_VALUE (void_list_node)) == VOID_TYPE, 160); my_friendly_assert (TREE_CHAIN (void_list_node) == NULL_TREE, 161); /* Assume, until we see it does. */ current_function_returns_value = 0; current_function_returns_null = 0; named_labels = 0; shadowed_labels = 0; current_function_assigns_this = 0; current_function_just_assigned_this = 0; current_function_parms_stored = 0; original_result_rtx = NULL_RTX; base_init_expr = NULL_TREE; current_base_init_list = NULL_TREE; current_member_init_list = NULL_TREE; ctor_label = dtor_label = NULL_TREE; static_labelno = 0; clear_temp_name (); /* This should only be done once on the top most decl. */ if (have_extern_spec && !used_extern_spec) { declspecs = decl_tree_cons (NULL_TREE, get_identifier ("extern"), declspecs); used_extern_spec = 1; } if (pre_parsed_p) { decl1 = declarator; #if 0 /* What was this testing for, exactly? */ if (! DECL_ARGUMENTS (decl1) && !DECL_STATIC_FUNCTION_P (decl1) && !DECL_ARTIFICIAL (decl1) && DECL_CLASS_SCOPE_P (decl1) && TYPE_IDENTIFIER (DECL_CONTEXT (decl1)) && IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (DECL_CONTEXT (decl1)))) { tree binding = binding_for_name (DECL_NAME (decl1), current_namespace); cp_error ("redeclaration of `%#D'", decl1); if (IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))) cp_error_at ("previous declaration here", IDENTIFIER_CLASS_VALUE (DECL_NAME (decl1))); else if (BINDING_VALUE (binding)) cp_error_at ("previous declaration here", BINDING_VALUE (binding)); } #endif fntype = TREE_TYPE (decl1); if (TREE_CODE (fntype) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (fntype); /* ANSI C++ June 5 1992 WP 11.4.5. A friend function defined in a class is in the (lexical) scope of the class in which it is defined. */ if (!ctype && DECL_FRIEND_P (decl1)) { ctype = DECL_CLASS_CONTEXT (decl1); /* CTYPE could be null here if we're dealing with a template; for example, `inline friend float foo()' inside a template will have no CTYPE set. */ if (ctype && TREE_CODE (ctype) != RECORD_TYPE) ctype = NULL_TREE; else doing_friend = 1; } last_function_parms = DECL_ARGUMENTS (decl1); last_function_parm_tags = NULL_TREE; } else { decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL_TREE); /* If the declarator is not suitable for a function definition, cause a syntax error. */ if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL) return 0; fntype = TREE_TYPE (decl1); restype = TREE_TYPE (fntype); if (CLASS_TYPE_P (restype) && !CLASSTYPE_GOT_SEMICOLON (restype)) { cp_error ("semicolon missing after declaration of `%#T'", restype); shadow_tag (build_expr_list (NULL_TREE, restype)); CLASSTYPE_GOT_SEMICOLON (restype) = 1; if (TREE_CODE (fntype) == FUNCTION_TYPE) fntype = build_function_type (integer_type_node, TYPE_ARG_TYPES (fntype)); else fntype = build_cplus_method_type (build_type_variant (TYPE_METHOD_BASETYPE (fntype), TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), integer_type_node, TYPE_ARG_TYPES (fntype)); TREE_TYPE (decl1) = fntype; } if (TREE_CODE (fntype) == METHOD_TYPE) ctype = TYPE_METHOD_BASETYPE (fntype); else if (DECL_MAIN_P (decl1)) { /* If this doesn't return integer_type, complain. */ if (TREE_TYPE (TREE_TYPE (decl1)) != integer_type_node) { if (pedantic || warn_return_type) pedwarn ("return type for `main' changed to `int'"); TREE_TYPE (decl1) = fntype = default_function_type; } } } /* Warn if function was previously implicitly declared (but not if we warned then). */ if (! warn_implicit && IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1)) != NULL_TREE) cp_warning_at ("`%D' implicitly declared before its definition", IDENTIFIER_IMPLICIT_DECL (DECL_NAME (decl1))); announce_function (decl1); /* Set up current_class_type, and enter the scope of the class, if appropriate. */ if (ctype) push_nested_class (ctype, 1); else if (DECL_STATIC_FUNCTION_P (decl1)) push_nested_class (DECL_CONTEXT (decl1), 2); /* Now that we have entered the scope of the class, we must restore the bindings for any template parameters surrounding DECL1, if it is an inline member template. (Order is important; consider the case where a template parameter has the same name as a field of the class.) It is not until after this point that PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */ if (pre_parsed_p == 2) maybe_begin_member_template_processing (decl1); /* We are now in the scope of the function being defined. */ current_function_decl = decl1; /* Save the parm names or decls from this function's declarator where store_parm_decls will find them. */ current_function_parms = last_function_parms; current_function_parm_tags = last_function_parm_tags; if (! processing_template_decl) { /* In a function definition, arg types must be complete. */ require_complete_types_for_parms (current_function_parms); if (TYPE_SIZE (complete_type (TREE_TYPE (fntype))) == NULL_TREE) { cp_error ("return-type `%#T' is an incomplete type", TREE_TYPE (fntype)); /* Make it return void instead, but don't change the type of the DECL_RESULT, in case we have a named return value. */ if (ctype) TREE_TYPE (decl1) = build_cplus_method_type (build_type_variant (ctype, TREE_READONLY (decl1), TREE_SIDE_EFFECTS (decl1)), void_type_node, FUNCTION_ARG_CHAIN (decl1)); else TREE_TYPE (decl1) = build_function_type (void_type_node, TYPE_ARG_TYPES (TREE_TYPE (decl1))); DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (TREE_TYPE (fntype))); TREE_READONLY (DECL_RESULT (decl1)) = CP_TYPE_CONST_P (TREE_TYPE (fntype)); TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = CP_TYPE_VOLATILE_P (TREE_TYPE (fntype)); } if (TYPE_LANG_SPECIFIC (TREE_TYPE (fntype)) && CLASSTYPE_ABSTRACT_VIRTUALS (TREE_TYPE (fntype))) abstract_virtuals_error (decl1, TREE_TYPE (fntype)); } /* Effective C++ rule 15. See also c_expand_return. */ if (warn_ecpp && DECL_NAME (decl1) == ansi_opname[(int) MODIFY_EXPR] && TREE_CODE (TREE_TYPE (fntype)) == VOID_TYPE) cp_warning ("`operator=' should return a reference to `*this'"); /* Make the init_value nonzero so pushdecl knows this is not tentative. error_mark_node is replaced below (in poplevel) with the BLOCK. */ DECL_INITIAL (decl1) = error_mark_node; #ifdef SET_DEFAULT_DECL_ATTRIBUTES SET_DEFAULT_DECL_ATTRIBUTES (decl1, attrs); #endif /* This function exists in static storage. (This does not mean `static' in the C sense!) */ TREE_STATIC (decl1) = 1; /* We must call push_template_decl after current_class_type is set up. (If we are processing inline definitions after exiting a class scope, current_class_type will be NULL_TREE until set above by push_nested_class.) */ if (processing_template_decl) decl1 = push_template_decl (decl1); /* Record the decl so that the function name is defined. If we already have a decl for this name, and it is a FUNCTION_DECL, use the old decl. */ if (!processing_template_decl && pre_parsed_p == 0) { /* A specialization is not used to guide overload resolution. */ if ((flag_guiding_decls || !DECL_TEMPLATE_SPECIALIZATION (decl1)) && ! DECL_FUNCTION_MEMBER_P (decl1)) decl1 = pushdecl (decl1); else { /* We need to set the DECL_CONTEXT. */ if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1)) DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1)); /* And make sure we have enough default args. */ check_default_args (decl1); } DECL_MAIN_VARIANT (decl1) = decl1; fntype = TREE_TYPE (decl1); } current_function_decl = decl1; if (DECL_INTERFACE_KNOWN (decl1)) { tree ctx = hack_decl_function_context (decl1); if (DECL_NOT_REALLY_EXTERN (decl1)) DECL_EXTERNAL (decl1) = 0; if (ctx != NULL_TREE && DECL_THIS_INLINE (ctx) && TREE_PUBLIC (ctx)) /* This is a function in a local class in an extern inline function. */ comdat_linkage (decl1); } /* If this function belongs to an interface, it is public. If it belongs to someone else's interface, it is also external. This only affects inlines and template instantiations. */ else if (interface_unknown == 0 && (! DECL_TEMPLATE_INSTANTIATION (decl1) || flag_alt_external_templates)) { if (DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1) || processing_template_decl) { DECL_EXTERNAL (decl1) = (interface_only || (DECL_THIS_INLINE (decl1) && ! flag_implement_inlines && !DECL_VINDEX (decl1))); /* For WIN32 we also want to put these in linkonce sections. */ maybe_make_one_only (decl1); } else DECL_EXTERNAL (decl1) = 0; DECL_NOT_REALLY_EXTERN (decl1) = 0; DECL_INTERFACE_KNOWN (decl1) = 1; } else if (interface_unknown && interface_only && (! DECL_TEMPLATE_INSTANTIATION (decl1) || flag_alt_external_templates)) { /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma interface, we will have interface_only set but not interface_known. In that case, we don't want to use the normal heuristics because someone will supply a #pragma implementation elsewhere, and deducing it here would produce a conflict. */ comdat_linkage (decl1); DECL_EXTERNAL (decl1) = 0; DECL_INTERFACE_KNOWN (decl1) = 1; DECL_DEFER_OUTPUT (decl1) = 1; } else { /* This is a definition, not a reference. So clear DECL_EXTERNAL. */ DECL_EXTERNAL (decl1) = 0; if ((DECL_THIS_INLINE (decl1) || DECL_TEMPLATE_INSTANTIATION (decl1)) && ! DECL_INTERFACE_KNOWN (decl1) /* Don't try to defer nested functions for now. */ && ! hack_decl_function_context (decl1)) DECL_DEFER_OUTPUT (decl1) = 1; else DECL_INTERFACE_KNOWN (decl1) = 1; } if (ctype != NULL_TREE && DECL_STATIC_FUNCTION_P (decl1)) { if (TREE_CODE (fntype) == METHOD_TYPE) TREE_TYPE (decl1) = fntype = build_function_type (TREE_TYPE (fntype), TREE_CHAIN (TYPE_ARG_TYPES (fntype))); current_function_parms = TREE_CHAIN (current_function_parms); DECL_ARGUMENTS (decl1) = current_function_parms; ctype = NULL_TREE; } restype = TREE_TYPE (fntype); if (ctype) { /* If we're compiling a friend function, neither of the variables current_class_ptr nor current_class_type will have values. */ if (! doing_friend) { /* We know that this was set up by `grokclassfn'. We do not wait until `store_parm_decls', since evil parse errors may never get us to that point. Here we keep the consistency between `current_class_type' and `current_class_ptr'. */ tree t = current_function_parms; my_friendly_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL, 162); if (TREE_CODE (TREE_TYPE (t)) == POINTER_TYPE) { int i; if (! hack_decl_function_context (decl1)) temporary_allocation (); i = suspend_momentary (); /* Normally, build_indirect_ref returns current_class_ref whenever current_class_ptr is dereferenced. This time, however, we want it to *create* current_class_ref, so we temporarily clear current_class_ptr to fool it. */ current_class_ptr = NULL_TREE; current_class_ref = build_indirect_ref (t, NULL_PTR); current_class_ptr = t; resume_momentary (i); if (! hack_decl_function_context (decl1)) end_temporary_allocation (); } else /* We're having a signature pointer here. */ current_class_ref = current_class_ptr = t; } } else current_class_ptr = current_class_ref = NULL_TREE; pushlevel (0); current_binding_level->parm_flag = 1; GNU_xref_function (decl1, current_function_parms); if (attrs) cplus_decl_attributes (decl1, NULL_TREE, attrs); make_function_rtl (decl1); /* Promote the value to int before returning it. */ if (C_PROMOTING_INTEGER_TYPE_P (restype)) restype = type_promotes_to (restype); /* If this fcn was already referenced via a block-scope `extern' decl (or an implicit decl), propagate certain information about the usage. */ if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl1))) TREE_ADDRESSABLE (decl1) = 1; if (DECL_RESULT (decl1) == NULL_TREE) { DECL_RESULT (decl1) = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype)); TREE_READONLY (DECL_RESULT (decl1)) = CP_TYPE_CONST_P (restype); TREE_THIS_VOLATILE (DECL_RESULT (decl1)) = CP_TYPE_VOLATILE_P (restype); } /* Allocate further tree nodes temporarily during compilation of this function only. Tiemann moved up here from bottom of fn. */ /* If this is a nested function, then we must continue to allocate RTL on the permanent obstack in case we need to inline it later. */ if (! hack_decl_function_context (decl1)) temporary_allocation (); if (processing_template_decl) { ++minimal_parse_mode; last_tree = DECL_SAVED_TREE (decl1) = build_nt (EXPR_STMT, void_zero_node); } ++function_depth; if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl1)) && DECL_LANGUAGE (decl1) == lang_cplusplus) { dtor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); ctor_label = NULL_TREE; } else { dtor_label = NULL_TREE; if (DECL_CONSTRUCTOR_P (decl1)) ctor_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); } return 1; } /* Called after store_parm_decls for a function-try-block. We need to update last_parm_cleanup_insn so that the base initializers for a constructor are run within this block, not before it. */ void expand_start_early_try_stmts () { expand_start_try_stmts (); last_parm_cleanup_insn = get_last_insn (); } /* Store the parameter declarations into the current function declaration. This is called after parsing the parameter declarations, before digesting the body of the function. Also install to binding contour return value identifier, if any. */ void store_parm_decls () { register tree fndecl = current_function_decl; register tree parm; int parms_have_cleanups = 0; tree cleanups = NULL_TREE; /* This is either a chain of PARM_DECLs (when a prototype is used). */ tree specparms = current_function_parms; /* This is a list of types declared among parms in a prototype. */ tree parmtags = current_function_parm_tags; /* This is a chain of any other decls that came in among the parm declarations. If a parm is declared with enum {foo, bar} x; then CONST_DECLs for foo and bar are put here. */ tree nonparms = NULL_TREE; if (toplevel_bindings_p ()) fatal ("parse errors have confused me too much"); /* Initialize RTL machinery. */ init_function_start (fndecl, input_filename, lineno); /* Create a binding level for the parms. */ expand_start_bindings (0); if (specparms != NULL_TREE) { /* This case is when the function was defined with an ANSI prototype. The parms already have decls, so we need not do anything here except record them as in effect and complain if any redundant old-style parm decls were written. */ register tree next; /* Must clear this because it might contain TYPE_DECLs declared at class level. */ storedecls (NULL_TREE); for (parm = nreverse (specparms); parm; parm = next) { next = TREE_CHAIN (parm); if (TREE_CODE (parm) == PARM_DECL) { tree cleanup; if (DECL_NAME (parm) == NULL_TREE) { pushdecl (parm); } else if (TREE_CODE (TREE_TYPE (parm)) == VOID_TYPE) cp_error ("parameter `%D' declared void", parm); else { /* Now fill in DECL_REFERENCE_SLOT for any of the parm decls. A parameter is assumed not to have any side effects. If this should change for any reason, then this will have to wrap the bashed reference type in a save_expr. Also, if the parameter type is declared to be an X and there is an X(X&) constructor, we cannot lay it into the stack (any more), so we make this parameter look like it is really of reference type. Functions which pass parameters to this function will know to create a temporary in their frame, and pass a reference to that. */ if (TREE_CODE (TREE_TYPE (parm)) == REFERENCE_TYPE && TYPE_SIZE (TREE_TYPE (TREE_TYPE (parm)))) SET_DECL_REFERENCE_SLOT (parm, convert_from_reference (parm)); pushdecl (parm); } if (! processing_template_decl && (cleanup = maybe_build_cleanup (parm), cleanup)) { expand_decl (parm); parms_have_cleanups = 1; /* Keep track of the cleanups. */ cleanups = tree_cons (parm, cleanup, cleanups); } } else { /* If we find an enum constant or a type tag, put it aside for the moment. */ TREE_CHAIN (parm) = NULL_TREE; nonparms = chainon (nonparms, parm); } } /* Get the decls in their original chain order and record in the function. This is all and only the PARM_DECLs that were pushed into scope by the loop above. */ DECL_ARGUMENTS (fndecl) = getdecls (); storetags (chainon (parmtags, gettags ())); } else DECL_ARGUMENTS (fndecl) = NULL_TREE; /* Now store the final chain of decls for the arguments as the decl-chain of the current lexical scope. Put the enumerators in as well, at the front so that DECL_ARGUMENTS is not modified. */ storedecls (chainon (nonparms, DECL_ARGUMENTS (fndecl))); /* Declare __FUNCTION__ and __PRETTY_FUNCTION__ for this function. */ declare_function_name (); /* Initialize the RTL code for the function. */ DECL_SAVED_INSNS (fndecl) = NULL_RTX; if (! processing_template_decl) expand_function_start (fndecl, parms_have_cleanups); current_function_parms_stored = 1; /* If this function is `main', emit a call to `__main' to run global initializers, etc. */ if (DECL_MAIN_P (fndecl)) expand_main_function (); /* Now that we have initialized the parms, we can start their cleanups. We cannot do this before, since expand_decl_cleanup should not be called before the parm can be used. */ if (cleanups && ! processing_template_decl) { for (cleanups = nreverse (cleanups); cleanups; cleanups = TREE_CHAIN (cleanups)) { if (! expand_decl_cleanup (TREE_PURPOSE (cleanups), TREE_VALUE (cleanups))) cp_error ("parser lost in parsing declaration of `%D'", TREE_PURPOSE (cleanups)); } } /* Create a binding contour which can be used to catch cleanup-generated temporaries. Also, if the return value needs or has initialization, deal with that now. */ if (parms_have_cleanups) { pushlevel (0); expand_start_bindings (0); } if (! processing_template_decl && flag_exceptions) { /* Do the starting of the exception specifications, if we have any. */ if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (current_function_decl))) expand_start_eh_spec (); } last_parm_cleanup_insn = get_last_insn (); last_dtor_insn = get_last_insn (); } /* Bind a name and initialization to the return value of the current function. */ void store_return_init (return_id, init) tree return_id, init; { tree decl = DECL_RESULT (current_function_decl); if (pedantic) /* Give this error as many times as there are occurrences, so that users can use Emacs compilation buffers to find and fix all such places. */ pedwarn ("ANSI C++ does not permit named return values"); if (return_id != NULL_TREE) { if (DECL_NAME (decl) == NULL_TREE) { DECL_NAME (decl) = return_id; DECL_ASSEMBLER_NAME (decl) = return_id; } else cp_error ("return identifier `%D' already in place", decl); } /* Can't let this happen for constructors. */ if (DECL_CONSTRUCTOR_P (current_function_decl)) { error ("can't redefine default return value for constructors"); return; } /* If we have a named return value, put that in our scope as well. */ if (DECL_NAME (decl) != NULL_TREE) { /* If this named return value comes in a register, put it in a pseudo-register. */ if (DECL_REGISTER (decl)) { original_result_rtx = DECL_RTL (decl); DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl)); } /* Let `cp_finish_decl' know that this initializer is ok. */ DECL_INITIAL (decl) = init; pushdecl (decl); if (minimal_parse_mode) add_tree (build_min_nt (RETURN_INIT, return_id, copy_to_permanent (init))); else cp_finish_decl (decl, init, NULL_TREE, 0, 0); } } +/* Emit implicit code for a destructor. This is a subroutine of + finish_function. */ + +static void +finish_dtor () +{ + tree binfo = TYPE_BINFO (current_class_type); + tree cond = integer_one_node; + tree exprstmt; + tree in_charge_node = lookup_name (in_charge_identifier, 0); + tree virtual_size; + int ok_to_optimize_dtor = 0; + int empty_dtor = get_last_insn () == last_dtor_insn; + rtx insns, last_parm_insn; + + if (current_function_assigns_this) + cond = build (NE_EXPR, boolean_type_node, + current_class_ptr, integer_zero_node); + else + { + int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); + + /* If this destructor is empty, then we don't need to check + whether `this' is NULL in some cases. */ + if ((flag_this_is_variable & 1) == 0) + ok_to_optimize_dtor = 1; + else if (empty_dtor) + ok_to_optimize_dtor + = (n_baseclasses == 0 + || (n_baseclasses == 1 + && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); + } + + /* If this has a vlist1 parameter, allocate the corresponding vlist + parameter. */ + if (DECL_DESTRUCTOR_FOR_PVBASE_P (current_function_decl)) + { + /* _Vlist __vlist; */ + tree vlist; + + mark_all_temps_used(); + vlist = pushdecl (build_decl (VAR_DECL, vlist_identifier, + vlist_type_node)); + TREE_USED (vlist) = 1; + DECL_ARTIFICIAL (vlist) = 1; + expand_decl (vlist); + expand_decl_init (vlist); + } + + /* These initializations might go inline. Protect + the binding level of the parms. */ + pushlevel (0); + expand_start_bindings (0); + + if (current_function_assigns_this) + { + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; + } + + /* Generate the code to call destructor on base class. + If this destructor belongs to a class with virtual + functions, then set the virtual function table + pointer to represent the type of our base class. */ + + /* This side-effect makes call to `build_delete' generate the + code we have to have at the end of this destructor. + `build_delete' will set the flag again. */ + TYPE_HAS_DESTRUCTOR (current_class_type) = 0; + + /* These are two cases where we cannot delegate deletion. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) + || TYPE_GETS_REG_DELETE (current_class_type)) + exprstmt = build_delete + (current_class_type, current_class_ref, integer_zero_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); + else + exprstmt = build_delete + (current_class_type, current_class_ref, in_charge_node, + LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); + + /* If we did not assign to this, then `this' is non-zero at + the end of a destructor. As a special optimization, don't + emit test if this is an empty destructor. If it does nothing, + it does nothing. If it calls a base destructor, the base + destructor will perform the test. */ + + if (exprstmt != error_mark_node + && (TREE_CODE (exprstmt) != NOP_EXPR + || TREE_OPERAND (exprstmt, 0) != integer_zero_node + || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) + { + expand_label (dtor_label); + if (cond != integer_one_node) + expand_start_cond (cond, 0); + if (exprstmt != void_zero_node) + /* Don't call `expand_expr_stmt' if we're not going to do + anything, since -Wall will give a diagnostic. */ + expand_expr_stmt (exprstmt); + + /* Run destructor on all virtual baseclasses. */ + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + { + tree vbases = nreverse + (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); + expand_start_cond (build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_two_node), 0); + while (vbases) + { + if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) + { + tree vb = get_vbase + (BINFO_TYPE (vbases), + TYPE_BINFO (current_class_type)); + + expand_expr_stmt + (build_base_dtor_call (current_class_ref, + vb, integer_zero_node)); + } + vbases = TREE_CHAIN (vbases); + } + expand_end_cond (); + } + + do_pending_stack_adjust (); + if (cond != integer_one_node) + expand_end_cond (); + } + + virtual_size = c_sizeof (current_class_type); + + /* At the end, call delete if that's what's requested. */ + + /* FDIS sez: At the point of definition of a virtual destructor + (including an implicit definition), non-placement operator + delete shall be looked up in the scope of the destructor's + class and if found shall be accessible and unambiguous. + + This is somewhat unclear, but I take it to mean that if the + class only defines placement deletes we don't do anything here. + So we pass LOOKUP_SPECULATIVELY; delete_sanity will complain + for us if they ever try to delete one of these. */ + + if (TYPE_GETS_REG_DELETE (current_class_type) + || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + exprstmt = build_op_delete_call + (DELETE_EXPR, current_class_ptr, virtual_size, + LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE); + else + exprstmt = NULL_TREE; + + if (exprstmt) + { + cond = build (BIT_AND_EXPR, integer_type_node, + in_charge_node, integer_one_node); + expand_start_cond (cond, 0); + expand_expr_stmt (exprstmt); + expand_end_cond (); + } + + /* End of destructor. */ + expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); + poplevel (getdecls () != NULL_TREE, 0, 0); + + /* Back to the top of destructor. */ + /* Don't execute destructor code if `this' is NULL. */ + + start_sequence (); + + /* If we need thunk-style vlists, initialize them if the caller did + not pass them. This requires a new temporary. The generated code + looks like + if (!(__in_charge & 4)) + __vlist = __vl. + sizeof(__vl.); + else + __vlist = __vlist1; + */ + if (TYPE_USES_PVBASES (current_class_type)) + { + tree vlist = lookup_name (vlist_identifier, 0); + tree vlist1 = lookup_name (get_identifier (VLIST1_NAME), 0); + cond = build (BIT_AND_EXPR, integer_type_node, + in_charge_node, build_int_2 (4, 0)); + cond = build1 (TRUTH_NOT_EXPR, boolean_type_node, cond); + expand_start_cond (cond, 0); + init_vlist (current_class_type); + expand_start_else (); + expand_expr_stmt (build_modify_expr (vlist, NOP_EXPR, vlist1)); + expand_end_cond (); + } + + /* If the dtor is empty, and we know there is not possible way we + could use any vtable entries, before they are possibly set by + a base class dtor, we don't have to setup the vtables, as we + know that any base class dtoring will set up any vtables it + needs. We avoid MI, because one base class dtor can do a + virtual dispatch to an overridden function that would need to + have a non-related vtable set up, we cannot avoid setting up + vtables in that case. We could change this to see if there is + just one vtable. */ + if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) + { + /* Make all virtual function table pointers in non-virtual base + classes point to CURRENT_CLASS_TYPE's virtual function + tables. */ + expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); + + if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) + expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); + } + + if (! ok_to_optimize_dtor) + { + cond = build_binary_op (NE_EXPR, + current_class_ptr, integer_zero_node); + expand_start_cond (cond, 0); + } + + insns = get_insns (); + end_sequence (); + + last_parm_insn = get_first_nonparm_insn (); + if (last_parm_insn == NULL_RTX) + last_parm_insn = get_last_insn (); + else + last_parm_insn = previous_insn (last_parm_insn); + + emit_insns_after (insns, last_parm_insn); + + if (! ok_to_optimize_dtor) + expand_end_cond (); +} + +/* Emit implicit code for a constructor. This is a subroutine of + finish_function. CALL_POPLEVEL is the same variable in + finish_function. */ + +static void +finish_ctor (call_poplevel) + int call_poplevel; +{ + register tree fndecl = current_function_decl; + tree cond = NULL_TREE, thenclause = NULL_TREE; + rtx insns; + tree decls; + + /* Allow constructor for a type to get a new instance of the object + using `build_new'. */ + tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; + + if (flag_this_is_variable > 0) + { + cond = build_binary_op (EQ_EXPR, current_class_ptr, integer_zero_node); + thenclause = + build_modify_expr (current_class_ptr, NOP_EXPR, + build_new (NULL_TREE, current_class_type, + void_type_node, 0)); + } + + CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; + + start_sequence (); + + if (flag_this_is_variable > 0) + { + expand_start_cond (cond, 0); + expand_expr_stmt (thenclause); + expand_end_cond (); + } + + /* Emit insns from `emit_base_init' which sets up virtual + function table pointer(s). */ + if (base_init_expr) + { + expand_expr_stmt (base_init_expr); + base_init_expr = NULL_TREE; + } + + insns = get_insns (); + end_sequence (); + + /* This is where the body of the constructor begins. */ + + emit_insns_after (insns, last_parm_cleanup_insn); + + end_protect_partials (); + + /* This is where the body of the constructor ends. */ + expand_label (ctor_label); + ctor_label = NULL_TREE; + + if (call_poplevel) + { + decls = getdecls (); + expand_end_bindings (decls, decls != NULL_TREE, 0); + poplevel (decls != NULL_TREE, 1, 0); + } + + /* c_expand_return knows to return 'this' from a constructor. */ + c_expand_return (NULL_TREE); + + current_function_assigns_this = 0; + current_function_just_assigned_this = 0; +} + + /* Finish up a function declaration and compile that function all the way to assembler language output. The free the storage for the function definition. This is called after parsing the body of the function definition. LINENO is the current line number. FLAGS is a bitwise or of the following values: 1 - CALL_POPLEVEL An extra call to poplevel (and expand_end_bindings) must be made to take care of the binding contour for the base initializers. This is only relevant for constructors. 2 - INCLASS_INLINE We just finished processing the body of an in-class inline function definition. (This processing will have taken place after the class definition is complete.) NESTED is nonzero if we were in the middle of compiling another function when we started on this one. */ void finish_function (lineno, flags, nested) int lineno; int flags; int nested; { register tree fndecl = current_function_decl; tree fntype, ctype = NULL_TREE; - rtx last_parm_insn, insns; /* Label to use if this function is supposed to return a value. */ tree no_return_label = NULL_TREE; tree decls = NULL_TREE; int call_poplevel = (flags & 1) != 0; int inclass_inline = (flags & 2) != 0; int in_template; /* When we get some parse errors, we can end up without a current_function_decl, so cope. */ if (fndecl == NULL_TREE) return; if (function_depth > 1) nested = 1; fntype = TREE_TYPE (fndecl); /* TREE_READONLY (fndecl) = 1; This caused &foo to be of type ptr-to-const-function which then got a warning when stored in a ptr-to-function variable. */ /* This happens on strange parse errors. */ if (! current_function_parms_stored) { call_poplevel = 0; store_parm_decls (); } if (processing_template_decl) { if (DECL_CONSTRUCTOR_P (fndecl) && call_poplevel) { decls = getdecls (); expand_end_bindings (decls, decls != NULL_TREE, 0); poplevel (decls != NULL_TREE, 0, 0); } } else { if (write_symbols != NO_DEBUG /*&& TREE_CODE (fntype) != METHOD_TYPE*/) { tree ttype = target_type (fntype); tree parmdecl; if (IS_AGGR_TYPE (ttype)) /* Let debugger know it should output info for this type. */ note_debug_info_needed (ttype); for (parmdecl = DECL_ARGUMENTS (fndecl); parmdecl; parmdecl = TREE_CHAIN (parmdecl)) { ttype = target_type (TREE_TYPE (parmdecl)); if (IS_AGGR_TYPE (ttype)) /* Let debugger know it should output info for this type. */ note_debug_info_needed (ttype); } } /* Clean house because we will need to reorder insns here. */ do_pending_stack_adjust (); if (dtor_label) - { - tree binfo = TYPE_BINFO (current_class_type); - tree cond = integer_one_node; - tree exprstmt; - tree in_charge_node = lookup_name (in_charge_identifier, 0); - tree virtual_size; - int ok_to_optimize_dtor = 0; - int empty_dtor = get_last_insn () == last_dtor_insn; - - if (current_function_assigns_this) - cond = build (NE_EXPR, boolean_type_node, - current_class_ptr, integer_zero_node); - else - { - int n_baseclasses = CLASSTYPE_N_BASECLASSES (current_class_type); - - /* If this destructor is empty, then we don't need to check - whether `this' is NULL in some cases. */ - if ((flag_this_is_variable & 1) == 0) - ok_to_optimize_dtor = 1; - else if (empty_dtor) - ok_to_optimize_dtor - = (n_baseclasses == 0 - || (n_baseclasses == 1 - && TYPE_HAS_DESTRUCTOR (TYPE_BINFO_BASETYPE (current_class_type, 0)))); - } - - /* These initializations might go inline. Protect - the binding level of the parms. */ - pushlevel (0); - expand_start_bindings (0); - - if (current_function_assigns_this) - { - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - } - - /* Generate the code to call destructor on base class. - If this destructor belongs to a class with virtual - functions, then set the virtual function table - pointer to represent the type of our base class. */ - - /* This side-effect makes call to `build_delete' generate the - code we have to have at the end of this destructor. - `build_delete' will set the flag again. */ - TYPE_HAS_DESTRUCTOR (current_class_type) = 0; - - /* These are two cases where we cannot delegate deletion. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type) - || TYPE_GETS_REG_DELETE (current_class_type)) - exprstmt = build_delete (current_class_type, current_class_ref, integer_zero_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); - else - exprstmt = build_delete (current_class_type, current_class_ref, in_charge_node, - LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR|LOOKUP_NORMAL, 0); - - /* If we did not assign to this, then `this' is non-zero at - the end of a destructor. As a special optimization, don't - emit test if this is an empty destructor. If it does nothing, - it does nothing. If it calls a base destructor, the base - destructor will perform the test. */ - - if (exprstmt != error_mark_node - && (TREE_CODE (exprstmt) != NOP_EXPR - || TREE_OPERAND (exprstmt, 0) != integer_zero_node - || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type))) - { - expand_label (dtor_label); - if (cond != integer_one_node) - expand_start_cond (cond, 0); - if (exprstmt != void_zero_node) - /* Don't call `expand_expr_stmt' if we're not going to do - anything, since -Wall will give a diagnostic. */ - expand_expr_stmt (exprstmt); - - /* Run destructor on all virtual baseclasses. */ - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - { - tree vbases = nreverse (copy_list (CLASSTYPE_VBASECLASSES (current_class_type))); - expand_start_cond (build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_two_node), 0); - while (vbases) - { - if (TYPE_NEEDS_DESTRUCTOR (BINFO_TYPE (vbases))) - { - tree vb = get_vbase - (BINFO_TYPE (vbases), - TYPE_BINFO (current_class_type)); - expand_expr_stmt - (build_scoped_method_call - (current_class_ref, vb, dtor_identifier, - build_expr_list (NULL_TREE, integer_zero_node))); - } - vbases = TREE_CHAIN (vbases); - } - expand_end_cond (); - } - - do_pending_stack_adjust (); - if (cond != integer_one_node) - expand_end_cond (); - } - - virtual_size = c_sizeof (current_class_type); - - /* At the end, call delete if that's what's requested. */ - - /* FDIS sez: At the point of definition of a virtual destructor - (including an implicit definition), non-placement operator - delete shall be looked up in the scope of the destructor's - class and if found shall be accessible and unambiguous. - - This is somewhat unclear, but I take it to mean that if the - class only defines placement deletes we don't do anything here. - So we pass LOOKUP_SPECULATIVELY; delete_sanity will complain - for us if they ever try to delete one of these. */ - - if (TYPE_GETS_REG_DELETE (current_class_type) - || TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - exprstmt = build_op_delete_call - (DELETE_EXPR, current_class_ptr, virtual_size, - LOOKUP_NORMAL | LOOKUP_SPECULATIVELY, NULL_TREE); - else - exprstmt = NULL_TREE; - - if (exprstmt) - { - cond = build (BIT_AND_EXPR, integer_type_node, - in_charge_node, integer_one_node); - expand_start_cond (cond, 0); - expand_expr_stmt (exprstmt); - expand_end_cond (); - } - - /* End of destructor. */ - expand_end_bindings (NULL_TREE, getdecls () != NULL_TREE, 0); - poplevel (getdecls () != NULL_TREE, 0, 0); - - /* Back to the top of destructor. */ - /* Don't execute destructor code if `this' is NULL. */ - - start_sequence (); - - /* If the dtor is empty, and we know there is not possible way we - could use any vtable entries, before they are possibly set by - a base class dtor, we don't have to setup the vtables, as we - know that any base class dtoring will set up any vtables it - needs. We avoid MI, because one base class dtor can do a - virtual dispatch to an overridden function that would need to - have a non-related vtable set up, we cannot avoid setting up - vtables in that case. We could change this to see if there is - just one vtable. */ - if (! empty_dtor || TYPE_USES_COMPLEX_INHERITANCE (current_class_type)) - { - /* Make all virtual function table pointers in non-virtual base - classes point to CURRENT_CLASS_TYPE's virtual function - tables. */ - expand_direct_vtbls_init (binfo, binfo, 1, 0, current_class_ptr); - - if (TYPE_USES_VIRTUAL_BASECLASSES (current_class_type)) - expand_indirect_vtbls_init (binfo, current_class_ref, current_class_ptr); - } - - if (! ok_to_optimize_dtor) - { - cond = build_binary_op (NE_EXPR, - current_class_ptr, integer_zero_node); - expand_start_cond (cond, 0); - } - - insns = get_insns (); - end_sequence (); - - last_parm_insn = get_first_nonparm_insn (); - if (last_parm_insn == NULL_RTX) - last_parm_insn = get_last_insn (); - else - last_parm_insn = previous_insn (last_parm_insn); - - emit_insns_after (insns, last_parm_insn); - - if (! ok_to_optimize_dtor) - expand_end_cond (); - } + finish_dtor (); else if (current_function_assigns_this) { /* Does not need to call emit_base_init, because that is done (if needed) just after assignment to this is seen. */ if (DECL_CONSTRUCTOR_P (current_function_decl)) { end_protect_partials (); expand_label (ctor_label); ctor_label = NULL_TREE; if (call_poplevel) { decls = getdecls (); expand_end_bindings (decls, decls != NULL_TREE, 0); poplevel (decls != NULL_TREE, 0, 0); } /* c_expand_return knows to return 'this' from a constructor. */ c_expand_return (NULL_TREE); } else if (TREE_CODE (TREE_TYPE (DECL_RESULT (current_function_decl))) != VOID_TYPE && return_label != NULL_RTX) no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); current_function_assigns_this = 0; current_function_just_assigned_this = 0; base_init_expr = NULL_TREE; } - else if (DECL_CONSTRUCTOR_P (fndecl)) - { - tree cond = NULL_TREE, thenclause = NULL_TREE; - /* Allow constructor for a type to get a new instance of the object - using `build_new'. */ - tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type); - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = NULL_TREE; - - if (flag_this_is_variable > 0) - { - cond = build_binary_op (EQ_EXPR, - current_class_ptr, integer_zero_node); - thenclause = build_modify_expr (current_class_ptr, NOP_EXPR, - build_new (NULL_TREE, current_class_type, void_type_node, 0)); - } - - CLASSTYPE_ABSTRACT_VIRTUALS (current_class_type) = abstract_virtuals; - - start_sequence (); - - if (flag_this_is_variable > 0) - { - expand_start_cond (cond, 0); - expand_expr_stmt (thenclause); - expand_end_cond (); - } - - /* Emit insns from `emit_base_init' which sets up virtual - function table pointer(s). */ - if (base_init_expr) - { - expand_expr_stmt (base_init_expr); - base_init_expr = NULL_TREE; - } - - insns = get_insns (); - end_sequence (); - - /* This is where the body of the constructor begins. */ - - emit_insns_after (insns, last_parm_cleanup_insn); - - end_protect_partials (); - - /* This is where the body of the constructor ends. */ - expand_label (ctor_label); - ctor_label = NULL_TREE; - - if (call_poplevel) - { - decls = getdecls (); - expand_end_bindings (decls, decls != NULL_TREE, 0); - poplevel (decls != NULL_TREE, 1, 0); - } - - /* c_expand_return knows to return 'this' from a constructor. */ - c_expand_return (NULL_TREE); - - current_function_assigns_this = 0; - current_function_just_assigned_this = 0; - } + else if (DECL_CONSTRUCTOR_P (fndecl) + && !DECL_VLIST_CTOR_WRAPPER_P (fndecl)) + finish_ctor (call_poplevel); else if (DECL_MAIN_P (fndecl)) { /* Make it so that `main' always returns 0 by default. */ #ifdef VMS c_expand_return (integer_one_node); #else c_expand_return (integer_zero_node); #endif } else if (return_label != NULL_RTX && current_function_return_value == NULL_TREE && ! DECL_NAME (DECL_RESULT (current_function_decl))) no_return_label = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE); if (flag_exceptions) expand_exception_blocks (); /* If this function is supposed to return a value, ensure that we do not fall into the cleanups by mistake. The end of our function will look like this: user code (may have return stmt somewhere) goto no_return_label cleanup_label: cleanups goto return_label no_return_label: NOTE_INSN_FUNCTION_END return_label: things for return If the user omits a return stmt in the USER CODE section, we will have a control path which reaches NOTE_INSN_FUNCTION_END. Otherwise, we won't. */ if (no_return_label) { DECL_CONTEXT (no_return_label) = fndecl; DECL_INITIAL (no_return_label) = error_mark_node; DECL_SOURCE_FILE (no_return_label) = input_filename; DECL_SOURCE_LINE (no_return_label) = lineno; expand_goto (no_return_label); } if (cleanup_label) { /* Remove the binding contour which is used to catch cleanup-generated temporaries. */ expand_end_bindings (0, 0, 0); poplevel (0, 0, 0); /* Emit label at beginning of cleanup code for parameters. */ emit_label (cleanup_label); } /* Get return value into register if that's where it's supposed to be. */ if (original_result_rtx) fixup_result_decl (DECL_RESULT (fndecl), original_result_rtx); /* Finish building code that will trigger warnings if users forget to make their functions return values. */ if (no_return_label || cleanup_label) emit_jump (return_label); if (no_return_label) { /* We don't need to call `expand_*_return' here because we don't need any cleanups here--this path of code is only for error checking purposes. */ expand_label (no_return_label); } /* Generate rtl for function exit. */ expand_function_end (input_filename, lineno, 1); } /* If we're processing a template, squirrel away the definition until we do an instantiation. */ if (processing_template_decl) { --minimal_parse_mode; DECL_SAVED_TREE (fndecl) = TREE_CHAIN (DECL_SAVED_TREE (fndecl)); /* We have to save this value here in case maybe_end_member_template_processing decides to pop all the template parameters. */ in_template = 1; } else in_template = 0; /* This must come after expand_function_end because cleanups might have declarations (from inline functions) that need to go into this function's blocks. */ if (current_binding_level->parm_flag != 1) my_friendly_abort (122); poplevel (1, 0, 1); /* If this is a in-class inline definition, we may have to pop the bindings for the template parameters that we added in maybe_begin_member_template_processing when start_function was called. */ if (inclass_inline) maybe_end_member_template_processing (); /* Reset scope for C++: if we were in the scope of a class, then when we finish this function, we are not longer so. This cannot be done until we know for sure that no more class members will ever be referenced in this function (i.e., calls to destructors). */ if (current_class_name) { ctype = current_class_type; pop_nested_class (); } /* Must mark the RESULT_DECL as being in this function. */ DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point to the FUNCTION_DECL node itself. */ BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; if (!in_template) { int saved_flag_keep_inline_functions = flag_keep_inline_functions; /* So we can tell if jump_optimize sets it to 1. */ can_reach_end = 0; if (DECL_CONTEXT (fndecl) != NULL_TREE && hack_decl_function_context (fndecl)) /* Trick rest_of_compilation into not deferring output of this function, even if it is inline, since the rtl_obstack for this function is the function_obstack of the enclosing function and will be deallocated when the enclosing function is gone. See save_tree_status. */ flag_keep_inline_functions = 1; /* Run the optimizers and output the assembler code for this function. */ if (DECL_ARTIFICIAL (fndecl)) { /* Do we really *want* to inline this synthesized method? */ int save_fif = flag_inline_functions; flag_inline_functions = 1; /* Turn off DECL_INLINE for the moment so function_cannot_inline_p will check our size. */ DECL_INLINE (fndecl) = 0; rest_of_compilation (fndecl); flag_inline_functions = save_fif; } else rest_of_compilation (fndecl); flag_keep_inline_functions = saved_flag_keep_inline_functions; if (DECL_SAVED_INSNS (fndecl) && ! TREE_ASM_WRITTEN (fndecl)) { /* Set DECL_EXTERNAL so that assemble_external will be called as necessary. We'll clear it again in finish_file. */ if (! DECL_EXTERNAL (fndecl)) DECL_NOT_REALLY_EXTERN (fndecl) = 1; DECL_EXTERNAL (fndecl) = 1; mark_inline_for_output (fndecl); } if (ctype && TREE_ASM_WRITTEN (fndecl)) note_debug_info_needed (ctype); current_function_returns_null |= can_reach_end; /* Since we don't normally go through c_expand_return for constructors, this normally gets the wrong value. Also, named return values have their return codes emitted after NOTE_INSN_FUNCTION_END, confusing jump.c. */ if (DECL_CONSTRUCTOR_P (fndecl) || DECL_NAME (DECL_RESULT (fndecl)) != NULL_TREE) current_function_returns_null = 0; if (TREE_THIS_VOLATILE (fndecl) && current_function_returns_null) cp_warning ("`noreturn' function `%D' does return", fndecl); else if ((warn_return_type || pedantic) && current_function_returns_null && TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE) { /* If this function returns non-void and control can drop through, complain. */ cp_warning ("control reaches end of non-void function `%D'", fndecl); } /* With just -W, complain only if function returns both with and without a value. */ else if (extra_warnings && current_function_returns_value && current_function_returns_null) warning ("this function may return with or without a value"); } --function_depth; /* Free all the tree nodes making up this function. */ /* Switch back to allocating nodes permanently until we start another function. */ if (! nested) permanent_allocation (1); if (DECL_SAVED_INSNS (fndecl) == NULL_RTX) { tree t; /* Stop pointing to the local nodes about to be freed. */ /* But DECL_INITIAL must remain nonzero so we know this was an actual function definition. */ DECL_INITIAL (fndecl) = error_mark_node; for (t = DECL_ARGUMENTS (fndecl); t; t = TREE_CHAIN (t)) DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX; } if (DECL_STATIC_CONSTRUCTOR (fndecl)) static_ctors = perm_tree_cons (NULL_TREE, fndecl, static_ctors); if (DECL_STATIC_DESTRUCTOR (fndecl)) static_dtors = perm_tree_cons (NULL_TREE, fndecl, static_dtors); if (! nested) { /* Let the error reporting routines know that we're outside a function. For a nested function, this value is used in pop_cp_function_context and then reset via pop_function_context. */ current_function_decl = NULL_TREE; } named_label_uses = NULL; current_class_ptr = NULL_TREE; current_class_ref = NULL_TREE; } /* Create the FUNCTION_DECL for a function definition. DECLSPECS and DECLARATOR are the parts of the declaration; they describe the return type and the name of the function, but twisted together in a fashion that parallels the syntax of C. This function creates a binding context for the function body as well as setting up the FUNCTION_DECL in current_function_decl. Returns a FUNCTION_DECL on success. If the DECLARATOR is not suitable for a function (it defines a datum instead), we return 0, which tells yyparse to report a parse error. May return void_type_node indicating that this method is actually a friend. See grokfield for more details. Came here with a `.pushlevel' . DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING CHANGES TO CODE IN `grokfield'. */ tree start_method (declspecs, declarator, attrlist) tree declarator, declspecs, attrlist; { tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, attrlist); /* Something too ugly to handle. */ if (fndecl == NULL_TREE) return NULL_TREE; /* Pass friends other than inline friend functions back. */ if (fndecl == void_type_node) return fndecl; if (TREE_CODE (fndecl) != FUNCTION_DECL) /* Not a function, tell parser to report parse error. */ return NULL_TREE; if (IS_SIGNATURE (current_class_type)) IS_DEFAULT_IMPLEMENTATION (fndecl) = 1; if (DECL_IN_AGGR_P (fndecl)) { if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (fndecl)) != current_class_type) { if (DECL_CONTEXT (fndecl) && TREE_CODE( DECL_CONTEXT (fndecl)) != NAMESPACE_DECL) cp_error ("`%D' is already defined in class %s", fndecl, TYPE_NAME_STRING (DECL_CONTEXT (fndecl))); } return void_type_node; } check_template_shadow (fndecl); DECL_THIS_INLINE (fndecl) = 1; if (flag_default_inline) DECL_INLINE (fndecl) = 1; /* We process method specializations in finish_struct_1. */ if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl)) fndecl = push_template_decl (fndecl); /* We read in the parameters on the maybepermanent_obstack, but we won't be getting back to them until after we may have clobbered them. So the call to preserve_data will keep them safe. */ preserve_data (); if (! DECL_FRIEND_P (fndecl)) { if (TREE_CHAIN (fndecl)) { fndecl = copy_node (fndecl); TREE_CHAIN (fndecl) = NULL_TREE; } if (DECL_CONSTRUCTOR_P (fndecl)) { if (! grok_ctor_properties (current_class_type, fndecl)) return void_type_node; } else if (IDENTIFIER_OPNAME_P (DECL_NAME (fndecl))) grok_op_properties (fndecl, DECL_VIRTUAL_P (fndecl), 0); } cp_finish_decl (fndecl, NULL_TREE, NULL_TREE, 0, 0); /* Make a place for the parms */ pushlevel (0); current_binding_level->parm_flag = 1; DECL_IN_AGGR_P (fndecl) = 1; return fndecl; } /* Go through the motions of finishing a function definition. We don't compile this method until after the whole class has been processed. FINISH_METHOD must return something that looks as though it came from GROKFIELD (since we are defining a method, after all). This is called after parsing the body of the function definition. STMTS is the chain of statements that makes up the function body. DECL is the ..._DECL that `start_method' provided. */ tree finish_method (decl) tree decl; { register tree fndecl = decl; tree old_initial; register tree link; if (decl == void_type_node) return decl; old_initial = DECL_INITIAL (fndecl); /* Undo the level for the parms (from start_method). This is like poplevel, but it causes nothing to be saved. Saving information here confuses symbol-table output routines. Besides, this information will be correctly output when this method is actually compiled. */ /* Clear out the meanings of the local variables of this level; also record in each decl which block it belongs to. */ for (link = current_binding_level->names; link; link = TREE_CHAIN (link)) { if (DECL_NAME (link) != NULL_TREE) pop_binding (DECL_NAME (link), link); my_friendly_assert (TREE_CODE (link) != FUNCTION_DECL, 163); DECL_CONTEXT (link) = NULL_TREE; } GNU_xref_end_scope ((HOST_WIDE_INT) current_binding_level, (HOST_WIDE_INT) current_binding_level->level_chain, current_binding_level->parm_flag, current_binding_level->keep); poplevel (0, 0, 0); DECL_INITIAL (fndecl) = old_initial; /* We used to check if the context of FNDECL was different from current_class_type as another way to get inside here. This didn't work for String.cc in libg++. */ if (DECL_FRIEND_P (fndecl)) { CLASSTYPE_INLINE_FRIENDS (current_class_type) = tree_cons (NULL_TREE, fndecl, CLASSTYPE_INLINE_FRIENDS (current_class_type)); decl = void_type_node; } return decl; } /* Called when a new struct TYPE is defined. If this structure or union completes the type of any previous variable declaration, lay it out and output its rtl. */ void hack_incomplete_structures (type) tree type; { tree *list; if (current_binding_level->incomplete == NULL_TREE) return; if (!type) /* Don't do this for class templates. */ return; for (list = ¤t_binding_level->incomplete; *list; ) { tree decl = TREE_VALUE (*list); if ((decl && TREE_TYPE (decl) == type) || (TREE_TYPE (decl) && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE && TREE_TYPE (TREE_TYPE (decl)) == type)) { int toplevel = toplevel_bindings_p (); if (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE && TREE_TYPE (TREE_TYPE (decl)) == type) layout_type (TREE_TYPE (decl)); layout_decl (decl, 0); rest_of_decl_compilation (decl, NULL_PTR, toplevel, 0); if (! toplevel) { tree cleanup; expand_decl (decl); cleanup = maybe_build_cleanup (decl); expand_decl_init (decl); if (! expand_decl_cleanup (decl, cleanup)) cp_error ("parser lost in parsing declaration of `%D'", decl); } *list = TREE_CHAIN (*list); } else list = &TREE_CHAIN (*list); } } /* If DECL is of a type which needs a cleanup, build that cleanup here. See build_delete for information about AUTO_DELETE. Don't build these on the momentary obstack; they must live the life of the binding contour. */ static tree maybe_build_cleanup_1 (decl, auto_delete) tree decl, auto_delete; { tree type = TREE_TYPE (decl); if (type != error_mark_node && TYPE_NEEDS_DESTRUCTOR (type)) { int temp = 0, flags = LOOKUP_NORMAL|LOOKUP_DESTRUCTOR; tree rval; if (TREE_CODE (decl) != PARM_DECL) temp = suspend_momentary (); if (TREE_CODE (type) == ARRAY_TYPE) rval = decl; else { mark_addressable (decl); rval = build_unary_op (ADDR_EXPR, decl, 0); } /* Optimize for space over speed here. */ if (! TYPE_USES_VIRTUAL_BASECLASSES (type) || flag_expensive_optimizations) flags |= LOOKUP_NONVIRTUAL; rval = build_delete (TREE_TYPE (rval), rval, auto_delete, flags, 0); if (TYPE_USES_VIRTUAL_BASECLASSES (type) && ! TYPE_HAS_DESTRUCTOR (type)) rval = build_compound_expr (expr_tree_cons (NULL_TREE, rval, build_expr_list (NULL_TREE, build_vbase_delete (type, decl)))); if (TREE_CODE (decl) != PARM_DECL) resume_momentary (temp); return rval; } return 0; } /* If DECL is of a type which needs a cleanup, build that cleanup here. The cleanup does free the storage with a call to delete. */ tree maybe_build_cleanup_and_delete (decl) tree decl; { return maybe_build_cleanup_1 (decl, integer_three_node); } /* If DECL is of a type which needs a cleanup, build that cleanup here. The cleanup does not free the storage with a call a delete. */ tree maybe_build_cleanup (decl) tree decl; { return maybe_build_cleanup_1 (decl, integer_two_node); } /* Expand a C++ expression at the statement level. This is needed to ferret out nodes which have UNKNOWN_TYPE. The C++ type checker should get all of these out when expressions are combined with other, type-providing, expressions, leaving only orphan expressions, such as: &class::bar; / / takes its address, but does nothing with it. */ void cplus_expand_expr_stmt (exp) tree exp; { if (processing_template_decl) { add_tree (build_min_nt (EXPR_STMT, exp)); return; } /* Arrange for all temps to disappear. */ expand_start_target_temps (); exp = require_complete_type_in_void (exp); if (TREE_CODE (exp) == FUNCTION_DECL) { cp_warning ("reference, not call, to function `%D'", exp); warning ("at this point in file"); } #if 0 /* We should do this eventually, but right now this causes regex.o from libg++ to miscompile, and tString to core dump. */ exp = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (exp), exp); #endif /* Strip unused implicit INDIRECT_REFs of references. */ if (TREE_CODE (exp) == INDIRECT_REF && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == REFERENCE_TYPE) exp = TREE_OPERAND (exp, 0); /* If we don't do this, we end up down inside expand_expr trying to do TYPE_MODE on the ERROR_MARK, and really go outside the bounds of the type. */ if (exp != error_mark_node) expand_expr_stmt (break_out_cleanups (exp)); /* Clean up any pending cleanups. This happens when a function call returns a cleanup-needing value that nobody uses. */ expand_end_target_temps (); } /* When a stmt has been parsed, this function is called. Currently, this function only does something within a constructor's scope: if a stmt has just assigned to this, and we are in a derived class, we call `emit_base_init'. */ void finish_stmt () { extern struct nesting *cond_stack, *loop_stack, *case_stack; if (current_function_assigns_this || ! current_function_just_assigned_this) return; if (DECL_CONSTRUCTOR_P (current_function_decl)) { /* Constructors must wait until we are out of control zones before calling base constructors. */ if (cond_stack || loop_stack || case_stack) return; expand_expr_stmt (base_init_expr); check_base_init (current_class_type); } current_function_assigns_this = 1; } /* Change a static member function definition into a FUNCTION_TYPE, instead of the METHOD_TYPE that we create when it's originally parsed. WARNING: DO NOT pass &TREE_TYPE (decl) to FN or &TYPE_ARG_TYPES (TREE_TYPE (decl)) to ARGTYPES, as doing so will corrupt the types of other decls. Either pass the addresses of local variables or NULL. */ void revert_static_member_fn (decl, fn, argtypes) tree *decl, *fn, *argtypes; { tree tmp; tree function = fn ? *fn : TREE_TYPE (*decl); tree args = argtypes ? *argtypes : TYPE_ARG_TYPES (function); if (CP_TYPE_QUALS (TREE_TYPE (TREE_VALUE (args))) != TYPE_UNQUALIFIED) cp_error ("static member function `%#D' declared with type qualifiers", *decl); args = TREE_CHAIN (args); tmp = build_function_type (TREE_TYPE (function), args); tmp = build_qualified_type (tmp, CP_TYPE_QUALS (function)); tmp = build_exception_variant (tmp, TYPE_RAISES_EXCEPTIONS (function)); TREE_TYPE (*decl) = tmp; if (DECL_ARGUMENTS (*decl)) DECL_ARGUMENTS (*decl) = TREE_CHAIN (DECL_ARGUMENTS (*decl)); DECL_STATIC_FUNCTION_P (*decl) = 1; if (fn) *fn = tmp; if (argtypes) *argtypes = args; } struct cp_function { int returns_value; int returns_null; int assigns_this; int just_assigned_this; int parms_stored; int temp_name_counter; tree named_labels; struct named_label_list *named_label_uses; tree shadowed_labels; tree ctor_label; tree dtor_label; rtx last_dtor_insn; rtx last_parm_cleanup_insn; tree base_init_list; tree member_init_list; tree base_init_expr; tree current_class_ptr; tree current_class_ref; rtx result_rtx; struct cp_function *next; struct binding_level *binding_level; int static_labelno; }; static struct cp_function *cp_function_chain; extern int temp_name_counter; /* Save and reinitialize the variables used during compilation of a C++ function. */ void push_cp_function_context (context) tree context; { struct cp_function *p = (struct cp_function *) xmalloc (sizeof (struct cp_function)); push_function_context_to (context); p->next = cp_function_chain; cp_function_chain = p; p->named_labels = named_labels; p->named_label_uses = named_label_uses; p->shadowed_labels = shadowed_labels; p->returns_value = current_function_returns_value; p->returns_null = current_function_returns_null; p->binding_level = current_binding_level; p->ctor_label = ctor_label; p->dtor_label = dtor_label; p->last_dtor_insn = last_dtor_insn; p->last_parm_cleanup_insn = last_parm_cleanup_insn; p->assigns_this = current_function_assigns_this; p->just_assigned_this = current_function_just_assigned_this; p->parms_stored = current_function_parms_stored; p->result_rtx = original_result_rtx; p->base_init_expr = base_init_expr; p->temp_name_counter = temp_name_counter; p->base_init_list = current_base_init_list; p->member_init_list = current_member_init_list; p->current_class_ptr = current_class_ptr; p->current_class_ref = current_class_ref; p->static_labelno = static_labelno; } /* Restore the variables used during compilation of a C++ function. */ void pop_cp_function_context (context) tree context; { struct cp_function *p = cp_function_chain; tree link; /* Bring back all the labels that were shadowed. */ for (link = shadowed_labels; link; link = TREE_CHAIN (link)) if (DECL_NAME (TREE_VALUE (link)) != 0) SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)), TREE_VALUE (link)); pop_function_context_from (context); cp_function_chain = p->next; named_labels = p->named_labels; named_label_uses = p->named_label_uses; shadowed_labels = p->shadowed_labels; current_function_returns_value = p->returns_value; current_function_returns_null = p->returns_null; current_binding_level = p->binding_level; ctor_label = p->ctor_label; dtor_label = p->dtor_label; last_dtor_insn = p->last_dtor_insn; last_parm_cleanup_insn = p->last_parm_cleanup_insn; current_function_assigns_this = p->assigns_this; current_function_just_assigned_this = p->just_assigned_this; current_function_parms_stored = p->parms_stored; original_result_rtx = p->result_rtx; base_init_expr = p->base_init_expr; temp_name_counter = p->temp_name_counter; current_base_init_list = p->base_init_list; current_member_init_list = p->member_init_list; current_class_ptr = p->current_class_ptr; current_class_ref = p->current_class_ref; static_labelno = p->static_labelno; free (p); } int in_function_p () { return function_depth != 0; } Index: head/contrib/gcc/cp/gxxint.texi =================================================================== --- head/contrib/gcc/cp/gxxint.texi (revision 60969) +++ head/contrib/gcc/cp/gxxint.texi (revision 60970) @@ -1,1849 +1,2076 @@ \input texinfo @c -*-texinfo-*- @c %** $FreeBSD$ @c %**start of header @setfilename g++int.info @settitle G++ internals @setchapternewpage odd @c %**end of header @node Top, Limitations of g++, (dir), (dir) @chapter Internal Architecture of the Compiler This is meant to describe the C++ front-end for gcc in detail. Questions and comments to Benjamin Kosnik @code{}. @menu * Limitations of g++:: * Routines:: * Implementation Specifics:: * Glossary:: * Macros:: * Typical Behavior:: * Coding Conventions:: * Templates:: * Access Control:: * Error Reporting:: * Parser:: * Exception Handling:: * Free Store:: * Mangling:: Function name mangling for C++ and Java +* Vtables:: Two ways to do virtual functions * Concept Index:: @end menu @node Limitations of g++, Routines, Top, Top @section Limitations of g++ @itemize @bullet @item Limitations on input source code: 240 nesting levels with the parser stacksize (YYSTACKSIZE) set to 500 (the default), and requires around 16.4k swap space per nesting level. The parser needs about 2.09 * number of nesting levels worth of stackspace. @cindex pushdecl_class_level @item I suspect there are other uses of pushdecl_class_level that do not call set_identifier_type_value in tandem with the call to pushdecl_class_level. It would seem to be an omission. @cindex access checking @item Access checking is unimplemented for nested types. @cindex @code{volatile} @item @code{volatile} is not implemented in general. @end itemize @node Routines, Implementation Specifics, Limitations of g++, Top @section Routines This section describes some of the routines used in the C++ front-end. @code{build_vtable} and @code{prepare_fresh_vtable} is used only within the @file{cp-class.c} file, and only in @code{finish_struct} and @code{modify_vtable_entries}. @code{build_vtable}, @code{prepare_fresh_vtable}, and @code{finish_struct} are the only routines that set @code{DECL_VPARENT}. @code{finish_struct} can steal the virtual function table from parents, this prohibits related_vslot from working. When finish_struct steals, we know that @example get_binfo (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (t)), t, 0) @end example @noindent will get the related binfo. @code{layout_basetypes} does something with the VIRTUALS. Supposedly (according to Tiemann) most of the breadth first searching done, like in @code{get_base_distance} and in @code{get_binfo} was not because of any design decision. I have since found out the at least one part of the compiler needs the notion of depth first binfo searching, I am going to try and convert the whole thing, it should just work. The term left-most refers to the depth first left-most node. It uses @code{MAIN_VARIANT == type} as the condition to get left-most, because the things that have @code{BINFO_OFFSET}s of zero are shared and will have themselves as their own @code{MAIN_VARIANT}s. The non-shared right ones, are copies of the left-most one, hence if it is its own @code{MAIN_VARIANT}, we know it IS a left-most one, if it is not, it is a non-left-most one. @code{get_base_distance}'s path and distance matters in its use in: @itemize @bullet @item @code{prepare_fresh_vtable} (the code is probably wrong) @item @code{init_vfields} Depends upon distance probably in a safe way, build_offset_ref might use partial paths to do further lookups, hack_identifier is probably not properly checking access. @item @code{get_first_matching_virtual} probably should check for @code{get_base_distance} returning -2. @item @code{resolve_offset_ref} should be called in a more deterministic manner. Right now, it is called in some random contexts, like for arguments at @code{build_method_call} time, @code{default_conversion} time, @code{convert_arguments} time, @code{build_unary_op} time, @code{build_c_cast} time, @code{build_modify_expr} time, @code{convert_for_assignment} time, and @code{convert_for_initialization} time. But, there are still more contexts it needs to be called in, one was the ever simple: @example if (obj.*pmi != 7) @dots{} @end example Seems that the problems were due to the fact that @code{TREE_TYPE} of the @code{OFFSET_REF} was not a @code{OFFSET_TYPE}, but rather the type of the referent (like @code{INTEGER_TYPE}). This problem was fixed by changing @code{default_conversion} to check @code{TREE_CODE (x)}, instead of only checking @code{TREE_CODE (TREE_TYPE (x))} to see if it was @code{OFFSET_TYPE}. @end itemize @node Implementation Specifics, Glossary, Routines, Top @section Implementation Specifics @itemize @bullet @item Explicit Initialization The global list @code{current_member_init_list} contains the list of mem-initializers specified in a constructor declaration. For example: @example foo::foo() : a(1), b(2) @{@} @end example @noindent will initialize @samp{a} with 1 and @samp{b} with 2. @code{expand_member_init} places each initialization (a with 1) on the global list. Then, when the fndecl is being processed, @code{emit_base_init} runs down the list, initializing them. It used to be the case that g++ first ran down @code{current_member_init_list}, then ran down the list of members initializing the ones that weren't explicitly initialized. Things were rewritten to perform the initializations in order of declaration in the class. So, for the above example, @samp{a} and @samp{b} will be initialized in the order that they were declared: @example class foo @{ public: int b; int a; foo (); @}; @end example @noindent Thus, @samp{b} will be initialized with 2 first, then @samp{a} will be initialized with 1, regardless of how they're listed in the mem-initializer. @item The Explicit Keyword The use of @code{explicit} on a constructor is used by @code{grokdeclarator} to set the field @code{DECL_NONCONVERTING_P}. That value is used by @code{build_method_call} and @code{build_user_type_conversion_1} to decide if a particular constructor should be used as a candidate for conversions. @end itemize @node Glossary, Macros, Implementation Specifics, Top @section Glossary @table @r @item binfo The main data structure in the compiler used to represent the inheritance relationships between classes. The data in the binfo can be accessed by the BINFO_ accessor macros. @item vtable @itemx virtual function table The virtual function table holds information used in virtual function dispatching. In the compiler, they are usually referred to as vtables, or vtbls. The first index is not used in the normal way, I believe it -is probably used for the virtual destructor. +is probably used for the virtual destructor. There are two forms of +virtual tables, one that has offsets in addition to pointers, and one +using thunks. @xref{Vtables}. @item vfield vfields can be thought of as the base information needed to build vtables. For every vtable that exists for a class, there is a vfield. See also vtable and virtual function table pointer. When a type is used as a base class to another type, the virtual function table for the derived class can be based upon the vtable for the base class, just extended to include the additional virtual methods declared in the derived class. The virtual function table from a virtual base class is never reused in a derived class. @code{is_normal} depends upon this. @item virtual function table pointer These are @code{FIELD_DECL}s that are pointer types that point to vtables. See also vtable and vfield. @end table @node Macros, Typical Behavior, Glossary, Top @section Macros This section describes some of the macros used on trees. The list should be alphabetical. Eventually all macros should be documented here. @table @code @item BINFO_BASETYPES A vector of additional binfos for the types inherited by this basetype. The binfos are fully unshared (except for virtual bases, in which case the binfo structure is shared). If this basetype describes type D as inherited in C, and if the basetypes of D are E anf F, then this vector contains binfos for inheritance of E and F by C. Has values of: TREE_VECs @item BINFO_INHERITANCE_CHAIN Temporarily used to represent specific inheritances. It usually points to the binfo associated with the lesser derived type, but it can be reversed by reverse_path. For example: @example Z ZbY least derived | Y YbX | X Xb most derived TYPE_BINFO (X) == Xb BINFO_INHERITANCE_CHAIN (Xb) == YbX BINFO_INHERITANCE_CHAIN (Yb) == ZbY BINFO_INHERITANCE_CHAIN (Zb) == 0 @end example Not sure is the above is really true, get_base_distance has is point towards the most derived type, opposite from above. Set by build_vbase_path, recursive_bounded_basetype_p, get_base_distance, lookup_field, lookup_fnfields, and reverse_path. What things can this be used on: TREE_VECs that are binfos @item BINFO_OFFSET The offset where this basetype appears in its containing type. BINFO_OFFSET slot holds the offset (in bytes) from the base of the complete object to the base of the part of the object that is allocated on behalf of this `type'. This is always 0 except when there is multiple inheritance. Used on TREE_VEC_ELTs of the binfos BINFO_BASETYPES (...) for example. @item BINFO_VIRTUALS A unique list of functions for the virtual function table. See also TYPE_BINFO_VIRTUALS. What things can this be used on: TREE_VECs that are binfos @item BINFO_VTABLE Used to find the VAR_DECL that is the virtual function table associated with this binfo. See also TYPE_BINFO_VTABLE. To get the virtual function table pointer, see CLASSTYPE_VFIELD. What things can this be used on: TREE_VECs that are binfos Has values of: VAR_DECLs that are virtual function tables @item BLOCK_SUPERCONTEXT In the outermost scope of each function, it points to the FUNCTION_DECL node. It aids in better DWARF support of inline functions. @item CLASSTYPE_TAGS CLASSTYPE_TAGS is a linked (via TREE_CHAIN) list of member classes of a class. TREE_PURPOSE is the name, TREE_VALUE is the type (pushclass scans these and calls pushtag on them.) finish_struct scans these to produce TYPE_DECLs to add to the TYPE_FIELDS of the type. It is expected that name found in the TREE_PURPOSE slot is unique, resolve_scope_to_name is one such place that depends upon this uniqueness. @item CLASSTYPE_METHOD_VEC The following is true after finish_struct has been called (on the class?) but not before. Before finish_struct is called, things are different to some extent. Contains a TREE_VEC of methods of the class. The TREE_VEC_LENGTH is the number of differently named methods plus one for the 0th entry. The 0th entry is always allocated, and reserved for ctors and dtors. If there are none, TREE_VEC_ELT(N,0) == NULL_TREE. Each entry of the TREE_VEC is a FUNCTION_DECL. For each FUNCTION_DECL, there is a DECL_CHAIN slot. If the FUNCTION_DECL is the last one with a given name, the DECL_CHAIN slot is NULL_TREE. Otherwise it is the next method that has the same name (but a different signature). It would seem that it is not true that because the DECL_CHAIN slot is used in this way, we cannot call pushdecl to put the method in the global scope (cause that would overwrite the TREE_CHAIN slot), because they use different _CHAINs. finish_struct_methods setups up one version of the TREE_CHAIN slots on the FUNCTION_DECLs. friends are kept in TREE_LISTs, so that there's no need to use their TREE_CHAIN slot for anything. Has values of: TREE_VECs @item CLASSTYPE_VFIELD Seems to be in the process of being renamed TYPE_VFIELD. Use on types to get the main virtual function table pointer. To get the virtual function table use BINFO_VTABLE (TYPE_BINFO ()). Has values of: FIELD_DECLs that are virtual function table pointers What things can this be used on: RECORD_TYPEs @item DECL_CLASS_CONTEXT Identifies the context that the _DECL was found in. For virtual function tables, it points to the type associated with the virtual function table. See also DECL_CONTEXT, DECL_FIELD_CONTEXT and DECL_FCONTEXT. The difference between this and DECL_CONTEXT, is that for virtuals functions like: @example struct A @{ virtual int f (); @}; struct B : A @{ int f (); @}; DECL_CONTEXT (A::f) == A DECL_CLASS_CONTEXT (A::f) == A DECL_CONTEXT (B::f) == A DECL_CLASS_CONTEXT (B::f) == B @end example Has values of: RECORD_TYPEs, or UNION_TYPEs What things can this be used on: TYPE_DECLs, _DECLs @item DECL_CONTEXT Identifies the context that the _DECL was found in. Can be used on virtual function tables to find the type associated with the virtual function table, but since they are FIELD_DECLs, DECL_FIELD_CONTEXT is a better access method. Internally the same as DECL_FIELD_CONTEXT, so don't us both. See also DECL_FIELD_CONTEXT, DECL_FCONTEXT and DECL_CLASS_CONTEXT. Has values of: RECORD_TYPEs What things can this be used on: @display VAR_DECLs that are virtual function tables _DECLs @end display @item DECL_FIELD_CONTEXT Identifies the context that the FIELD_DECL was found in. Internally the same as DECL_CONTEXT, so don't us both. See also DECL_CONTEXT, DECL_FCONTEXT and DECL_CLASS_CONTEXT. Has values of: RECORD_TYPEs What things can this be used on: @display FIELD_DECLs that are virtual function pointers FIELD_DECLs @end display @item DECL_NAME Has values of: @display 0 for things that don't have names IDENTIFIER_NODEs for TYPE_DECLs @end display @item DECL_IGNORED_P A bit that can be set to inform the debug information output routines in the back-end that a certain _DECL node should be totally ignored. Used in cases where it is known that the debugging information will be output in another file, or where a sub-type is known not to be needed because the enclosing type is not needed. A compiler constructed virtual destructor in derived classes that do not define an explicit destructor that was defined explicit in a base class has this bit set as well. Also used on __FUNCTION__ and __PRETTY_FUNCTION__ to mark they are ``compiler generated.'' c-decl and c-lex.c both want DECL_IGNORED_P set for ``internally generated vars,'' and ``user-invisible variable.'' Functions built by the C++ front-end such as default destructors, virtual destructors and default constructors want to be marked that they are compiler generated, but unsure why. Currently, it is used in an absolute way in the C++ front-end, as an optimization, to tell the debug information output routines to not generate debugging information that will be output by another separately compiled file. @item DECL_VIRTUAL_P A flag used on FIELD_DECLs and VAR_DECLs. (Documentation in tree.h is wrong.) Used in VAR_DECLs to indicate that the variable is a vtable. It is also used in FIELD_DECLs for vtable pointers. What things can this be used on: FIELD_DECLs and VAR_DECLs @item DECL_VPARENT Used to point to the parent type of the vtable if there is one, else it is just the type associated with the vtable. Because of the sharing of virtual function tables that goes on, this slot is not very useful, and is in fact, not used in the compiler at all. It can be removed. What things can this be used on: VAR_DECLs that are virtual function tables Has values of: RECORD_TYPEs maybe UNION_TYPEs @item DECL_FCONTEXT Used to find the first baseclass in which this FIELD_DECL is defined. See also DECL_CONTEXT, DECL_FIELD_CONTEXT and DECL_CLASS_CONTEXT. How it is used: Used when writing out debugging information about vfield and vbase decls. What things can this be used on: FIELD_DECLs that are virtual function pointers FIELD_DECLs @item DECL_REFERENCE_SLOT Used to hold the initialize for the reference. What things can this be used on: PARM_DECLs and VAR_DECLs that have a reference type @item DECL_VINDEX Used for FUNCTION_DECLs in two different ways. Before the structure containing the FUNCTION_DECL is laid out, DECL_VINDEX may point to a FUNCTION_DECL in a base class which is the FUNCTION_DECL which this FUNCTION_DECL will replace as a virtual function. When the class is laid out, this pointer is changed to an INTEGER_CST node which is suitable to find an index into the virtual function table. See get_vtable_entry as to how one can find the right index into the virtual function table. The first index 0, of a virtual function table it not used in the normal way, so the first real index is 1. DECL_VINDEX may be a TREE_LIST, that would seem to be a list of overridden FUNCTION_DECLs. add_virtual_function has code to deal with this when it uses the variable base_fndecl_list, but it would seem that somehow, it is possible for the TREE_LIST to pursist until method_call, and it should not. What things can this be used on: FUNCTION_DECLs @item DECL_SOURCE_FILE Identifies what source file a particular declaration was found in. Has values of: "" on TYPE_DECLs to mean the typedef is built in @item DECL_SOURCE_LINE Identifies what source line number in the source file the declaration was found at. Has values of: @display 0 for an undefined label 0 for TYPE_DECLs that are internally generated 0 for FUNCTION_DECLs for functions generated by the compiler (not yet, but should be) 0 for ``magic'' arguments to functions, that the user has no control over @end display @item TREE_USED Has values of: 0 for unused labels @item TREE_ADDRESSABLE A flag that is set for any type that has a constructor. @item TREE_COMPLEXITY They seem a kludge way to track recursion, poping, and pushing. They only appear in cp-decl.c and cp-decl2.c, so the are a good candidate for proper fixing, and removal. @item TREE_HAS_CONSTRUCTOR A flag to indicate when a CALL_EXPR represents a call to a constructor. If set, we know that the type of the object, is the complete type of the object, and that the value returned is nonnull. When used in this fashion, it is an optimization. Can also be used on SAVE_EXPRs to indicate when they are of fixed type and nonnull. Can also be used on INDIRECT_EXPRs on CALL_EXPRs that represent a call to a constructor. @item TREE_PRIVATE Set for FIELD_DECLs by finish_struct. But not uniformly set. The following routines do something with PRIVATE access: build_method_call, alter_access, finish_struct_methods, finish_struct, convert_to_aggr, CWriteLanguageDecl, CWriteLanguageType, CWriteUseObject, compute_access, lookup_field, dfs_pushdecl, GNU_xref_member, dbxout_type_fields, dbxout_type_method_1 @item TREE_PROTECTED The following routines do something with PROTECTED access: build_method_call, alter_access, finish_struct, convert_to_aggr, CWriteLanguageDecl, CWriteLanguageType, CWriteUseObject, compute_access, lookup_field, GNU_xref_member, dbxout_type_fields, dbxout_type_method_1 @item TYPE_BINFO Used to get the binfo for the type. Has values of: TREE_VECs that are binfos What things can this be used on: RECORD_TYPEs @item TYPE_BINFO_BASETYPES See also BINFO_BASETYPES. @item TYPE_BINFO_VIRTUALS A unique list of functions for the virtual function table. See also BINFO_VIRTUALS. What things can this be used on: RECORD_TYPEs @item TYPE_BINFO_VTABLE Points to the virtual function table associated with the given type. See also BINFO_VTABLE. What things can this be used on: RECORD_TYPEs Has values of: VAR_DECLs that are virtual function tables @item TYPE_NAME Names the type. Has values of: @display 0 for things that don't have names. should be IDENTIFIER_NODE for RECORD_TYPEs UNION_TYPEs and ENUM_TYPEs. TYPE_DECL for RECORD_TYPEs, UNION_TYPEs and ENUM_TYPEs, but shouldn't be. TYPE_DECL for typedefs, unsure why. @end display What things can one use this on: @display TYPE_DECLs RECORD_TYPEs UNION_TYPEs ENUM_TYPEs @end display History: It currently points to the TYPE_DECL for RECORD_TYPEs, UNION_TYPEs and ENUM_TYPEs, but it should be history soon. @item TYPE_METHODS Synonym for @code{CLASSTYPE_METHOD_VEC}. Chained together with @code{TREE_CHAIN}. @file{dbxout.c} uses this to get at the methods of a class. @item TYPE_DECL Used to represent typedefs, and used to represent bindings layers. Components: DECL_NAME is the name of the typedef. For example, foo would be found in the DECL_NAME slot when @code{typedef int foo;} is seen. DECL_SOURCE_LINE identifies what source line number in the source file the declaration was found at. A value of 0 indicates that this TYPE_DECL is just an internal binding layer marker, and does not correspond to a user supplied typedef. DECL_SOURCE_FILE @item TYPE_FIELDS A linked list (via @code{TREE_CHAIN}) of member types of a class. The list can contain @code{TYPE_DECL}s, but there can also be other things in the list apparently. See also @code{CLASSTYPE_TAGS}. @item TYPE_VIRTUAL_P A flag used on a @code{FIELD_DECL} or a @code{VAR_DECL}, indicates it is a virtual function table or a pointer to one. When used on a @code{FUNCTION_DECL}, indicates that it is a virtual function. When used on an @code{IDENTIFIER_NODE}, indicates that a function with this same name exists and has been declared virtual. When used on types, it indicates that the type has virtual functions, or is derived from one that does. Not sure if the above about virtual function tables is still true. See also info on @code{DECL_VIRTUAL_P}. What things can this be used on: FIELD_DECLs, VAR_DECLs, FUNCTION_DECLs, IDENTIFIER_NODEs @item VF_BASETYPE_VALUE Get the associated type from the binfo that caused the given vfield to exist. This is the least derived class (the most parent class) that needed a virtual function table. It is probably the case that all uses of this field are misguided, but they need to be examined on a case-by-case basis. See history for more information on why the previous statement was made. Set at @code{finish_base_struct} time. What things can this be used on: TREE_LISTs that are vfields History: This field was used to determine if a virtual function table's slot should be filled in with a certain virtual function, by checking to see if the type returned by VF_BASETYPE_VALUE was a parent of the context in which the old virtual function existed. This incorrectly assumes that a given type _could_ not appear as a parent twice in a given inheritance lattice. For single inheritance, this would in fact work, because a type could not possibly appear more than once in an inheritance lattice, but with multiple inheritance, a type can appear more than once. @item VF_BINFO_VALUE Identifies the binfo that caused this vfield to exist. If this vfield is from the first direct base class that has a virtual function table, then VF_BINFO_VALUE is NULL_TREE, otherwise it will be the binfo of the direct base where the vfield came from. Can use @code{TREE_VIA_VIRTUAL} on result to find out if it is a virtual base class. Related to the binfo found by @example get_binfo (VF_BASETYPE_VALUE (vfield), t, 0) @end example @noindent where @samp{t} is the type that has the given vfield. @example get_binfo (VF_BASETYPE_VALUE (vfield), t, 0) @end example @noindent will return the binfo for the given vfield. May or may not be set at @code{modify_vtable_entries} time. Set at @code{finish_base_struct} time. What things can this be used on: TREE_LISTs that are vfields @item VF_DERIVED_VALUE Identifies the type of the most derived class of the vfield, excluding the class this vfield is for. Set at @code{finish_base_struct} time. What things can this be used on: TREE_LISTs that are vfields @item VF_NORMAL_VALUE Identifies the type of the most derived class of the vfield, including the class this vfield is for. Set at @code{finish_base_struct} time. What things can this be used on: TREE_LISTs that are vfields @item WRITABLE_VTABLES This is a option that can be defined when building the compiler, that will cause the compiler to output vtables into the data segment so that the vtables maybe written. This is undefined by default, because normally the vtables should be unwritable. People that implement object I/O facilities may, or people that want to change the dynamic type of objects may want to have the vtables writable. Another way of achieving this would be to make a copy of the vtable into writable memory, but the drawback there is that that method only changes the type for one object. @end table @node Typical Behavior, Coding Conventions, Macros, Top @section Typical Behavior @cindex parse errors Whenever seemingly normal code fails with errors like @code{syntax error at `\@{'}, it's highly likely that grokdeclarator is returning a NULL_TREE for whatever reason. @node Coding Conventions, Templates, Typical Behavior, Top @section Coding Conventions It should never be that case that trees are modified in-place by the back-end, @emph{unless} it is guaranteed that the semantics are the same no matter how shared the tree structure is. @file{fold-const.c} still has some cases where this is not true, but rms hypothesizes that this will never be a problem. @node Templates, Access Control, Coding Conventions, Top @section Templates A template is represented by a @code{TEMPLATE_DECL}. The specific fields used are: @table @code @item DECL_TEMPLATE_RESULT The generic decl on which instantiations are based. This looks just like any other decl. @item DECL_TEMPLATE_PARMS The parameters to this template. @end table The generic decl is parsed as much like any other decl as possible, given the parameterization. The template decl is not built up until the generic decl has been completed. For template classes, a template decl is generated for each member function and static data member, as well. Template members of template classes are represented by a TEMPLATE_DECL for the class' parameters around another TEMPLATE_DECL for the member's parameters. All declarations that are instantiations or specializations of templates refer to their template and parameters through DECL_TEMPLATE_INFO. How should I handle parsing member functions with the proper param decls? Set them up again or try to use the same ones? Currently we do the former. We can probably do this without any extra machinery in store_pending_inline, by deducing the parameters from the decl in do_pending_inlines. PRE_PARSED_TEMPLATE_DECL? If a base is a parm, we can't check anything about it. If a base is not a parm, we need to check it for name binding. Do finish_base_struct if no bases are parameterized (only if none, including indirect, are parms). Nah, don't bother trying to do any of this until instantiation -- we only need to do name binding in advance. Always set up method vec and fields, inc. synthesized methods. Really? We can't know the types of the copy folks, or whether we need a destructor, or can have a default ctor, until we know our bases and fields. Otherwise, we can assume and fix ourselves later. Hopefully. @node Access Control, Error Reporting, Templates, Top @section Access Control The function compute_access returns one of three values: @table @code @item access_public means that the field can be accessed by the current lexical scope. @item access_protected means that the field cannot be accessed by the current lexical scope because it is protected. @item access_private means that the field cannot be accessed by the current lexical scope because it is private. @end table DECL_ACCESS is used for access declarations; alter_access creates a list of types and accesses for a given decl. Formerly, DECL_@{PUBLIC,PROTECTED,PRIVATE@} corresponded to the return codes of compute_access and were used as a cache for compute_access. Now they are not used at all. TREE_PROTECTED and TREE_PRIVATE are used to record the access levels granted by the containing class. BEWARE: TREE_PUBLIC means something completely unrelated to access control! @node Error Reporting, Parser, Access Control, Top @section Error Reporting The C++ front-end uses a call-back mechanism to allow functions to print out reasonable strings for types and functions without putting extra logic in the functions where errors are found. The interface is through the @code{cp_error} function (or @code{cp_warning}, etc.). The syntax is exactly like that of @code{error}, except that a few more conversions are supported: @itemize @bullet @item %C indicates a value of `enum tree_code'. @item %D indicates a *_DECL node. @item %E indicates a *_EXPR node. @item %L indicates a value of `enum languages'. @item %P indicates the name of a parameter (i.e. "this", "1", "2", ...) @item %T indicates a *_TYPE node. @item %O indicates the name of an operator (MODIFY_EXPR -> "operator ="). @end itemize There is some overlap between these; for instance, any of the node options can be used for printing an identifier (though only @code{%D} tries to decipher function names). For a more verbose message (@code{class foo} as opposed to just @code{foo}, including the return type for functions), use @code{%#c}. To have the line number on the error message indicate the line of the DECL, use @code{cp_error_at} and its ilk; to indicate which argument you want, use @code{%+D}, or it will default to the first. @node Parser, Exception Handling, Error Reporting, Top @section Parser Some comments on the parser: The @code{after_type_declarator} / @code{notype_declarator} hack is necessary in order to allow redeclarations of @code{TYPENAME}s, for instance @example typedef int foo; class A @{ char *foo; @}; @end example In the above, the first @code{foo} is parsed as a @code{notype_declarator}, and the second as a @code{after_type_declarator}. Ambiguities: There are currently four reduce/reduce ambiguities in the parser. They are: 1) Between @code{template_parm} and @code{named_class_head_sans_basetype}, for the tokens @code{aggr identifier}. This situation occurs in code looking like @example template class A @{ @}; @end example It is ambiguous whether @code{class T} should be parsed as the declaration of a template type parameter named @code{T} or an unnamed constant parameter of type @code{class T}. Section 14.6, paragraph 3 of the January '94 working paper states that the first interpretation is the correct one. This ambiguity results in two reduce/reduce conflicts. 2) Between @code{primary} and @code{type_id} for code like @samp{int()} in places where both can be accepted, such as the argument to @code{sizeof}. Section 8.1 of the pre-San Diego working paper specifies that these ambiguous constructs will be interpreted as @code{typename}s. This ambiguity results in six reduce/reduce conflicts between @samp{absdcl} and @samp{functional_cast}. 3) Between @code{functional_cast} and @code{complex_direct_notype_declarator}, for various token strings. This situation occurs in code looking like @example int (*a); @end example This code is ambiguous; it could be a declaration of the variable @samp{a} as a pointer to @samp{int}, or it could be a functional cast of @samp{*a} to @samp{int}. Section 6.8 specifies that the former interpretation is correct. This ambiguity results in 7 reduce/reduce conflicts. Another aspect of this ambiguity is code like 'int (x[2]);', which is resolved at the '[' and accounts for 6 reduce/reduce conflicts between @samp{direct_notype_declarator} and @samp{primary}/@samp{overqualified_id}. Finally, there are 4 r/r conflicts between @samp{expr_or_declarator} and @samp{primary} over code like 'int (a);', which could probably be resolved but would also probably be more trouble than it's worth. In all, this situation accounts for 17 conflicts. Ack! The second case above is responsible for the failure to parse 'LinppFile ppfile (String (argv[1]), &outs, argc, argv);' (from Rogue Wave Math.h++) as an object declaration, and must be fixed so that it does not resolve until later. 4) Indirectly between @code{after_type_declarator} and @code{parm}, for type names. This occurs in (as one example) code like @example typedef int foo, bar; class A @{ foo (bar); @}; @end example What is @code{bar} inside the class definition? We currently interpret it as a @code{parm}, as does Cfront, but IBM xlC interprets it as an @code{after_type_declarator}. I believe that xlC is correct, in light of 7.1p2, which says "The longest sequence of @i{decl-specifiers} that could possibly be a type name is taken as the @i{decl-specifier-seq} of a @i{declaration}." However, it seems clear that this rule must be violated in the case of constructors. This ambiguity accounts for 8 conflicts. Unlike the others, this ambiguity is not recognized by the Working Paper. @node Exception Handling, Free Store, Parser, Top @section Exception Handling Note, exception handling in g++ is still under development. This section describes the mapping of C++ exceptions in the C++ front-end, into the back-end exception handling framework. The basic mechanism of exception handling in the back-end is unwind-protect a la elisp. This is a general, robust, and language independent representation for exceptions. The C++ front-end exceptions are mapping into the unwind-protect semantics by the C++ front-end. The mapping is describe below. When -frtti is used, rtti is used to do exception object type checking, when it isn't used, the encoded name for the type of the object being thrown is used instead. All code that originates exceptions, even code that throws exceptions as a side effect, like dynamic casting, and all code that catches exceptions must be compiled with either -frtti, or -fno-rtti. It is not possible to mix rtti base exception handling objects with code that doesn't use rtti. The exceptions to this, are code that doesn't catch or throw exceptions, catch (...), and code that just rethrows an exception. Currently we use the normal mangling used in building functions names (int's are "i", const char * is PCc) to build the non-rtti base type descriptors for exception handling. These descriptors are just plain NULL terminated strings, and internally they are passed around as char *. In C++, all cleanups should be protected by exception regions. The region starts just after the reason why the cleanup is created has ended. For example, with an automatic variable, that has a constructor, it would be right after the constructor is run. The region ends just before the finalization is expanded. Since the backend may expand the cleanup multiple times along different paths, once for normal end of the region, once for non-local gotos, once for returns, etc, the backend must take special care to protect the finalization expansion, if the expansion is for any other reason than normal region end, and it is `inline' (it is inside the exception region). The backend can either choose to move them out of line, or it can created an exception region over the finalization to protect it, and in the handler associated with it, it would not run the finalization as it otherwise would have, but rather just rethrow to the outer handler, careful to skip the normal handler for the original region. In Ada, they will use the more runtime intensive approach of having fewer regions, but at the cost of additional work at run time, to keep a list of things that need cleanups. When a variable has finished construction, they add the cleanup to the list, when the come to the end of the lifetime of the variable, the run the list down. If the take a hit before the section finishes normally, they examine the list for actions to perform. I hope they add this logic into the back-end, as it would be nice to get that alternative approach in C++. On an rs6000, xlC stores exception objects on that stack, under the try block. When is unwinds down into a handler, the frame pointer is adjusted back to the normal value for the frame in which the handler resides, and the stack pointer is left unchanged from the time at which the object was thrown. This is so that there is always someplace for the exception object, and nothing can overwrite it, once we start throwing. The only bad part, is that the stack remains large. The below points out some things that work in g++'s exception handling. All completely constructed temps and local variables are cleaned up in all unwinded scopes. Completely constructed parts of partially constructed objects are cleaned up. This includes partially built arrays. Exception specifications are now handled. Thrown objects are now cleaned up all the time. We can now tell if we have an active exception being thrown or not (__eh_type != 0). We use this to call terminate if someone does a throw; without there being an active exception object. uncaught_exception () works. Exception handling should work right if you optimize. Exception handling should work with -fpic or -fPIC. The below points out some flaws in g++'s exception handling, as it now stands. Only exact type matching or reference matching of throw types works when -fno-rtti is used. Only works on a SPARC (like Suns) (both -mflat and -mno-flat models work), SPARClite, Hitachi SH, i386, arm, rs6000, PowerPC, Alpha, mips, VAX, m68k and z8k machines. SPARC v9 may not work. HPPA is mostly done, but throwing between a shared library and user code doesn't yet work. Some targets have support for data-driven unwinding. Partial support is in for all other machines, but a stack unwinder called __unwind_function has to be written, and added to libgcc2 for them. The new EH code doesn't rely upon the __unwind_function for C++ code, instead it creates per function unwinders right inside the function, unfortunately, on many platforms the definition of RETURN_ADDR_RTX in the tm.h file for the machine port is wrong. See below for details on __unwind_function. RTL_EXPRs for EH cond variables for && and || exprs should probably be wrapped in UNSAVE_EXPRs, and RTL_EXPRs tweaked so that they can be unsaved. We only do pointer conversions on exception matching a la 15.3 p2 case 3: `A handler with type T, const T, T&, or const T& is a match for a throw-expression with an object of type E if [3]T is a pointer type and E is a pointer type that can be converted to T by a standard pointer conversion (_conv.ptr_) not involving conversions to pointers to private or protected base classes.' when -frtti is given. We don't call delete on new expressions that die because the ctor threw an exception. See except/18 for a test case. 15.2 para 13: The exception being handled should be rethrown if control reaches the end of a handler of the function-try-block of a constructor or destructor, right now, it is not. 15.2 para 12: If a return statement appears in a handler of function-try-block of a constructor, the program is ill-formed, but this isn't diagnosed. 15.2 para 11: If the handlers of a function-try-block contain a jump into the body of a constructor or destructor, the program is ill-formed, but this isn't diagnosed. 15.2 para 9: Check that the fully constructed base classes and members of an object are destroyed before entering the handler of a function-try-block of a constructor or destructor for that object. build_exception_variant should sort the incoming list, so that it implements set compares, not exact list equality. Type smashing should smash exception specifications using set union. Thrown objects are usually allocated on the heap, in the usual way. If one runs out of heap space, throwing an object will probably never work. This could be relaxed some by passing an __in_chrg parameter to track who has control over the exception object. Thrown objects are not allocated on the heap when they are pointer to object types. We should extend it so that all small (<4*sizeof(void*)) objects are stored directly, instead of allocated on the heap. When the backend returns a value, it can create new exception regions that need protecting. The new region should rethrow the object in context of the last associated cleanup that ran to completion. The structure of the code that is generated for C++ exception handling code is shown below: @example Ln: throw value; copy value onto heap jump throw (Ln, id, address of copy of value on heap) try @{ +Lstart: the start of the main EH region |... ... +Lend: the end of the main EH region @} catch (T o) @{ ...1 @} Lresume: nop used to make sure there is something before the next region ends, if there is one ... ... jump Ldone [ Lmainhandler: handler for the region Lstart-Lend cleanup ] zero or more, depending upon automatic vars with dtors +Lpartial: | jump Lover +Lhere: rethrow (Lhere, same id, same obj); Lterm: handler for the region Lpartial-Lhere call terminate Lover: [ [ call throw_type_match if (eq) @{ ] these lines disappear when there is no catch condition +Lsregion2: | ...1 | jump Lresume |Lhandler: handler for the region Lsregion2-Leregion2 | rethrow (Lresume, same id, same obj); +Leregion2 @} ] there are zero or more of these sections, depending upon how many catch clauses there are ----------------------------- expand_end_all_catch -------------------------- here we have fallen off the end of all catch clauses, so we rethrow to outer rethrow (Lresume, same id, same obj); ----------------------------- expand_end_all_catch -------------------------- [ L1: maybe throw routine ] depending upon if we have expanded it or not Ldone: ret start_all_catch emits labels: Lresume, @end example The __unwind_function takes a pointer to the throw handler, and is expected to pop the stack frame that was built to call it, as well as the frame underneath and then jump to the throw handler. It must restore all registers to their proper values as well as all other machine state as determined by the context in which we are unwinding into. The way I normally start is to compile: void *g; foo(void* a) @{ g = a; @} with -S, and change the thing that alters the PC (return, or ret usually) to not alter the PC, making sure to leave all other semantics (like adjusting the stack pointer, or frame pointers) in. After that, replicate the prologue once more at the end, again, changing the PC altering instructions, and finally, at the very end, jump to `g'. It takes about a week to write this routine, if someone wants to volunteer to write this routine for any architecture, exception support for that architecture will be added to g++. Please send in those code donations. One other thing that needs to be done, is to double check that __builtin_return_address (0) works. @subsection Specific Targets For the alpha, the __unwind_function will be something resembling: @example void __unwind_function(void *ptr) @{ /* First frame */ asm ("ldq $15, 8($30)"); /* get the saved frame ptr; 15 is fp, 30 is sp */ asm ("bis $15, $15, $30"); /* reload sp with the fp we found */ /* Second frame */ asm ("ldq $15, 8($30)"); /* fp */ asm ("bis $15, $15, $30"); /* reload sp with the fp we found */ /* Return */ asm ("ret $31, ($16), 1"); /* return to PTR, stored in a0 */ @} @end example @noindent However, there are a few problems preventing it from working. First of all, the gcc-internal function @code{__builtin_return_address} needs to work given an argument of 0 for the alpha. As it stands as of August 30th, 1995, the code for @code{BUILT_IN_RETURN_ADDRESS} in @file{expr.c} will definitely not work on the alpha. Instead, we need to define the macros @code{DYNAMIC_CHAIN_ADDRESS} (maybe), @code{RETURN_ADDR_IN_PREVIOUS_FRAME}, and definitely need a new definition for @code{RETURN_ADDR_RTX}. In addition (and more importantly), we need a way to reliably find the frame pointer on the alpha. The use of the value 8 above to restore the frame pointer (register 15) is incorrect. On many systems, the frame pointer is consistently offset to a specific point on the stack. On the alpha, however, the frame pointer is pushed last. First the return address is stored, then any other registers are saved (e.g., @code{s0}), and finally the frame pointer is put in place. So @code{fp} could have an offset of 8, but if the calling function saved any registers at all, they add to the offset. The only places the frame size is noted are with the @samp{.frame} directive, for use by the debugger and the OSF exception handling model (useless to us), and in the initial computation of the new value for @code{sp}, the stack pointer. For example, the function may start with: @example lda $30,-32($30) .frame $15,32,$26,0 @end example @noindent The 32 above is exactly the value we need. With this, we can be sure that the frame pointer is stored 8 bytes less---in this case, at 24(sp)). The drawback is that there is no way that I (Brendan) have found to let us discover the size of a previous frame @emph{inside} the definition of @code{__unwind_function}. So to accomplish exception handling support on the alpha, we need two things: first, a way to figure out where the frame pointer was stored, and second, a functional @code{__builtin_return_address} implementation for except.c to be able to use it. Or just support DWARF 2 unwind info. @subsection New Backend Exception Support This subsection discusses various aspects of the design of the data-driven model being implemented for the exception handling backend. The goal is to generate enough data during the compilation of user code, such that we can dynamically unwind through functions at run time with a single routine (@code{__throw}) that lives in libgcc.a, built by the compiler, and dispatch into associated exception handlers. This information is generated by the DWARF 2 debugging backend, and includes all of the information __throw needs to unwind an arbitrary frame. It specifies where all of the saved registers and the return address can be found at any point in the function. Major disadvantages when enabling exceptions are: @itemize @bullet @item Code that uses caller saved registers, can't, when flow can be transferred into that code from an exception handler. In high performance code this should not usually be true, so the effects should be minimal. @end itemize @subsection Backend Exception Support The backend must be extended to fully support exceptions. Right now there are a few hooks into the alpha exception handling backend that resides in the C++ frontend from that backend that allows exception handling to work in g++. An exception region is a segment of generated code that has a handler associated with it. The exception regions are denoted in the generated code as address ranges denoted by a starting PC value and an ending PC value of the region. Some of the limitations with this scheme are: @itemize @bullet @item The backend replicates insns for such things as loop unrolling and function inlining. Right now, there are no hooks into the frontend's exception handling backend to handle the replication of insns. When replication happens, a new exception region descriptor needs to be generated for the new region. @item The backend expects to be able to rearrange code, for things like jump optimization. Any rearranging of the code needs have exception region descriptors updated appropriately. @item The backend can eliminate dead code. Any associated exception region descriptor that refers to fully contained code that has been eliminated should also be removed, although not doing this is harmless in terms of semantics. @end itemize The above is not meant to be exhaustive, but does include all things I have thought of so far. I am sure other limitations exist. Below are some notes on the migration of the exception handling code backend from the C++ frontend to the backend. NOTEs are to be used to denote the start of an exception region, and the end of the region. I presume that the interface used to generate these notes in the backend would be two functions, start_exception_region and end_exception_region (or something like that). The frontends are required to call them in pairs. When marking the end of a region, an argument can be passed to indicate the handler for the marked region. This can be passed in many ways, currently a tree is used. Another possibility would be insns for the handler, or a label that denotes a handler. I have a feeling insns might be the best way to pass it. Semantics are, if an exception is thrown inside the region, control is transferred unconditionally to the handler. If control passes through the handler, then the backend is to rethrow the exception, in the context of the end of the original region. The handler is protected by the conventional mechanisms; it is the frontend's responsibility to protect the handler, if special semantics are required. This is a very low level view, and it would be nice is the backend supported a somewhat higher level view in addition to this view. This higher level could include source line number, name of the source file, name of the language that threw the exception and possibly the name of the exception. Kenner may want to rope you into doing more than just the basics required by C++. You will have to resolve this. He may want you to do support for non-local gotos, first scan for exception handler, if none is found, allow the debugger to be entered, without any cleanups being done. To do this, the backend would have to know the difference between a cleanup-rethrower, and a real handler, if would also have to have a way to know if a handler `matches' a thrown exception, and this is frontend specific. The stack unwinder is one of the hardest parts to do. It is highly machine dependent. The form that kenner seems to like was a couple of macros, that would do the machine dependent grunt work. One preexisting function that might be of some use is __builtin_return_address (). One macro he seemed to want was __builtin_return_address, and the other would do the hard work of fixing up the registers, adjusting the stack pointer, frame pointer, arg pointer and so on. @node Free Store, Mangling, Exception Handling, Top @section Free Store @code{operator new []} adds a magic cookie to the beginning of arrays for which the number of elements will be needed by @code{operator delete []}. These are arrays of objects with destructors and arrays of objects that define @code{operator delete []} with the optional size_t argument. This cookie can be examined from a program as follows: @example typedef unsigned long size_t; extern "C" int printf (const char *, ...); size_t nelts (void *p) @{ struct cookie @{ size_t nelts __attribute__ ((aligned (sizeof (double)))); @}; cookie *cp = (cookie *)p; --cp; return cp->nelts; @} struct A @{ ~A() @{ @} @}; main() @{ A *ap = new A[3]; printf ("%ld\n", nelts (ap)); @} @end example @section Linkage The linkage code in g++ is horribly twisted in order to meet two design goals: 1) Avoid unnecessary emission of inlines and vtables. 2) Support pedantic assemblers like the one in AIX. To meet the first goal, we defer emission of inlines and vtables until the end of the translation unit, where we can decide whether or not they are needed, and how to emit them if they are. -@node Mangling, Concept Index, Free Store, Top +@node Mangling, Vtables, Free Store, Top @section Function name mangling for C++ and Java Both C++ and Jave provide overloaded function and methods, which are methods with the same types but different parameter lists. Selecting the correct version is done at compile time. Though the overloaded functions have the same name in the source code, they need to be translated into different assembler-level names, since typical assemblers and linkers cannot handle overloading. This process of encoding the parameter types with the method name into a unique name is called @dfn{name mangling}. The inverse process is called @dfn{demangling}. It is convenient that C++ and Java use compatible mangling schemes, since the makes life easier for tools such as gdb, and it eases integration between C++ and Java. Note there is also a standard "Jave Native Interface" (JNI) which implements a different calling convention, and uses a different mangling scheme. The JNI is a rather abstract ABI so Java can call methods written in C or C++; we are concerned here about a lower-level interface primarily intended for methods written in Java, but that can also be used for C++ (and less easily C). Note that on systems that follow BSD tradition, a C identifier @code{var} would get "mangled" into the assembler name @samp{_var}. On such systems, all other mangled names are also prefixed by a @samp{_} which is not shown in the following examples. @subsection Method name mangling C++ mangles a method by emitting the function name, followed by @code{__}, followed by encodings of any method qualifiers (such as @code{const}), followed by the mangling of the method's class, followed by the mangling of the parameters, in order. For example @code{Foo::bar(int, long) const} is mangled as @samp{bar__C3Fooil}. For a constructor, the method name is left out. That is @code{Foo::Foo(int, long) const} is mangled as @samp{__C3Fooil}. GNU Java does the same. @subsection Primitive types The C++ types @code{int}, @code{long}, @code{short}, @code{char}, and @code{long long} are mangled as @samp{i}, @samp{l}, @samp{s}, @samp{c}, and @samp{x}, respectively. The corresponding unsigned types have @samp{U} prefixed to the mangling. The type @code{signed char} is mangled @samp{Sc}. The C++ and Java floating-point types @code{float} and @code{double} are mangled as @samp{f} and @samp{d} respectively. The C++ @code{bool} type and the Java @code{boolean} type are mangled as @samp{b}. The C++ @code{wchar_t} and the Java @code{char} types are mangled as @samp{w}. The Java integral types @code{byte}, @code{short}, @code{int} and @code{long} are mangled as @samp{c}, @samp{s}, @samp{i}, and @samp{x}, respectively. C++ code that has included @code{javatypes.h} will mangle the typedefs @code{jbyte}, @code{jshort}, @code{jint} and @code{jlong} as respectively @samp{c}, @samp{s}, @samp{i}, and @samp{x}. (This has not been implemented yet.) @subsection Mangling of simple names A simple class, package, template, or namespace name is encoded as the number of characters in the name, followed by the actual characters. Thus the class @code{Foo} is encoded as @samp{3Foo}. If any of the characters in the name are not alphanumeric (i.e not one of the standard ASCII letters, digits, or '_'), or the initial character is a digit, then the name is mangled as a sequence of encoded Unicode letters. A Unicode encoding starts with a @samp{U} to indicate that Unicode escapes are used, followed by the number of bytes used by the Unicode encoding, followed by the bytes representing the encoding. ASSCI letters and non-initial digits are encoded without change. However, all other characters (including underscore and initial digits) are translated into a sequence starting with an underscore, followed by the big-endian 4-hex-digit lower-case encoding of the character. If a method name contains Unicode-escaped characters, the entire mangled method name is followed by a @samp{U}. For example, the method @code{X\u0319::M\u002B(int)} is encoded as @samp{M_002b__U6X_0319iU}. @subsection Pointer and reference types A C++ pointer type is mangled as @samp{P} followed by the mangling of the type pointed to. A C++ reference type as mangled as @samp{R} followed by the mangling of the type referenced. A Java object reference type is equivalent to a C++ pointer parameter, so we mangle such an parameter type as @samp{P} followed by the mangling of the class name. @subsection Squangled type compression Squangling (enabled with the @samp{-fsquangle} option), utilizes the @samp{B} code to indicate reuse of a previously seen type within an indentifier. Types are recognized in a left to right manner and given increasing values, which are appended to the code in the standard manner. Ie, multiple digit numbers are delimited by @samp{_} characters. A type is considered to be any non primitive type, regardless of whether its a parameter, template parameter, or entire template. Certain codes are considered modifiers of a type, and are not included as part of the type. These are the @samp{C}, @samp{V}, @samp{P}, @samp{A}, @samp{R}, @samp{U} and @samp{u} codes, denoting constant, volatile, pointer, array, reference, unsigned, and restrict. These codes may precede a @samp{B} type in order to make the required modifications to the type. For example: @example template class class1 @{ @}; template class class2 @{ @}; class class3 @{ @}; int f(class2 > a ,int b, const class1&c, class3 *d) @{ @} B0 -> class2 B1 -> class1 B2 -> class3 @end example Produces the mangled name @samp{f__FGt6class21Zt6class11Z6class3iRCB1PB2}. The int parameter is a basic type, and does not receive a B encoding... @subsection Qualified names Both C++ and Java allow a class to be lexically nested inside another class. C++ also supports namespaces (not yet implemented by G++). Java also supports packages. These are all mangled the same way: First the letter @samp{Q} indicates that we are emitting a qualified name. That is followed by the number of parts in the qualified name. If that number is 9 or less, it is emitted with no delimiters. Otherwise, an underscore is written before and after the count. Then follows each part of the qualified name, as described above. For example @code{Foo::\u0319::Bar} is encoded as @samp{Q33FooU5_03193Bar}. Squangling utilizes the the letter @samp{K} to indicate a remembered portion of a qualified name. As qualified names are processed for an identifier, the names are numbered and remembered in a manner similar to the @samp{B} type compression code. Names are recognized left to right, and given increasing values, which are appended to the code in the standard manner. ie, multiple digit numbers are delimited by @samp{_} characters. For example @example class Andrew @{ class WasHere @{ class AndHereToo @{ @}; @}; @}; f(Andrew&r1, Andrew::WasHere& r2, Andrew::WasHere::AndHereToo& r3) @{ @} K0 -> Andrew K1 -> Andrew::WasHere K2 -> Andrew::WasHere::AndHereToo @end example Function @samp{f()} would be mangled as : @samp{f__FR6AndrewRQ2K07WasHereRQ2K110AndHereToo} There are some occasions when either a @samp{B} or @samp{K} code could be chosen, preference is always given to the @samp{B} code. Ie, the example in the section on @samp{B} mangling could have used a @samp{K} code instead of @samp{B2}. @subsection Templates A class template instantiation is encoded as the letter @samp{t}, followed by the encoding of the template name, followed the number of template parameters, followed by encoding of the template parameters. If a template parameter is a type, it is written as a @samp{Z} followed by the encoding of the type. A function template specialization (either an instantiation or an explicit specialization) is encoded by an @samp{H} followed by the encoding of the template parameters, as described above, followed by an @samp{_}, the encoding of the argument types to the template function (not the specialization), another @samp{_}, and the return type. (Like the argument types, the return type is the return type of the function template, not the specialization.) Template parameters in the argument and return types are encoded by an @samp{X} for type parameters, or a @samp{Y} for constant parameters, an index indicating their position in the template parameter list declaration, and their template depth. @subsection Arrays C++ array types are mangled by emitting @samp{A}, followed by the length of the array, followed by an @samp{_}, followed by the mangling of the element type. Of course, normally array parameter types decay into a pointer types, so you don't see this. Java arrays are objects. A Java type @code{T[]} is mangled as if it were the C++ type @code{JArray}. For example @code{java.lang.String[]} is encoded as @samp{Pt6JArray1ZPQ34java4lang6String}. @subsection Static fields Both C++ and Java classes can have static fields. These are allocated statically, and are shared among all instances. The mangling starts with a prefix (@samp{_} in most systems), which is followed by the mangling of the class name, followed by the "joiner" and finally the field name. The joiner (see @code{JOINER} in @code{cp-tree.h}) is a special separator character. For historical reasons (and idiosyncracies of assembler syntax) it can @samp{$} or @samp{.} (or even @samp{_} on a few systems). If the joiner is @samp{_} then the prefix is @samp{__static_} instead of just @samp{_}. For example @code{Foo::Bar::var} (or @code{Foo.Bar.var} in Java syntax) would be encoded as @samp{_Q23Foo3Bar$var} or @samp{_Q23Foo3Bar.var} (or rarely @samp{__static_Q23Foo3Bar_var}). If the name of a static variable needs Unicode escapes, the Unicode indicator @samp{U} comes before the "joiner". This @code{\u1234Foo::var\u3445} becomes @code{_U8_1234FooU.var_3445}. @subsection Table of demangling code characters The following special characters are used in mangling: @table @samp @item A Indicates a C++ array type. @item b Encodes the C++ @code{bool} type, and the Java @code{boolean} type. @item B Used for squangling. Similar in concept to the 'T' non-squangled code. @item c Encodes the C++ @code{char} type, and the Java @code{byte} type. @item C A modifier to indicate a @code{const} type. Also used to indicate a @code{const} member function (in which cases it precedes the encoding of the method's class). @item d Encodes the C++ and Java @code{double} types. @item e Indicates extra unknown arguments @code{...}. @item E Indicates the opening parenthesis of an expression. @item f Encodes the C++ and Java @code{float} types. @item F Used to indicate a function type. @item H Used to indicate a template function. @item i Encodes the C++ and Java @code{int} types. @item I Encodes typedef names of the form @code{int@var{n}_t}, where @var{n} is a positive decimal number. The @samp{I} is followed by either two hexidecimal digits, which encode the value of @var{n}, or by an arbitrary number of hexidecimal digits between underscores. For example, @samp{I40} encodes the type @code{int64_t}, and @samp{I_200_} encodes the type @code{int512_t}. @item J Indicates a complex type. @item K Used by squangling to compress qualified names. @item l Encodes the C++ @code{long} type. @item n Immediate repeated type. Followed by the repeat count. @item N Repeated type. Followed by the repeat count of the repeated type, followed by the type index of the repeated type. Due to a bug in g++ 2.7.2, this is only generated if index is 0. Superceded by @samp{n} when squangling. @item P Indicates a pointer type. Followed by the type pointed to. @item Q Used to mangle qualified names, which arise from nested classes. Also used for namespaces. In Java used to mangle package-qualified names, and inner classes. @item r Encodes the GNU C++ @code{long double} type. @item R Indicates a reference type. Followed by the referenced type. @item s Encodes the C++ and java @code{short} types. @item S A modifier that indicates that the following integer type is signed. Only used with @code{char}. Also used as a modifier to indicate a static member function. @item t Indicates a template instantiation. @item T A back reference to a previously seen type. @item U A modifier that indicates that the following integer type is unsigned. Also used to indicate that the following class or namespace name is encoded using Unicode-mangling. @item u The @code{restrict} type qualifier. @item v Encodes the C++ and Java @code{void} types. @item V A modifier for a @code{volatile} type or method. @item w Encodes the C++ @code{wchar_t} type, and the Java @code{char} types. @item W Indicates the closing parenthesis of an expression. @item x Encodes the GNU C++ @code{long long} type, and the Java @code{long} type. @item X Encodes a template type parameter, when part of a function type. @item Y Encodes a template constant parameter, when part of a function type. @item Z Used for template type parameters. @end table The letters @samp{G}, @samp{M}, @samp{O}, and @samp{p} also seem to be used for obscure purposes ... -@node Concept Index, , Mangling, Top +@node Vtables, Concept Index, Mangling, Top +@section Virtual Tables + +In order to invoke virtual functions, GNU C++ uses virtual tables. Each +virtual function gets an index, and the table entry points to the +overridden function to call. Sometimes, and adjustment to the this +pointer has to be made before calling a virtual function: + +@example +struct A@{ + int i; + virtual void foo(); +@}; + +struct B@{ + int j; + virtual void bar(); +@}; + +struct C:A,B@{ + virtual void bar(); +@}; + +void C::bar() +@{ + i++; +@} + +int main() +@{ + C *c = new C; + B *b = c; + c->bar(); +@} +@end example + +Here, casting from @samp{c} to @samp{b} adds an offset. When @samp{bar} +is called, this offset needs to be subtracted, so that @samp{C::bar} can +properly access @samp{i}. One approach of achieving this is to use +@emph{thunks}, which are small half-functions put into the virtual +table. The modify the first argument (the @samp{this} pointer), and then +jump into the real function. + +The other (traditional) approach is to have an additional integer in the +virtual table which is added to this. This is an additional overhead +both at the function call, and in the size of virtual tables: In the +case of single inheritance (or for the first base class), these integers +will always be zero. + +@subsection Virtual Base Classes with Virtual Tables + +In case of virtual bases, the code is even more +complicated. Constructors and destructors need to know whether they are +"in charge" of the virtual bases, and an implicit integer +@samp{__in_chrg} for that purpose. + +@example +struct A@{ + int i; + virtual void bar(); + void call_bar()@{bar();@} +@}; + +struct B:virtual A@{ + B(); + int j; + virtual void bar(); +@}; + +B::B()@{ + call_bar(); +@} + +struct C@{ + int k; +@}; + +struct D:C,B@{ + int l; + virtual void bar(); +@}; + +@end example + +When constructing an instance of B, it will have the following layout: +@samp{vbase pointer to A}, @samp{j}, @samp{A virtual table}, @samp{i}. +On a 32-bit machine, downcasting from @samp{A*} to @samp{B*} would need +to subtract 8, which would be the thunk executed when calling +@samp{B::bar} inside @samp{call_bar}. + +When constructing an instance of D, it will have a different layout: +@samp{k}, @samp{vbase pointer to A}, @samp{j}, @samp{l}, @samp{A virtual +table}, @samp{i}. So, when downcasting from @samp{A*} to @samp{B*} in a +@samp{D} object, the offset would be @samp{12}. + +This means that during construction of the @samp{B} base of a @samp{D} +object, a virtual table is needed which has a @samp{-12} thunk to +@samp{B::bar}. This is @emph{only} needed during construction and +destruction, as the full object will use a @samp{-16} thunk to +@samp{D::bar}. + +In order to implement this, the compiler generates an implicit argument +(in addition to @code{__in_chrg}): the virtual list argument +@code{__vlist}. This is a list of virtual tables needed during +construction and destruction. The virtual pointers are ordered in the +way they are used during construction; the destructors will process the +array in reverse order. The ordering is as follows: +@itemize @bullet +@item +If the class is in charge, the vlist starts with virtual table pointers +for the virtual bases that have virtual bases themselves. Here, only +@emph{polymorphic} virtual bases (pvbases) are interesting: if a vbase +has no virtual functions, it doesn't have a virtual table. + +@item +Next, the vlist has virtual tables for the initialization of the +non-virtual bases. These bases are not in charge, so the layout is +recursive, but ignores virtual bases during recursion. + +@item +Next, there is a number of virtual tables for each virtual base. These +are sorted in the order in which virtual bases are constructed. Each +virtual base may have more than one @code{vfield}, and therefore require +more than one @code{vtable}. The order of vtables is the same as used +when initializing vfields of non-virtual bases in a constructor. +@end itemize + +The compiler emits a virtual table list in a variable mangled as +@code{__vl.classname}. + +Class with virtual bases, but without pvbases, only have the +@code{__in_chrg} argument to their ctors and dtors: they don't have any +vfields in the vbases to initialize. + +A further problem arises with virtual destructors: A destructor +typically has only the @code{__in_chrg} argument, which also indicates +whether the destructor should call @code{operator delete}. A dtor of a +class with pvbases has an additional argument. Unfortunately, a caller +of a virtual dtor might not know whether to pass that argument or not. +Therefore, the dtor processes the @code{__vlist} argument in an +automatic variable, which is initialized from the class' vlist if the +__in_chrg flag has a zero value in bit 2 (bit mask 4), or from the +argument @code{__vlist1} if bit 2 of the __in_chrg parameter is set to +one. + +@subsection Specification of non-thunked vtables + +In the traditional implementation of vtables, each slot contains three +fields: The offset to be added to the this pointer before invoking a +virtual function, an unused field that is always zero, and the pointer +to the virtual function. The first two fields are typically 16 bits +wide. The unused field is called `index'; it may be non-zero in +pointer-to-member-functions, which use the same layout. + +The virtual table then is an array of vtable slots. The first slot is +always the virtual type info function, the other slots are in the order +in which the virtual functions appear in the class declaration. + +If a class has base classes, it may inherit other bases' vfields. Each +class may have a primary vfield; the primary vfield of the derived class +is the primary vfield of the left-most non-virtual base class. If a +class inherits a primary vfield, any new virtual functions in the +derived class are appended to the virtual table of the primary +vfield. If there are new virtual functions in the derived class, and no +primary vfield is inherited, a new vfield is introduced which becomes +primary. The redefined virtual functions fill the vtable slots inherited +from the base; new virtual functions are put into the primary vtable in +the order of declaration. If no new virtual functions are introduced, no +primary vfield is allocated. + +In a base class that has pvbases, virtual tables are needed which are +used only in the constructor (see example above). At run-time, the +virtual tables of the base class are adjusted, to reflect the new offset +of the pvbase. The compiler knows statically what offset the pvbase has +for a complete object. At run-time, the offset of the pvbase can be +extracted from the vbase pointer, which is set in the constructor of the +complete object. These two offsets result in a delta, which is used to +adjust the deltas in the vtable (the adjustment might be different for +different vtable slots). To adjust the vtables, the compiler emits code +that creates a vtable on the stack. This vtable is initialized with the +vtable for the complete base type, and then adjusted. + +In order to call a virtual function, the compiler gets the offset field +from the vtable entry, and adds it to the this pointer. It then +indirectly calls the virtual function pointer, passing the adjusted this +pointer, and any arguments the virtual function may have. + +To implement dynamic casting, the dynamic_cast function needs typeinfos +for the complete type, and the pointer to the complete type. The +typeinfo pointer is obtained by calling the virtual typeinfo function +(which doesn't take a this parameter). The pointer to the complete +object is obtained by adding the offset of the virtual typeinfo vtable +slot, since this virtual function is always implemented in the complete +object. + +@subsection Specification of thunked vtables + +For vtable thunks, each slot only consists of a pointer to the virtual +function, which might be a thunk function. The first slot in the vtable +is an offset of the this pointer to the complete object, which is needed +as a parameter to __dynamic_cast. The second slot is the virtual +typeinfo function. All other slots are allocated with the same procedure +as in the non-thunked case. Allocation of vfields also uses the same +procedure as described above. + +If the virtual function needs an adjusted this pointer, a thunk function +is emitted. If supported by the target architecture, this is only a +half-function. Such a thunk has no stack frame; it merely adjusts the +first argument of the function, and then directly branches into the +implementation of the virtual function. If the architecture does not +support half-functions (i.e. if ASM_OUTPUT_MI_THUNK is not defined), the +compiler emits a wrapper function, which copies all arguments, adjust +the this pointer, and then calls the original function. Since objects of +non-aggregate type are passed by invisible reference, this copies only +POD arguments. The approach fails for virtual functions with a variable +number of arguments. + +In order to support the vtables needed in base constructors with +pvbases, the compiler passes an implicit __vlist argument as described +above, if the version 2 thunks are used. For version 1 thunks, the base +class constructor will fill in the vtables for the complete base class, +which will incorrectly adjust the this pointer, leading to a dynamic +error. + +@node Concept Index, , Vtables, Top @section Concept Index @printindex cp @bye Index: head/contrib/gcc/function.c =================================================================== --- head/contrib/gcc/function.c (revision 60969) +++ head/contrib/gcc/function.c (revision 60970) @@ -1,6969 +1,7020 @@ /* Expands front end tree to back end RTL for GNU C-Compiler Copyright (C) 1987, 88, 89, 91-98, 1999 Free Software Foundation, Inc. This file is part of GNU CC. GNU CC 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 2, or (at your option) any later version. GNU CC 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 GNU CC; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* $FreeBSD$ */ /* This file handles the generation of rtl code from tree structure at the level of the function as a whole. It creates the rtl expressions for parameters and auto variables and has full responsibility for allocating stack slots. `expand_function_start' is called at the beginning of a function, before the function body is parsed, and `expand_function_end' is called after parsing the body. Call `assign_stack_local' to allocate a stack slot for a local variable. This is usually done during the RTL generation for the function body, but it can also be done in the reload pass when a pseudo-register does not get a hard register. Call `put_var_into_stack' when you learn, belatedly, that a variable previously given a pseudo-register must in fact go in the stack. This function changes the DECL_RTL to be a stack slot instead of a reg then scans all the RTL instructions so far generated to correct them. */ #include "config.h" #include "system.h" #include "rtl.h" #include "tree.h" #include "flags.h" #include "except.h" #include "function.h" #include "insn-flags.h" #include "expr.h" #include "insn-codes.h" #include "regs.h" #include "hard-reg-set.h" #include "insn-config.h" #include "recog.h" #include "output.h" #include "basic-block.h" #include "obstack.h" #include "toplev.h" #include "hash.h" #ifndef TRAMPOLINE_ALIGNMENT #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY #endif #ifndef LOCAL_ALIGNMENT #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT #endif /* Some systems use __main in a way incompatible with its use in gcc, in these cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to give the same symbol without quotes for an alternative entry point. You must define both, or neither. */ #ifndef NAME__MAIN #define NAME__MAIN "__main" #define SYMBOL__MAIN __main #endif /* Round a value to the lowest integer less than it that is a multiple of the required alignment. Avoid using division in case the value is negative. Assume the alignment is a power of two. */ #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1)) /* Similar, but round to the next highest integer that meets the alignment. */ #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1)) /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp during rtl generation. If they are different register numbers, this is always true. It may also be true if FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl generation. See fix_lexical_addr for details. */ #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM #define NEED_SEPARATE_AP #endif /* Number of bytes of args popped by function being compiled on its return. Zero if no bytes are to be popped. May affect compilation of return insn or of function epilogue. */ int current_function_pops_args; /* Nonzero if function being compiled needs to be given an address where the value should be stored. */ int current_function_returns_struct; /* Nonzero if function being compiled needs to return the address of where it has put a structure value. */ int current_function_returns_pcc_struct; /* Nonzero if function being compiled needs to be passed a static chain. */ int current_function_needs_context; /* Nonzero if function being compiled can call setjmp. */ int current_function_calls_setjmp; /* Nonzero if function being compiled can call longjmp. */ int current_function_calls_longjmp; /* Nonzero if function being compiled receives nonlocal gotos from nested functions. */ int current_function_has_nonlocal_label; /* Nonzero if function being compiled has nonlocal gotos to parent function. */ int current_function_has_nonlocal_goto; /* Nonzero if function being compiled contains nested functions. */ int current_function_contains_functions; /* Nonzero if function being compiled doesn't contain any calls (ignoring the prologue and epilogue). This is set prior to local register allocation and is valid for the remaining compiler passes. */ int current_function_is_leaf; /* Nonzero if function being compiled doesn't modify the stack pointer (ignoring the prologue and epilogue). This is only valid after life_analysis has run. */ int current_function_sp_is_unchanging; /* Nonzero if the function being compiled is a leaf function which only uses leaf registers. This is valid after reload (specifically after sched2) and is useful only if the port defines LEAF_REGISTERS. */ int current_function_uses_only_leaf_regs; /* Nonzero if the function being compiled issues a computed jump. */ int current_function_has_computed_jump; /* Nonzero if the current function is a thunk (a lightweight function that just adjusts one of its arguments and forwards to another function), so we should try to cut corners where we can. */ int current_function_is_thunk; /* Nonzero if function being compiled can call alloca, either as a subroutine or builtin. */ int current_function_calls_alloca; /* Nonzero if the current function returns a pointer type */ int current_function_returns_pointer; /* If some insns can be deferred to the delay slots of the epilogue, the delay list for them is recorded here. */ rtx current_function_epilogue_delay_list; /* If function's args have a fixed size, this is that size, in bytes. Otherwise, it is -1. May affect compilation of return insn or of function epilogue. */ int current_function_args_size; /* # bytes the prologue should push and pretend that the caller pushed them. The prologue must do this, but only if parms can be passed in registers. */ int current_function_pretend_args_size; /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is defined, the needed space is pushed by the prologue. */ int current_function_outgoing_args_size; /* This is the offset from the arg pointer to the place where the first anonymous arg can be found, if there is one. */ rtx current_function_arg_offset_rtx; /* Nonzero if current function uses varargs.h or equivalent. Zero for functions that use stdarg.h. */ int current_function_varargs; /* Nonzero if current function uses stdarg.h or equivalent. Zero for functions that use varargs.h. */ int current_function_stdarg; /* Quantities of various kinds of registers used for the current function's args. */ CUMULATIVE_ARGS current_function_args_info; /* Name of function now being compiled. */ char *current_function_name; /* If non-zero, an RTL expression for the location at which the current function returns its result. If the current function returns its result in a register, current_function_return_rtx will always be the hard register containing the result. */ rtx current_function_return_rtx; /* Nonzero if the current function uses the constant pool. */ int current_function_uses_const_pool; /* Nonzero if the current function uses pic_offset_table_rtx. */ int current_function_uses_pic_offset_table; /* The arg pointer hard register, or the pseudo into which it was copied. */ rtx current_function_internal_arg_pointer; /* Language-specific reason why the current function cannot be made inline. */ char *current_function_cannot_inline; /* Nonzero if instrumentation calls for function entry and exit should be generated. */ int current_function_instrument_entry_exit; /* Nonzero if memory access checking be enabled in the current function. */ int current_function_check_memory_usage; /* The FUNCTION_DECL for an inline function currently being expanded. */ tree inline_function_decl; /* Number of function calls seen so far in current function. */ int function_call_count; /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels (labels to which there can be nonlocal gotos from nested functions) in this function. */ tree nonlocal_labels; /* List (chain of EXPR_LIST) of stack slots that hold the current handlers for nonlocal gotos. There is one for every nonlocal label in the function; this list matches the one in nonlocal_labels. Zero when function does not have nonlocal labels. */ rtx nonlocal_goto_handler_slots; /* List (chain of EXPR_LIST) of labels heading the current handlers for nonlocal gotos. */ rtx nonlocal_goto_handler_labels; /* RTX for stack slot that holds the stack pointer value to restore for a nonlocal goto. Zero when function does not have nonlocal labels. */ rtx nonlocal_goto_stack_level; /* Label that will go on parm cleanup code, if any. Jumping to this label runs cleanup code for parameters, if such code must be run. Following this code is the logical return label. */ rtx cleanup_label; /* Label that will go on function epilogue. Jumping to this label serves as a "return" instruction on machines which require execution of the epilogue on all returns. */ rtx return_label; /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs. So we can mark them all live at the end of the function, if nonopt. */ rtx save_expr_regs; /* List (chain of EXPR_LISTs) of all stack slots in this function. Made for the sake of unshare_all_rtl. */ rtx stack_slot_list; /* Chain of all RTL_EXPRs that have insns in them. */ tree rtl_expr_chain; /* Label to jump back to for tail recursion, or 0 if we have not yet needed one for this function. */ rtx tail_recursion_label; /* Place after which to insert the tail_recursion_label if we need one. */ rtx tail_recursion_reentry; /* Location at which to save the argument pointer if it will need to be referenced. There are two cases where this is done: if nonlocal gotos exist, or if vars stored at an offset from the argument pointer will be needed by inner routines. */ rtx arg_pointer_save_area; /* Offset to end of allocated area of stack frame. If stack grows down, this is the address of the last stack slot allocated. If stack grows up, this is the address for the next slot. */ HOST_WIDE_INT frame_offset; /* List (chain of TREE_LISTs) of static chains for containing functions. Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx in an RTL_EXPR in the TREE_VALUE. */ static tree context_display; /* List (chain of TREE_LISTs) of trampolines for nested functions. The trampoline sets up the static chain and jumps to the function. We supply the trampoline's address when the function's address is requested. Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx in an RTL_EXPR in the TREE_VALUE. */ static tree trampoline_list; /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */ static rtx parm_birth_insn; #if 0 /* Nonzero if a stack slot has been generated whose address is not actually valid. It means that the generated rtl must all be scanned to detect and correct the invalid addresses where they occur. */ static int invalid_stack_slot; #endif /* Last insn of those whose job was to put parms into their nominal homes. */ static rtx last_parm_insn; /* 1 + last pseudo register number possibly used for loading a copy of a parameter of this function. */ int max_parm_reg; /* Vector indexed by REGNO, containing location on stack in which to put the parm which is nominally in pseudo register REGNO, if we discover that that parm must go in the stack. The highest element in this vector is one less than MAX_PARM_REG, above. */ rtx *parm_reg_stack_loc; /* Nonzero once virtual register instantiation has been done. assign_stack_local uses frame_pointer_rtx when this is nonzero. */ static int virtuals_instantiated; /* These variables hold pointers to functions to save and restore machine-specific data, in push_function_context and pop_function_context. */ void (*save_machine_status) PROTO((struct function *)); void (*restore_machine_status) PROTO((struct function *)); /* Nonzero if we need to distinguish between the return value of this function and the return value of a function called by this function. This helps integrate.c */ extern int rtx_equal_function_value_matters; extern tree sequence_rtl_expr; /* In order to evaluate some expressions, such as function calls returning structures in memory, we need to temporarily allocate stack locations. We record each allocated temporary in the following structure. Associated with each temporary slot is a nesting level. When we pop up one level, all temporaries associated with the previous level are freed. Normally, all temporaries are freed after the execution of the statement in which they were created. However, if we are inside a ({...}) grouping, the result may be in a temporary and hence must be preserved. If the result could be in a temporary, we preserve it if we can determine which one it is in. If we cannot determine which temporary may contain the result, all temporaries are preserved. A temporary is preserved by pretending it was allocated at the previous nesting level. Automatic variables are also assigned temporary slots, at the nesting level where they are defined. They are marked a "kept" so that free_temp_slots will not free them. */ struct temp_slot { /* Points to next temporary slot. */ struct temp_slot *next; /* The rtx to used to reference the slot. */ rtx slot; /* The rtx used to represent the address if not the address of the slot above. May be an EXPR_LIST if multiple addresses exist. */ rtx address; /* The alignment (in bits) of the slot. */ int align; /* The size, in units, of the slot. */ HOST_WIDE_INT size; /* The alias set for the slot. If the alias set is zero, we don't know anything about the alias set of the slot. We must only reuse a slot if it is assigned an object of the same alias set. Otherwise, the rest of the compiler may assume that the new use of the slot cannot alias the old use of the slot, which is false. If the slot has alias set zero, then we can't reuse the slot at all, since we have no idea what alias set may have been imposed on the memory. For example, if the stack slot is the call frame for an inline functioned, we have no idea what alias sets will be assigned to various pieces of the call frame. */ int alias_set; /* The value of `sequence_rtl_expr' when this temporary is allocated. */ tree rtl_expr; /* Non-zero if this temporary is currently in use. */ char in_use; /* Non-zero if this temporary has its address taken. */ char addr_taken; /* Nesting level at which this slot is being used. */ int level; /* Non-zero if this should survive a call to free_temp_slots. */ int keep; /* The offset of the slot from the frame_pointer, including extra space for alignment. This info is for combine_temp_slots. */ HOST_WIDE_INT base_offset; /* The size of the slot, including extra space for alignment. This info is for combine_temp_slots. */ HOST_WIDE_INT full_size; }; /* List of all temporaries allocated, both available and in use. */ struct temp_slot *temp_slots; /* Current nesting level for temporaries. */ int temp_slot_level; /* Current nesting level for variables in a block. */ int var_temp_slot_level; /* When temporaries are created by TARGET_EXPRs, they are created at this level of temp_slot_level, so that they can remain allocated until no longer needed. CLEANUP_POINT_EXPRs define the lifetime of TARGET_EXPRs. */ int target_temp_slot_level; /* This structure is used to record MEMs or pseudos used to replace VAR, any SUBREGs of VAR, and any MEMs containing VAR as an address. We need to maintain this list in case two operands of an insn were required to match; in that case we must ensure we use the same replacement. */ struct fixup_replacement { rtx old; rtx new; struct fixup_replacement *next; }; struct insns_for_mem_entry { /* The KEY in HE will be a MEM. */ struct hash_entry he; /* These are the INSNS which reference the MEM. */ rtx insns; }; /* Forward declarations. */ static rtx assign_outer_stack_local PROTO ((enum machine_mode, HOST_WIDE_INT, int, struct function *)); static rtx assign_stack_temp_for_type PROTO ((enum machine_mode, HOST_WIDE_INT, int, tree)); static struct temp_slot *find_temp_slot_from_address PROTO((rtx)); static void put_reg_into_stack PROTO((struct function *, rtx, tree, enum machine_mode, enum machine_mode, int, int, int, struct hash_table *)); static void fixup_var_refs PROTO((rtx, enum machine_mode, int, struct hash_table *)); static struct fixup_replacement *find_fixup_replacement PROTO((struct fixup_replacement **, rtx)); static void fixup_var_refs_insns PROTO((rtx, enum machine_mode, int, rtx, int, struct hash_table *)); static void fixup_var_refs_1 PROTO((rtx, enum machine_mode, rtx *, rtx, struct fixup_replacement **)); static rtx fixup_memory_subreg PROTO((rtx, rtx, int)); static rtx walk_fixup_memory_subreg PROTO((rtx, rtx, int)); static rtx fixup_stack_1 PROTO((rtx, rtx)); static void optimize_bit_field PROTO((rtx, rtx, rtx *)); static void instantiate_decls PROTO((tree, int)); static void instantiate_decls_1 PROTO((tree, int)); static void instantiate_decl PROTO((rtx, int, int)); static int instantiate_virtual_regs_1 PROTO((rtx *, rtx, int)); static void delete_handlers PROTO((void)); static void pad_to_arg_alignment PROTO((struct args_size *, int)); #ifndef ARGS_GROW_DOWNWARD static void pad_below PROTO((struct args_size *, enum machine_mode, tree)); #endif #ifdef ARGS_GROW_DOWNWARD static tree round_down PROTO((tree, int)); #endif static rtx round_trampoline_addr PROTO((rtx)); static tree blocks_nreverse PROTO((tree)); static int all_blocks PROTO((tree, tree *)); #if defined (HAVE_prologue) || defined (HAVE_epilogue) static int *record_insns PROTO((rtx)); static int contains PROTO((rtx, int *)); #endif /* HAVE_prologue || HAVE_epilogue */ static void put_addressof_into_stack PROTO((rtx, struct hash_table *)); static void purge_addressof_1 PROTO((rtx *, rtx, int, int, struct hash_table *)); static struct hash_entry *insns_for_mem_newfunc PROTO((struct hash_entry *, struct hash_table *, hash_table_key)); static unsigned long insns_for_mem_hash PROTO ((hash_table_key)); static boolean insns_for_mem_comp PROTO ((hash_table_key, hash_table_key)); static int insns_for_mem_walk PROTO ((rtx *, void *)); static void compute_insns_for_mem PROTO ((rtx, rtx, struct hash_table *)); /* Pointer to chain of `struct function' for containing functions. */ struct function *outer_function_chain; /* Given a function decl for a containing function, return the `struct function' for it. */ struct function * find_function_data (decl) tree decl; { struct function *p; for (p = outer_function_chain; p; p = p->next) if (p->decl == decl) return p; abort (); } /* Save the current context for compilation of a nested function. This is called from language-specific code. The caller is responsible for saving any language-specific status, since this function knows only about language-independent variables. */ void push_function_context_to (context) tree context; { struct function *p = (struct function *) xmalloc (sizeof (struct function)); p->next = outer_function_chain; outer_function_chain = p; p->name = current_function_name; p->decl = current_function_decl; p->pops_args = current_function_pops_args; p->returns_struct = current_function_returns_struct; p->returns_pcc_struct = current_function_returns_pcc_struct; p->returns_pointer = current_function_returns_pointer; p->needs_context = current_function_needs_context; p->calls_setjmp = current_function_calls_setjmp; p->calls_longjmp = current_function_calls_longjmp; p->calls_alloca = current_function_calls_alloca; p->has_nonlocal_label = current_function_has_nonlocal_label; p->has_nonlocal_goto = current_function_has_nonlocal_goto; p->contains_functions = current_function_contains_functions; p->has_computed_jump = current_function_has_computed_jump; p->is_thunk = current_function_is_thunk; p->args_size = current_function_args_size; p->pretend_args_size = current_function_pretend_args_size; p->arg_offset_rtx = current_function_arg_offset_rtx; p->varargs = current_function_varargs; p->stdarg = current_function_stdarg; p->uses_const_pool = current_function_uses_const_pool; p->uses_pic_offset_table = current_function_uses_pic_offset_table; p->internal_arg_pointer = current_function_internal_arg_pointer; p->cannot_inline = current_function_cannot_inline; p->max_parm_reg = max_parm_reg; p->parm_reg_stack_loc = parm_reg_stack_loc; p->outgoing_args_size = current_function_outgoing_args_size; p->return_rtx = current_function_return_rtx; p->nonlocal_goto_handler_slots = nonlocal_goto_handler_slots; p->nonlocal_goto_handler_labels = nonlocal_goto_handler_labels; p->nonlocal_goto_stack_level = nonlocal_goto_stack_level; p->nonlocal_labels = nonlocal_labels; p->cleanup_label = cleanup_label; p->return_label = return_label; p->save_expr_regs = save_expr_regs; p->stack_slot_list = stack_slot_list; p->parm_birth_insn = parm_birth_insn; p->frame_offset = frame_offset; p->tail_recursion_label = tail_recursion_label; p->tail_recursion_reentry = tail_recursion_reentry; p->arg_pointer_save_area = arg_pointer_save_area; p->rtl_expr_chain = rtl_expr_chain; p->last_parm_insn = last_parm_insn; p->context_display = context_display; p->trampoline_list = trampoline_list; p->function_call_count = function_call_count; p->temp_slots = temp_slots; p->temp_slot_level = temp_slot_level; p->target_temp_slot_level = target_temp_slot_level; p->var_temp_slot_level = var_temp_slot_level; p->fixup_var_refs_queue = 0; p->epilogue_delay_list = current_function_epilogue_delay_list; p->args_info = current_function_args_info; p->check_memory_usage = current_function_check_memory_usage; p->instrument_entry_exit = current_function_instrument_entry_exit; save_tree_status (p, context); save_storage_status (p); save_emit_status (p); save_expr_status (p); save_stmt_status (p); save_varasm_status (p, context); if (save_machine_status) (*save_machine_status) (p); } void push_function_context () { push_function_context_to (current_function_decl); } /* Restore the last saved context, at the end of a nested function. This function is called from language-specific code. */ void pop_function_context_from (context) tree context; { struct function *p = outer_function_chain; struct var_refs_queue *queue; outer_function_chain = p->next; current_function_contains_functions = p->contains_functions || p->inline_obstacks || context == current_function_decl; current_function_has_computed_jump = p->has_computed_jump; current_function_name = p->name; current_function_decl = p->decl; current_function_pops_args = p->pops_args; current_function_returns_struct = p->returns_struct; current_function_returns_pcc_struct = p->returns_pcc_struct; current_function_returns_pointer = p->returns_pointer; current_function_needs_context = p->needs_context; current_function_calls_setjmp = p->calls_setjmp; current_function_calls_longjmp = p->calls_longjmp; current_function_calls_alloca = p->calls_alloca; current_function_has_nonlocal_label = p->has_nonlocal_label; current_function_has_nonlocal_goto = p->has_nonlocal_goto; current_function_is_thunk = p->is_thunk; current_function_args_size = p->args_size; current_function_pretend_args_size = p->pretend_args_size; current_function_arg_offset_rtx = p->arg_offset_rtx; current_function_varargs = p->varargs; current_function_stdarg = p->stdarg; current_function_uses_const_pool = p->uses_const_pool; current_function_uses_pic_offset_table = p->uses_pic_offset_table; current_function_internal_arg_pointer = p->internal_arg_pointer; current_function_cannot_inline = p->cannot_inline; max_parm_reg = p->max_parm_reg; parm_reg_stack_loc = p->parm_reg_stack_loc; current_function_outgoing_args_size = p->outgoing_args_size; current_function_return_rtx = p->return_rtx; nonlocal_goto_handler_slots = p->nonlocal_goto_handler_slots; nonlocal_goto_handler_labels = p->nonlocal_goto_handler_labels; nonlocal_goto_stack_level = p->nonlocal_goto_stack_level; nonlocal_labels = p->nonlocal_labels; cleanup_label = p->cleanup_label; return_label = p->return_label; save_expr_regs = p->save_expr_regs; stack_slot_list = p->stack_slot_list; parm_birth_insn = p->parm_birth_insn; frame_offset = p->frame_offset; tail_recursion_label = p->tail_recursion_label; tail_recursion_reentry = p->tail_recursion_reentry; arg_pointer_save_area = p->arg_pointer_save_area; rtl_expr_chain = p->rtl_expr_chain; last_parm_insn = p->last_parm_insn; context_display = p->context_display; trampoline_list = p->trampoline_list; function_call_count = p->function_call_count; temp_slots = p->temp_slots; temp_slot_level = p->temp_slot_level; target_temp_slot_level = p->target_temp_slot_level; var_temp_slot_level = p->var_temp_slot_level; current_function_epilogue_delay_list = p->epilogue_delay_list; reg_renumber = 0; current_function_args_info = p->args_info; current_function_check_memory_usage = p->check_memory_usage; current_function_instrument_entry_exit = p->instrument_entry_exit; restore_tree_status (p, context); restore_storage_status (p); restore_expr_status (p); restore_emit_status (p); restore_stmt_status (p); restore_varasm_status (p); if (restore_machine_status) (*restore_machine_status) (p); /* Finish doing put_var_into_stack for any of our variables which became addressable during the nested function. */ for (queue = p->fixup_var_refs_queue; queue; queue = queue->next) fixup_var_refs (queue->modified, queue->promoted_mode, queue->unsignedp, 0); free (p); /* Reset variables that have known state during rtx generation. */ rtx_equal_function_value_matters = 1; virtuals_instantiated = 0; } void pop_function_context () { pop_function_context_from (current_function_decl); } /* Allocate fixed slots in the stack frame of the current function. */ /* Return size needed for stack frame based on slots so far allocated. This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY; the caller may have to do that. */ HOST_WIDE_INT get_frame_size () { #ifdef FRAME_GROWS_DOWNWARD return -frame_offset; #else return frame_offset; #endif } /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it with machine mode MODE. ALIGN controls the amount of alignment for the address of the slot: 0 means according to MODE, -1 means use BIGGEST_ALIGNMENT and round size to multiple of that, positive specifies alignment boundary in bits. We do not round to stack_boundary here. */ rtx assign_stack_local (mode, size, align) enum machine_mode mode; HOST_WIDE_INT size; int align; { register rtx x, addr; int bigend_correction = 0; int alignment; if (align == 0) { tree type; alignment = GET_MODE_ALIGNMENT (mode); if (mode == BLKmode) alignment = BIGGEST_ALIGNMENT; /* Allow the target to (possibly) increase the alignment of this stack slot. */ type = type_for_mode (mode, 0); if (type) alignment = LOCAL_ALIGNMENT (type, alignment); alignment /= BITS_PER_UNIT; } else if (align == -1) { alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; size = CEIL_ROUND (size, alignment); } else alignment = align / BITS_PER_UNIT; #ifdef FRAME_GROWS_DOWNWARD frame_offset -= size; #endif /* Round frame offset to that alignment. We must be careful here, since FRAME_OFFSET might be negative and division with a negative dividend isn't as well defined as we might like. So we instead assume that ALIGNMENT is a power of two and use logical operations which are unambiguous. */ #ifdef FRAME_GROWS_DOWNWARD frame_offset = FLOOR_ROUND (frame_offset, alignment); #else frame_offset = CEIL_ROUND (frame_offset, alignment); #endif /* On a big-endian machine, if we are allocating more space than we will use, use the least significant bytes of those that are allocated. */ if (BYTES_BIG_ENDIAN && mode != BLKmode) bigend_correction = size - GET_MODE_SIZE (mode); /* If we have already instantiated virtual registers, return the actual address relative to the frame pointer. */ if (virtuals_instantiated) addr = plus_constant (frame_pointer_rtx, (frame_offset + bigend_correction + STARTING_FRAME_OFFSET)); else addr = plus_constant (virtual_stack_vars_rtx, frame_offset + bigend_correction); #ifndef FRAME_GROWS_DOWNWARD frame_offset += size; #endif x = gen_rtx_MEM (mode, addr); stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, stack_slot_list); return x; } /* Assign a stack slot in a containing function. First three arguments are same as in preceding function. The last argument specifies the function to allocate in. */ static rtx assign_outer_stack_local (mode, size, align, function) enum machine_mode mode; HOST_WIDE_INT size; int align; struct function *function; { register rtx x, addr; int bigend_correction = 0; int alignment; /* Allocate in the memory associated with the function in whose frame we are assigning. */ push_obstacks (function->function_obstack, function->function_maybepermanent_obstack); if (align == 0) { tree type; alignment = GET_MODE_ALIGNMENT (mode); if (mode == BLKmode) alignment = BIGGEST_ALIGNMENT; /* Allow the target to (possibly) increase the alignment of this stack slot. */ type = type_for_mode (mode, 0); if (type) alignment = LOCAL_ALIGNMENT (type, alignment); alignment /= BITS_PER_UNIT; } else if (align == -1) { alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; size = CEIL_ROUND (size, alignment); } else alignment = align / BITS_PER_UNIT; #ifdef FRAME_GROWS_DOWNWARD function->frame_offset -= size; #endif /* Round frame offset to that alignment. */ #ifdef FRAME_GROWS_DOWNWARD function->frame_offset = FLOOR_ROUND (function->frame_offset, alignment); #else function->frame_offset = CEIL_ROUND (function->frame_offset, alignment); #endif /* On a big-endian machine, if we are allocating more space than we will use, use the least significant bytes of those that are allocated. */ if (BYTES_BIG_ENDIAN && mode != BLKmode) bigend_correction = size - GET_MODE_SIZE (mode); addr = plus_constant (virtual_stack_vars_rtx, function->frame_offset + bigend_correction); #ifndef FRAME_GROWS_DOWNWARD function->frame_offset += size; #endif x = gen_rtx_MEM (mode, addr); function->stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, x, function->stack_slot_list); pop_obstacks (); return x; } /* Allocate a temporary stack slot and record it for possible later reuse. MODE is the machine mode to be given to the returned rtx. SIZE is the size in units of the space required. We do no rounding here since assign_stack_local will do any required rounding. KEEP is 1 if this slot is to be retained after a call to free_temp_slots. Automatic variables for a block are allocated with this flag. KEEP is 2 if we allocate a longer term temporary, whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3 if we are to allocate something at an inner level to be treated as a variable in the block (e.g., a SAVE_EXPR). TYPE is the type that will be used for the stack slot. */ static rtx assign_stack_temp_for_type (mode, size, keep, type) enum machine_mode mode; HOST_WIDE_INT size; int keep; tree type; { int align; int alias_set; struct temp_slot *p, *best_p = 0; /* If SIZE is -1 it means that somebody tried to allocate a temporary of a variable size. */ if (size == -1) abort (); /* If we know the alias set for the memory that will be used, use it. If there's no TYPE, then we don't know anything about the alias set for the memory. */ if (type) alias_set = get_alias_set (type); else alias_set = 0; align = GET_MODE_ALIGNMENT (mode); if (mode == BLKmode) align = BIGGEST_ALIGNMENT; if (! type) type = type_for_mode (mode, 0); if (type) align = LOCAL_ALIGNMENT (type, align); /* Try to find an available, already-allocated temporary of the proper mode which meets the size and alignment requirements. Choose the smallest one with the closest alignment. */ for (p = temp_slots; p; p = p->next) if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode && ! p->in_use && (!flag_strict_aliasing || (alias_set && p->alias_set == alias_set)) && (best_p == 0 || best_p->size > p->size || (best_p->size == p->size && best_p->align > p->align))) { if (p->align == align && p->size == size) { best_p = 0; break; } best_p = p; } /* Make our best, if any, the one to use. */ if (best_p) { /* If there are enough aligned bytes left over, make them into a new temp_slot so that the extra bytes don't get wasted. Do this only for BLKmode slots, so that we can be sure of the alignment. */ if (GET_MODE (best_p->slot) == BLKmode /* We can't split slots if -fstrict-aliasing because the information about the alias set for the new slot will be lost. */ && !flag_strict_aliasing) { int alignment = best_p->align / BITS_PER_UNIT; HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment); if (best_p->size - rounded_size >= alignment) { p = (struct temp_slot *) oballoc (sizeof (struct temp_slot)); p->in_use = p->addr_taken = 0; p->size = best_p->size - rounded_size; p->base_offset = best_p->base_offset + rounded_size; p->full_size = best_p->full_size - rounded_size; p->slot = gen_rtx_MEM (BLKmode, plus_constant (XEXP (best_p->slot, 0), rounded_size)); p->align = best_p->align; p->address = 0; p->rtl_expr = 0; p->next = temp_slots; temp_slots = p; stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot, stack_slot_list); best_p->size = rounded_size; best_p->full_size = rounded_size; } } p = best_p; } /* If we still didn't find one, make a new temporary. */ if (p == 0) { HOST_WIDE_INT frame_offset_old = frame_offset; p = (struct temp_slot *) oballoc (sizeof (struct temp_slot)); /* We are passing an explicit alignment request to assign_stack_local. One side effect of that is assign_stack_local will not round SIZE to ensure the frame offset remains suitably aligned. So for requests which depended on the rounding of SIZE, we go ahead and round it now. We also make sure ALIGNMENT is at least BIGGEST_ALIGNMENT. */ if (mode == BLKmode && align < BIGGEST_ALIGNMENT) abort(); p->slot = assign_stack_local (mode, (mode == BLKmode ? CEIL_ROUND (size, align / BITS_PER_UNIT) : size), align); p->align = align; p->alias_set = alias_set; /* The following slot size computation is necessary because we don't know the actual size of the temporary slot until assign_stack_local has performed all the frame alignment and size rounding for the requested temporary. Note that extra space added for alignment can be either above or below this stack slot depending on which way the frame grows. We include the extra space if and only if it is above this slot. */ #ifdef FRAME_GROWS_DOWNWARD p->size = frame_offset_old - frame_offset; #else p->size = size; #endif /* Now define the fields used by combine_temp_slots. */ #ifdef FRAME_GROWS_DOWNWARD p->base_offset = frame_offset; p->full_size = frame_offset_old - frame_offset; #else p->base_offset = frame_offset_old; p->full_size = frame_offset - frame_offset_old; #endif p->address = 0; p->next = temp_slots; temp_slots = p; } p->in_use = 1; p->addr_taken = 0; p->rtl_expr = sequence_rtl_expr; if (keep == 2) { p->level = target_temp_slot_level; p->keep = 0; } else if (keep == 3) { p->level = var_temp_slot_level; p->keep = 0; } else { p->level = temp_slot_level; p->keep = keep; } /* We may be reusing an old slot, so clear any MEM flags that may have been set from before. */ RTX_UNCHANGING_P (p->slot) = 0; MEM_IN_STRUCT_P (p->slot) = 0; MEM_SCALAR_P (p->slot) = 0; MEM_ALIAS_SET (p->slot) = 0; return p->slot; } /* Allocate a temporary stack slot and record it for possible later reuse. First three arguments are same as in preceding function. */ rtx assign_stack_temp (mode, size, keep) enum machine_mode mode; HOST_WIDE_INT size; int keep; { return assign_stack_temp_for_type (mode, size, keep, NULL_TREE); } /* Assign a temporary of given TYPE. KEEP is as for assign_stack_temp. MEMORY_REQUIRED is 1 if the result must be addressable stack memory; it is 0 if a register is OK. DONT_PROMOTE is 1 if we should not promote values in register to wider modes. */ rtx assign_temp (type, keep, memory_required, dont_promote) tree type; int keep; int memory_required; int dont_promote; { enum machine_mode mode = TYPE_MODE (type); int unsignedp = TREE_UNSIGNED (type); if (mode == BLKmode || memory_required) { HOST_WIDE_INT size = int_size_in_bytes (type); rtx tmp; /* Unfortunately, we don't yet know how to allocate variable-sized temporaries. However, sometimes we have a fixed upper limit on the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that instead. This is the case for Chill variable-sized strings. */ if (size == -1 && TREE_CODE (type) == ARRAY_TYPE && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE && TREE_CODE (TYPE_ARRAY_MAX_SIZE (type)) == INTEGER_CST) size = TREE_INT_CST_LOW (TYPE_ARRAY_MAX_SIZE (type)); tmp = assign_stack_temp_for_type (mode, size, keep, type); MEM_SET_IN_STRUCT_P (tmp, AGGREGATE_TYPE_P (type)); return tmp; } #ifndef PROMOTE_FOR_CALL_ONLY if (! dont_promote) mode = promote_mode (type, mode, &unsignedp, 0); #endif return gen_reg_rtx (mode); } /* Combine temporary stack slots which are adjacent on the stack. This allows for better use of already allocated stack space. This is only done for BLKmode slots because we can be sure that we won't have alignment problems in this case. */ void combine_temp_slots () { struct temp_slot *p, *q; struct temp_slot *prev_p, *prev_q; int num_slots; /* We can't combine slots, because the information about which slot is in which alias set will be lost. */ if (flag_strict_aliasing) return; /* If there are a lot of temp slots, don't do anything unless high levels of optimizaton. */ if (! flag_expensive_optimizations) for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++) if (num_slots > 100 || (num_slots > 10 && optimize == 0)) return; for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots) { int delete_p = 0; if (! p->in_use && GET_MODE (p->slot) == BLKmode) for (q = p->next, prev_q = p; q; q = prev_q->next) { int delete_q = 0; if (! q->in_use && GET_MODE (q->slot) == BLKmode) { if (p->base_offset + p->full_size == q->base_offset) { /* Q comes after P; combine Q into P. */ p->size += q->size; p->full_size += q->full_size; delete_q = 1; } else if (q->base_offset + q->full_size == p->base_offset) { /* P comes after Q; combine P into Q. */ q->size += p->size; q->full_size += p->full_size; delete_p = 1; break; } } /* Either delete Q or advance past it. */ if (delete_q) prev_q->next = q->next; else prev_q = q; } /* Either delete P or advance past it. */ if (delete_p) { if (prev_p) prev_p->next = p->next; else temp_slots = p->next; } else prev_p = p; } } /* Find the temp slot corresponding to the object at address X. */ static struct temp_slot * find_temp_slot_from_address (x) rtx x; { struct temp_slot *p; rtx next; for (p = temp_slots; p; p = p->next) { if (! p->in_use) continue; else if (XEXP (p->slot, 0) == x || p->address == x || (GET_CODE (x) == PLUS && XEXP (x, 0) == virtual_stack_vars_rtx && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) >= p->base_offset && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size)) return p; else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST) for (next = p->address; next; next = XEXP (next, 1)) if (XEXP (next, 0) == x) return p; } return 0; } /* Indicate that NEW is an alternate way of referring to the temp slot that previously was known by OLD. */ void update_temp_slot_address (old, new) rtx old, new; { struct temp_slot *p = find_temp_slot_from_address (old); /* If none, return. Else add NEW as an alias. */ if (p == 0) return; else if (p->address == 0) p->address = new; else { if (GET_CODE (p->address) != EXPR_LIST) p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX); p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address); } } /* If X could be a reference to a temporary slot, mark the fact that its address was taken. */ void mark_temp_addr_taken (x) rtx x; { struct temp_slot *p; if (x == 0) return; /* If X is not in memory or is at a constant address, it cannot be in a temporary slot. */ if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) return; p = find_temp_slot_from_address (XEXP (x, 0)); if (p != 0) p->addr_taken = 1; } /* If X could be a reference to a temporary slot, mark that slot as belonging to the to one level higher than the current level. If X matched one of our slots, just mark that one. Otherwise, we can't easily predict which it is, so upgrade all of them. Kept slots need not be touched. This is called when an ({...}) construct occurs and a statement returns a value in memory. */ void preserve_temp_slots (x) rtx x; { struct temp_slot *p = 0; /* If there is no result, we still might have some objects whose address were taken, so we need to make sure they stay around. */ if (x == 0) { for (p = temp_slots; p; p = p->next) if (p->in_use && p->level == temp_slot_level && p->addr_taken) p->level--; return; } /* If X is a register that is being used as a pointer, see if we have a temporary slot we know it points to. To be consistent with the code below, we really should preserve all non-kept slots if we can't find a match, but that seems to be much too costly. */ if (GET_CODE (x) == REG && REGNO_POINTER_FLAG (REGNO (x))) p = find_temp_slot_from_address (x); /* If X is not in memory or is at a constant address, it cannot be in a temporary slot, but it can contain something whose address was taken. */ if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))) { for (p = temp_slots; p; p = p->next) if (p->in_use && p->level == temp_slot_level && p->addr_taken) p->level--; return; } /* First see if we can find a match. */ if (p == 0) p = find_temp_slot_from_address (XEXP (x, 0)); if (p != 0) { /* Move everything at our level whose address was taken to our new level in case we used its address. */ struct temp_slot *q; if (p->level == temp_slot_level) { for (q = temp_slots; q; q = q->next) if (q != p && q->addr_taken && q->level == p->level) q->level--; p->level--; p->addr_taken = 0; } return; } /* Otherwise, preserve all non-kept slots at this level. */ for (p = temp_slots; p; p = p->next) if (p->in_use && p->level == temp_slot_level && ! p->keep) p->level--; } /* X is the result of an RTL_EXPR. If it is a temporary slot associated with that RTL_EXPR, promote it into a temporary slot at the present level so it will not be freed when we free slots made in the RTL_EXPR. */ void preserve_rtl_expr_result (x) rtx x; { struct temp_slot *p; /* If X is not in memory or is at a constant address, it cannot be in a temporary slot. */ if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) return; /* If we can find a match, move it to our level unless it is already at an upper level. */ p = find_temp_slot_from_address (XEXP (x, 0)); if (p != 0) { p->level = MIN (p->level, temp_slot_level); p->rtl_expr = 0; } return; } /* Free all temporaries used so far. This is normally called at the end of generating code for a statement. Don't free any temporaries currently in use for an RTL_EXPR that hasn't yet been emitted. We could eventually do better than this since it can be reused while generating the same RTL_EXPR, but this is complex and probably not worthwhile. */ void free_temp_slots () { struct temp_slot *p; for (p = temp_slots; p; p = p->next) if (p->in_use && p->level == temp_slot_level && ! p->keep && p->rtl_expr == 0) p->in_use = 0; combine_temp_slots (); } /* Free all temporary slots used in T, an RTL_EXPR node. */ void free_temps_for_rtl_expr (t) tree t; { struct temp_slot *p; for (p = temp_slots; p; p = p->next) if (p->rtl_expr == t) p->in_use = 0; combine_temp_slots (); } /* Mark all temporaries ever allocated in this function as not suitable for reuse until the current level is exited. */ void mark_all_temps_used () { struct temp_slot *p; for (p = temp_slots; p; p = p->next) { p->in_use = p->keep = 1; p->level = MIN (p->level, temp_slot_level); } } /* Push deeper into the nesting level for stack temporaries. */ void push_temp_slots () { temp_slot_level++; } /* Likewise, but save the new level as the place to allocate variables for blocks. */ void push_temp_slots_for_block () { push_temp_slots (); var_temp_slot_level = temp_slot_level; } /* Likewise, but save the new level as the place to allocate temporaries for TARGET_EXPRs. */ void push_temp_slots_for_target () { push_temp_slots (); target_temp_slot_level = temp_slot_level; } /* Set and get the value of target_temp_slot_level. The only permitted use of these functions is to save and restore this value. */ int get_target_temp_slot_level () { return target_temp_slot_level; } void set_target_temp_slot_level (level) int level; { target_temp_slot_level = level; } /* Pop a temporary nesting level. All slots in use in the current level are freed. */ void pop_temp_slots () { struct temp_slot *p; for (p = temp_slots; p; p = p->next) if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0) p->in_use = 0; combine_temp_slots (); temp_slot_level--; } /* Initialize temporary slots. */ void init_temp_slots () { /* We have not allocated any temporaries yet. */ temp_slots = 0; temp_slot_level = 0; var_temp_slot_level = 0; target_temp_slot_level = 0; } /* Retroactively move an auto variable from a register to a stack slot. This is done when an address-reference to the variable is seen. */ void put_var_into_stack (decl) tree decl; { register rtx reg; enum machine_mode promoted_mode, decl_mode; struct function *function = 0; tree context; int can_use_addressof; context = decl_function_context (decl); /* Get the current rtl used for this object and its original mode. */ reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl); /* No need to do anything if decl has no rtx yet since in that case caller is setting TREE_ADDRESSABLE and a stack slot will be assigned when the rtl is made. */ if (reg == 0) return; /* Get the declared mode for this object. */ decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl)) : DECL_MODE (decl)); /* Get the mode it's actually stored in. */ promoted_mode = GET_MODE (reg); /* If this variable comes from an outer function, find that function's saved context. */ if (context != current_function_decl && context != inline_function_decl) for (function = outer_function_chain; function; function = function->next) if (function->decl == context) break; /* If this is a variable-size object with a pseudo to address it, put that pseudo into the stack, if the var is nonlocal. */ if (DECL_NONLOCAL (decl) && GET_CODE (reg) == MEM && GET_CODE (XEXP (reg, 0)) == REG && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER) { reg = XEXP (reg, 0); decl_mode = promoted_mode = GET_MODE (reg); } can_use_addressof = (function == 0 && optimize > 0 /* FIXME make it work for promoted modes too */ && decl_mode == promoted_mode #ifdef NON_SAVING_SETJMP && ! (NON_SAVING_SETJMP && current_function_calls_setjmp) #endif ); /* If we can't use ADDRESSOF, make sure we see through one we already generated. */ if (! can_use_addressof && GET_CODE (reg) == MEM && GET_CODE (XEXP (reg, 0)) == ADDRESSOF) reg = XEXP (XEXP (reg, 0), 0); /* Now we should have a value that resides in one or more pseudo regs. */ if (GET_CODE (reg) == REG) { /* If this variable lives in the current function and we don't need to put things in the stack for the sake of setjmp, try to keep it in a register until we know we actually need the address. */ if (can_use_addressof) gen_mem_addressof (reg, decl); else put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode, decl_mode, TREE_SIDE_EFFECTS (decl), 0, TREE_USED (decl) || DECL_INITIAL (decl) != 0, 0); } else if (GET_CODE (reg) == CONCAT) { /* A CONCAT contains two pseudos; put them both in the stack. We do it so they end up consecutive. */ enum machine_mode part_mode = GET_MODE (XEXP (reg, 0)); tree part_type = TREE_TYPE (TREE_TYPE (decl)); #ifdef FRAME_GROWS_DOWNWARD /* Since part 0 should have a lower address, do it second. */ put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode, part_mode, TREE_SIDE_EFFECTS (decl), 0, TREE_USED (decl) || DECL_INITIAL (decl) != 0, 0); put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode, part_mode, TREE_SIDE_EFFECTS (decl), 0, TREE_USED (decl) || DECL_INITIAL (decl) != 0, 0); #else put_reg_into_stack (function, XEXP (reg, 0), part_type, part_mode, part_mode, TREE_SIDE_EFFECTS (decl), 0, TREE_USED (decl) || DECL_INITIAL (decl) != 0, 0); put_reg_into_stack (function, XEXP (reg, 1), part_type, part_mode, part_mode, TREE_SIDE_EFFECTS (decl), 0, TREE_USED (decl) || DECL_INITIAL (decl) != 0, 0); #endif /* Change the CONCAT into a combined MEM for both parts. */ PUT_CODE (reg, MEM); MEM_VOLATILE_P (reg) = MEM_VOLATILE_P (XEXP (reg, 0)); MEM_ALIAS_SET (reg) = get_alias_set (decl); /* The two parts are in memory order already. Use the lower parts address as ours. */ XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0); /* Prevent sharing of rtl that might lose. */ if (GET_CODE (XEXP (reg, 0)) == PLUS) XEXP (reg, 0) = copy_rtx (XEXP (reg, 0)); } else return; if (current_function_check_memory_usage) emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, XEXP (reg, 0), Pmode, GEN_INT (GET_MODE_SIZE (GET_MODE (reg))), TYPE_MODE (sizetype), GEN_INT (MEMORY_USE_RW), TYPE_MODE (integer_type_node)); } /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG into the stack frame of FUNCTION (0 means the current function). DECL_MODE is the machine mode of the user-level data type. PROMOTED_MODE is the machine mode of the register. VOLATILE_P is nonzero if this is for a "volatile" decl. USED_P is nonzero if this reg might have already been used in an insn. */ static void put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p, original_regno, used_p, ht) struct function *function; rtx reg; tree type; enum machine_mode promoted_mode, decl_mode; int volatile_p; int original_regno; int used_p; struct hash_table *ht; { rtx new = 0; int regno = original_regno; if (regno == 0) regno = REGNO (reg); if (function) { if (regno < function->max_parm_reg) new = function->parm_reg_stack_loc[regno]; if (new == 0) new = assign_outer_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0, function); } else { if (regno < max_parm_reg) new = parm_reg_stack_loc[regno]; if (new == 0) new = assign_stack_local (decl_mode, GET_MODE_SIZE (decl_mode), 0); } PUT_MODE (reg, decl_mode); XEXP (reg, 0) = XEXP (new, 0); /* `volatil' bit means one thing for MEMs, another entirely for REGs. */ MEM_VOLATILE_P (reg) = volatile_p; PUT_CODE (reg, MEM); /* If this is a memory ref that contains aggregate components, mark it as such for cse and loop optimize. If we are reusing a previously generated stack slot, then we need to copy the bit in case it was set for other reasons. For instance, it is set for __builtin_va_alist. */ MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new)); MEM_ALIAS_SET (reg) = get_alias_set (type); /* Now make sure that all refs to the variable, previously made when it was a register, are fixed up to be valid again. */ if (used_p && function != 0) { struct var_refs_queue *temp; /* Variable is inherited; fix it up when we get back to its function. */ push_obstacks (function->function_obstack, function->function_maybepermanent_obstack); /* See comment in restore_tree_status in tree.c for why this needs to be on saveable obstack. */ temp = (struct var_refs_queue *) savealloc (sizeof (struct var_refs_queue)); temp->modified = reg; temp->promoted_mode = promoted_mode; temp->unsignedp = TREE_UNSIGNED (type); temp->next = function->fixup_var_refs_queue; function->fixup_var_refs_queue = temp; pop_obstacks (); } else if (used_p) /* Variable is local; fix it up now. */ fixup_var_refs (reg, promoted_mode, TREE_UNSIGNED (type), ht); } static void fixup_var_refs (var, promoted_mode, unsignedp, ht) rtx var; enum machine_mode promoted_mode; int unsignedp; struct hash_table *ht; { tree pending; rtx first_insn = get_insns (); struct sequence_stack *stack = sequence_stack; tree rtl_exps = rtl_expr_chain; /* Must scan all insns for stack-refs that exceed the limit. */ fixup_var_refs_insns (var, promoted_mode, unsignedp, first_insn, stack == 0, ht); /* If there's a hash table, it must record all uses of VAR. */ if (ht) return; /* Scan all pending sequences too. */ for (; stack; stack = stack->next) { push_to_sequence (stack->first); fixup_var_refs_insns (var, promoted_mode, unsignedp, stack->first, stack->next != 0, 0); /* Update remembered end of sequence in case we added an insn at the end. */ stack->last = get_last_insn (); end_sequence (); } /* Scan all waiting RTL_EXPRs too. */ for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending)) { rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending)); if (seq != const0_rtx && seq != 0) { push_to_sequence (seq); fixup_var_refs_insns (var, promoted_mode, unsignedp, seq, 0, 0); end_sequence (); } } /* Scan the catch clauses for exception handling too. */ push_to_sequence (catch_clauses); fixup_var_refs_insns (var, promoted_mode, unsignedp, catch_clauses, 0, 0); end_sequence (); } /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is some part of an insn. Return a struct fixup_replacement whose OLD value is equal to X. Allocate a new structure if no such entry exists. */ static struct fixup_replacement * find_fixup_replacement (replacements, x) struct fixup_replacement **replacements; rtx x; { struct fixup_replacement *p; /* See if we have already replaced this. */ for (p = *replacements; p && p->old != x; p = p->next) ; if (p == 0) { p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement)); p->old = x; p->new = 0; p->next = *replacements; *replacements = p; } return p; } /* Scan the insn-chain starting with INSN for refs to VAR and fix them up. TOPLEVEL is nonzero if this chain is the main chain of insns for the current function. */ static void fixup_var_refs_insns (var, promoted_mode, unsignedp, insn, toplevel, ht) rtx var; enum machine_mode promoted_mode; int unsignedp; rtx insn; int toplevel; struct hash_table *ht; { rtx call_dest = 0; rtx insn_list = NULL_RTX; /* If we already know which INSNs reference VAR there's no need to walk the entire instruction chain. */ if (ht) { insn_list = ((struct insns_for_mem_entry *) hash_lookup (ht, var, /*create=*/0, /*copy=*/0))->insns; insn = insn_list ? XEXP (insn_list, 0) : NULL_RTX; insn_list = XEXP (insn_list, 1); } while (insn) { rtx next = NEXT_INSN (insn); rtx set, prev, prev_set; rtx note; if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') { /* If this is a CLOBBER of VAR, delete it. If it has a REG_LIBCALL note, delete the REG_LIBCALL and REG_RETVAL notes too. */ if (GET_CODE (PATTERN (insn)) == CLOBBER && (XEXP (PATTERN (insn), 0) == var || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT && (XEXP (XEXP (PATTERN (insn), 0), 0) == var || XEXP (XEXP (PATTERN (insn), 0), 1) == var)))) { if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0) /* The REG_LIBCALL note will go away since we are going to turn INSN into a NOTE, so just delete the corresponding REG_RETVAL note. */ remove_note (XEXP (note, 0), find_reg_note (XEXP (note, 0), REG_RETVAL, NULL_RTX)); /* In unoptimized compilation, we shouldn't call delete_insn except in jump.c doing warnings. */ PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; } /* The insn to load VAR from a home in the arglist is now a no-op. When we see it, just delete it. Similarly if this is storing VAR from a register from which it was loaded in the previous insn. This will occur when an ADDRESSOF was made for an arglist slot. */ else if (toplevel && (set = single_set (insn)) != 0 && SET_DEST (set) == var /* If this represents the result of an insn group, don't delete the insn. */ && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0 && (rtx_equal_p (SET_SRC (set), var) || (GET_CODE (SET_SRC (set)) == REG && (prev = prev_nonnote_insn (insn)) != 0 && (prev_set = single_set (prev)) != 0 && SET_DEST (prev_set) == SET_SRC (set) && rtx_equal_p (SET_SRC (prev_set), var)))) { /* In unoptimized compilation, we shouldn't call delete_insn except in jump.c doing warnings. */ PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; if (insn == last_parm_insn) last_parm_insn = PREV_INSN (next); } else { struct fixup_replacement *replacements = 0; rtx next_insn = NEXT_INSN (insn); if (SMALL_REGISTER_CLASSES) { /* If the insn that copies the results of a CALL_INSN into a pseudo now references VAR, we have to use an intermediate pseudo since we want the life of the return value register to be only a single insn. If we don't use an intermediate pseudo, such things as address computations to make the address of VAR valid if it is not can be placed between the CALL_INSN and INSN. To make sure this doesn't happen, we record the destination of the CALL_INSN and see if the next insn uses both that and VAR. */ if (call_dest != 0 && GET_CODE (insn) == INSN && reg_mentioned_p (var, PATTERN (insn)) && reg_mentioned_p (call_dest, PATTERN (insn))) { rtx temp = gen_reg_rtx (GET_MODE (call_dest)); emit_insn_before (gen_move_insn (temp, call_dest), insn); PATTERN (insn) = replace_rtx (PATTERN (insn), call_dest, temp); } if (GET_CODE (insn) == CALL_INSN && GET_CODE (PATTERN (insn)) == SET) call_dest = SET_DEST (PATTERN (insn)); else if (GET_CODE (insn) == CALL_INSN && GET_CODE (PATTERN (insn)) == PARALLEL && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET) call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0)); else call_dest = 0; } /* See if we have to do anything to INSN now that VAR is in memory. If it needs to be loaded into a pseudo, use a single pseudo for the entire insn in case there is a MATCH_DUP between two operands. We pass a pointer to the head of a list of struct fixup_replacements. If fixup_var_refs_1 needs to allocate pseudos or replacement MEMs (for SUBREGs), it will record them in this list. If it allocated a pseudo for any replacement, we copy into it here. */ fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn, &replacements); /* If this is last_parm_insn, and any instructions were output after it to fix it up, then we must set last_parm_insn to the last such instruction emitted. */ if (insn == last_parm_insn) last_parm_insn = PREV_INSN (next_insn); while (replacements) { if (GET_CODE (replacements->new) == REG) { rtx insert_before; rtx seq; /* OLD might be a (subreg (mem)). */ if (GET_CODE (replacements->old) == SUBREG) replacements->old = fixup_memory_subreg (replacements->old, insn, 0); else replacements->old = fixup_stack_1 (replacements->old, insn); insert_before = insn; /* If we are changing the mode, do a conversion. This might be wasteful, but combine.c will eliminate much of the waste. */ if (GET_MODE (replacements->new) != GET_MODE (replacements->old)) { start_sequence (); convert_move (replacements->new, replacements->old, unsignedp); seq = gen_sequence (); end_sequence (); } else seq = gen_move_insn (replacements->new, replacements->old); emit_insn_before (seq, insert_before); } replacements = replacements->next; } } /* Also fix up any invalid exprs in the REG_NOTES of this insn. But don't touch other insns referred to by reg-notes; we will get them elsewhere. */ for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) if (GET_CODE (note) != INSN_LIST) XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1); } if (!ht) insn = next; else if (insn_list) { insn = XEXP (insn_list, 0); insn_list = XEXP (insn_list, 1); } else insn = NULL_RTX; } } /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE. See if the rtx expression at *LOC in INSN needs to be changed. REPLACEMENTS is a pointer to a list head that starts out zero, but may contain a list of original rtx's and replacements. If we find that we need to modify this insn by replacing a memory reference with a pseudo or by making a new MEM to implement a SUBREG, we consult that list to see if we have already chosen a replacement. If none has already been allocated, we allocate it and update the list. fixup_var_refs_insns will copy VAR or the SUBREG, as appropriate, to the pseudo. */ static void fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements) register rtx var; enum machine_mode promoted_mode; register rtx *loc; rtx insn; struct fixup_replacement **replacements; { register int i; register rtx x = *loc; RTX_CODE code = GET_CODE (x); register char *fmt; register rtx tem, tem1; struct fixup_replacement *replacement; switch (code) { case ADDRESSOF: if (XEXP (x, 0) == var) { /* Prevent sharing of rtl that might lose. */ rtx sub = copy_rtx (XEXP (var, 0)); if (! validate_change (insn, loc, sub, 0)) { rtx y = gen_reg_rtx (GET_MODE (sub)); rtx seq, new_insn; /* We should be able to replace with a register or all is lost. Note that we can't use validate_change to verify this, since we're not caring for replacing all dups simultaneously. */ if (! validate_replace_rtx (*loc, y, insn)) abort (); /* Careful! First try to recognize a direct move of the value, mimicking how things are done in gen_reload wrt PLUS. Consider what happens when insn is a conditional move instruction and addsi3 clobbers flags. */ start_sequence (); new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub)); seq = gen_sequence (); end_sequence (); if (recog_memoized (new_insn) < 0) { /* That failed. Fall back on force_operand and hope. */ start_sequence (); force_operand (sub, y); seq = gen_sequence (); end_sequence (); } #ifdef HAVE_cc0 /* Don't separate setter from user. */ if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn))) insn = PREV_INSN (insn); #endif emit_insn_before (seq, insn); } } return; case MEM: if (var == x) { /* If we already have a replacement, use it. Otherwise, try to fix up this address in case it is invalid. */ replacement = find_fixup_replacement (replacements, var); if (replacement->new) { *loc = replacement->new; return; } *loc = replacement->new = x = fixup_stack_1 (x, insn); /* Unless we are forcing memory to register or we changed the mode, we can leave things the way they are if the insn is valid. */ INSN_CODE (insn) = -1; if (! flag_force_mem && GET_MODE (x) == promoted_mode && recog_memoized (insn) >= 0) return; *loc = replacement->new = gen_reg_rtx (promoted_mode); return; } /* If X contains VAR, we need to unshare it here so that we update each occurrence separately. But all identical MEMs in one insn must be replaced with the same rtx because of the possibility of MATCH_DUPs. */ if (reg_mentioned_p (var, x)) { replacement = find_fixup_replacement (replacements, x); if (replacement->new == 0) replacement->new = copy_most_rtx (x, var); *loc = x = replacement->new; } break; case REG: case CC0: case PC: case CONST_INT: case CONST: case SYMBOL_REF: case LABEL_REF: case CONST_DOUBLE: return; case SIGN_EXTRACT: case ZERO_EXTRACT: /* Note that in some cases those types of expressions are altered by optimize_bit_field, and do not survive to get here. */ if (XEXP (x, 0) == var || (GET_CODE (XEXP (x, 0)) == SUBREG && SUBREG_REG (XEXP (x, 0)) == var)) { /* Get TEM as a valid MEM in the mode presently in the insn. We don't worry about the possibility of MATCH_DUP here; it is highly unlikely and would be tricky to handle. */ tem = XEXP (x, 0); if (GET_CODE (tem) == SUBREG) { if (GET_MODE_BITSIZE (GET_MODE (tem)) > GET_MODE_BITSIZE (GET_MODE (var))) { replacement = find_fixup_replacement (replacements, var); if (replacement->new == 0) replacement->new = gen_reg_rtx (GET_MODE (var)); SUBREG_REG (tem) = replacement->new; } else tem = fixup_memory_subreg (tem, insn, 0); } else tem = fixup_stack_1 (tem, insn); /* Unless we want to load from memory, get TEM into the proper mode for an extract from memory. This can only be done if the extract is at a constant position and length. */ if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT && GET_CODE (XEXP (x, 2)) == CONST_INT && ! mode_dependent_address_p (XEXP (tem, 0)) && ! MEM_VOLATILE_P (tem)) { enum machine_mode wanted_mode = VOIDmode; enum machine_mode is_mode = GET_MODE (tem); HOST_WIDE_INT pos = INTVAL (XEXP (x, 2)); #ifdef HAVE_extzv if (GET_CODE (x) == ZERO_EXTRACT) { wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1]; if (wanted_mode == VOIDmode) wanted_mode = word_mode; } #endif #ifdef HAVE_extv if (GET_CODE (x) == SIGN_EXTRACT) { wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1]; if (wanted_mode == VOIDmode) wanted_mode = word_mode; } #endif /* If we have a narrower mode, we can do something. */ if (wanted_mode != VOIDmode && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) { HOST_WIDE_INT offset = pos / BITS_PER_UNIT; rtx old_pos = XEXP (x, 2); rtx newmem; /* If the bytes and bits are counted differently, we must adjust the offset. */ if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) - offset); pos %= GET_MODE_BITSIZE (wanted_mode); newmem = gen_rtx_MEM (wanted_mode, plus_constant (XEXP (tem, 0), offset)); RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); MEM_COPY_ATTRIBUTES (newmem, tem); /* Make the change and see if the insn remains valid. */ INSN_CODE (insn) = -1; XEXP (x, 0) = newmem; XEXP (x, 2) = GEN_INT (pos); if (recog_memoized (insn) >= 0) return; /* Otherwise, restore old position. XEXP (x, 0) will be restored later. */ XEXP (x, 2) = old_pos; } } /* If we get here, the bitfield extract insn can't accept a memory reference. Copy the input into a register. */ tem1 = gen_reg_rtx (GET_MODE (tem)); emit_insn_before (gen_move_insn (tem1, tem), insn); XEXP (x, 0) = tem1; return; } break; case SUBREG: if (SUBREG_REG (x) == var) { /* If this is a special SUBREG made because VAR was promoted from a wider mode, replace it with VAR and call ourself recursively, this time saying that the object previously had its current mode (by virtue of the SUBREG). */ if (SUBREG_PROMOTED_VAR_P (x)) { *loc = var; fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements); return; } /* If this SUBREG makes VAR wider, it has become a paradoxical SUBREG with VAR in memory, but these aren't allowed at this stage of the compilation. So load VAR into a pseudo and take a SUBREG of that pseudo. */ if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var))) { replacement = find_fixup_replacement (replacements, var); if (replacement->new == 0) replacement->new = gen_reg_rtx (GET_MODE (var)); SUBREG_REG (x) = replacement->new; return; } /* See if we have already found a replacement for this SUBREG. If so, use it. Otherwise, make a MEM and see if the insn is recognized. If not, or if we should force MEM into a register, make a pseudo for this SUBREG. */ replacement = find_fixup_replacement (replacements, x); if (replacement->new) { *loc = replacement->new; return; } replacement->new = *loc = fixup_memory_subreg (x, insn, 0); INSN_CODE (insn) = -1; if (! flag_force_mem && recog_memoized (insn) >= 0) return; *loc = replacement->new = gen_reg_rtx (GET_MODE (x)); return; } break; case SET: /* First do special simplification of bit-field references. */ if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) optimize_bit_field (x, insn, 0); if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT) optimize_bit_field (x, insn, NULL_PTR); /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object into a register and then store it back out. */ if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0))) > GET_MODE_SIZE (GET_MODE (var)))) { replacement = find_fixup_replacement (replacements, var); if (replacement->new == 0) replacement->new = gen_reg_rtx (GET_MODE (var)); SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new; emit_insn_after (gen_move_insn (var, replacement->new), insn); } /* If SET_DEST is now a paradoxical SUBREG, put the result of this insn into a pseudo and store the low part of the pseudo into VAR. */ if (GET_CODE (SET_DEST (x)) == SUBREG && SUBREG_REG (SET_DEST (x)) == var && (GET_MODE_SIZE (GET_MODE (SET_DEST (x))) > GET_MODE_SIZE (GET_MODE (var)))) { SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x))); emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var), tem)), insn); break; } { rtx dest = SET_DEST (x); rtx src = SET_SRC (x); #ifdef HAVE_insv rtx outerdest = dest; #endif while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART || GET_CODE (dest) == SIGN_EXTRACT || GET_CODE (dest) == ZERO_EXTRACT) dest = XEXP (dest, 0); if (GET_CODE (src) == SUBREG) src = XEXP (src, 0); /* If VAR does not appear at the top level of the SET just scan the lower levels of the tree. */ if (src != var && dest != var) break; /* We will need to rerecognize this insn. */ INSN_CODE (insn) = -1; #ifdef HAVE_insv if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var) { /* Since this case will return, ensure we fixup all the operands here. */ fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1), insn, replacements); fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2), insn, replacements); fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x), insn, replacements); tem = XEXP (outerdest, 0); /* Clean up (SUBREG:SI (MEM:mode ...) 0) that may appear inside a ZERO_EXTRACT. This was legitimate when the MEM was a REG. */ if (GET_CODE (tem) == SUBREG && SUBREG_REG (tem) == var) tem = fixup_memory_subreg (tem, insn, 0); else tem = fixup_stack_1 (tem, insn); if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT && GET_CODE (XEXP (outerdest, 2)) == CONST_INT && ! mode_dependent_address_p (XEXP (tem, 0)) && ! MEM_VOLATILE_P (tem)) { enum machine_mode wanted_mode; enum machine_mode is_mode = GET_MODE (tem); HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2)); wanted_mode = insn_operand_mode[(int) CODE_FOR_insv][0]; if (wanted_mode == VOIDmode) wanted_mode = word_mode; /* If we have a narrower mode, we can do something. */ if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) { HOST_WIDE_INT offset = pos / BITS_PER_UNIT; rtx old_pos = XEXP (outerdest, 2); rtx newmem; if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) offset = (GET_MODE_SIZE (is_mode) - GET_MODE_SIZE (wanted_mode) - offset); pos %= GET_MODE_BITSIZE (wanted_mode); newmem = gen_rtx_MEM (wanted_mode, plus_constant (XEXP (tem, 0), offset)); RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem); MEM_COPY_ATTRIBUTES (newmem, tem); /* Make the change and see if the insn remains valid. */ INSN_CODE (insn) = -1; XEXP (outerdest, 0) = newmem; XEXP (outerdest, 2) = GEN_INT (pos); if (recog_memoized (insn) >= 0) return; /* Otherwise, restore old position. XEXP (x, 0) will be restored later. */ XEXP (outerdest, 2) = old_pos; } } /* If we get here, the bit-field store doesn't allow memory or isn't located at a constant position. Load the value into a register, do the store, and put it back into memory. */ tem1 = gen_reg_rtx (GET_MODE (tem)); emit_insn_before (gen_move_insn (tem1, tem), insn); emit_insn_after (gen_move_insn (tem, tem1), insn); XEXP (outerdest, 0) = tem1; return; } #endif /* STRICT_LOW_PART is a no-op on memory references and it can cause combinations to be unrecognizable, so eliminate it. */ if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) SET_DEST (x) = XEXP (SET_DEST (x), 0); /* A valid insn to copy VAR into or out of a register must be left alone, to avoid an infinite loop here. If the reference to VAR is by a subreg, fix that up, since SUBREG is not valid for a memref. Also fix up the address of the stack slot. Note that we must not try to recognize the insn until after we know that we have valid addresses and no (subreg (mem ...) ...) constructs, since these interfere with determining the validity of the insn. */ if ((SET_SRC (x) == var || (GET_CODE (SET_SRC (x)) == SUBREG && SUBREG_REG (SET_SRC (x)) == var)) && (GET_CODE (SET_DEST (x)) == REG || (GET_CODE (SET_DEST (x)) == SUBREG && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)) && GET_MODE (var) == promoted_mode && x == single_set (insn)) { rtx pat; replacement = find_fixup_replacement (replacements, SET_SRC (x)); if (replacement->new) SET_SRC (x) = replacement->new; else if (GET_CODE (SET_SRC (x)) == SUBREG) SET_SRC (x) = replacement->new = fixup_memory_subreg (SET_SRC (x), insn, 0); else SET_SRC (x) = replacement->new = fixup_stack_1 (SET_SRC (x), insn); if (recog_memoized (insn) >= 0) return; /* INSN is not valid, but we know that we want to copy SET_SRC (x) to SET_DEST (x) in some way. So we generate the move and see whether it requires more than one insn. If it does, we emit those insns and delete INSN. Otherwise, we an just replace the pattern of INSN; we have already verified above that INSN has no other function that to do X. */ pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); if (GET_CODE (pat) == SEQUENCE) { emit_insn_after (pat, insn); PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; } else PATTERN (insn) = pat; return; } if ((SET_DEST (x) == var || (GET_CODE (SET_DEST (x)) == SUBREG && SUBREG_REG (SET_DEST (x)) == var)) && (GET_CODE (SET_SRC (x)) == REG || (GET_CODE (SET_SRC (x)) == SUBREG && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)) && GET_MODE (var) == promoted_mode && x == single_set (insn)) { rtx pat; if (GET_CODE (SET_DEST (x)) == SUBREG) SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 0); else SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn); if (recog_memoized (insn) >= 0) return; pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); if (GET_CODE (pat) == SEQUENCE) { emit_insn_after (pat, insn); PUT_CODE (insn, NOTE); NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; NOTE_SOURCE_FILE (insn) = 0; } else PATTERN (insn) = pat; return; } /* Otherwise, storing into VAR must be handled specially by storing into a temporary and copying that into VAR with a new insn after this one. Note that this case will be used when storing into a promoted scalar since the insn will now have different modes on the input and output and hence will be invalid (except for the case of setting it to a constant, which does not need any change if it is valid). We generate extra code in that case, but combine.c will eliminate it. */ if (dest == var) { rtx temp; rtx fixeddest = SET_DEST (x); /* STRICT_LOW_PART can be discarded, around a MEM. */ if (GET_CODE (fixeddest) == STRICT_LOW_PART) fixeddest = XEXP (fixeddest, 0); /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */ if (GET_CODE (fixeddest) == SUBREG) { fixeddest = fixup_memory_subreg (fixeddest, insn, 0); promoted_mode = GET_MODE (fixeddest); } else fixeddest = fixup_stack_1 (fixeddest, insn); temp = gen_reg_rtx (promoted_mode); emit_insn_after (gen_move_insn (fixeddest, gen_lowpart (GET_MODE (fixeddest), temp)), insn); SET_DEST (x) = temp; } } default: break; } /* Nothing special about this RTX; fix its operands. */ fmt = GET_RTX_FORMAT (code); for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) { if (fmt[i] == 'e') fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements); if (fmt[i] == 'E') { register int j; for (j = 0; j < XVECLEN (x, i); j++) fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j), insn, replacements); } } } /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)), return an rtx (MEM:m1 newaddr) which is equivalent. If any insns must be emitted to compute NEWADDR, put them before INSN. UNCRITICAL nonzero means accept paradoxical subregs. This is used for subregs found inside REG_NOTES. */ static rtx fixup_memory_subreg (x, insn, uncritical) rtx x; rtx insn; int uncritical; { int offset = SUBREG_WORD (x) * UNITS_PER_WORD; rtx addr = XEXP (SUBREG_REG (x), 0); enum machine_mode mode = GET_MODE (x); rtx result; /* Paradoxical SUBREGs are usually invalid during RTL generation. */ if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) && ! uncritical) abort (); if (BYTES_BIG_ENDIAN) offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))); addr = plus_constant (addr, offset); if (!flag_force_addr && memory_address_p (mode, addr)) /* Shortcut if no insns need be emitted. */ return change_address (SUBREG_REG (x), mode, addr); start_sequence (); result = change_address (SUBREG_REG (x), mode, addr); emit_insn_before (gen_sequence (), insn); end_sequence (); return result; } /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X. Replace subexpressions of X in place. If X itself is a (SUBREG (MEM ...) ...), return the replacement expression. Otherwise return X, with its contents possibly altered. If any insns must be emitted to compute NEWADDR, put them before INSN. UNCRITICAL is as in fixup_memory_subreg. */ static rtx walk_fixup_memory_subreg (x, insn, uncritical) register rtx x; rtx insn; int uncritical; { register enum rtx_code code; register char *fmt; register int i; if (x == 0) return 0; code = GET_CODE (x); if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) return fixup_memory_subreg (x, insn, uncritical); /* Nothing special about this RTX; fix its operands. */ fmt = GET_RTX_FORMAT (code); for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) { if (fmt[i] == 'e') XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, uncritical); if (fmt[i] == 'E') { register int j; for (j = 0; j < XVECLEN (x, i); j++) XVECEXP (x, i, j) = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, uncritical); } } return x; } /* For each memory ref within X, if it refers to a stack slot with an out of range displacement, put the address in a temp register (emitting new insns before INSN to load these registers) and alter the memory ref to use that register. Replace each such MEM rtx with a copy, to avoid clobberage. */ static rtx fixup_stack_1 (x, insn) rtx x; rtx insn; { register int i; register RTX_CODE code = GET_CODE (x); register char *fmt; if (code == MEM) { register rtx ad = XEXP (x, 0); /* If we have address of a stack slot but it's not valid (displacement is too large), compute the sum in a register. */ if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 0)) == REG && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER) || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM #endif || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM || XEXP (ad, 0) == current_function_internal_arg_pointer) && GET_CODE (XEXP (ad, 1)) == CONST_INT) { rtx temp, seq; if (memory_address_p (GET_MODE (x), ad)) return x; start_sequence (); temp = copy_to_reg (ad); seq = gen_sequence (); end_sequence (); emit_insn_before (seq, insn); return change_address (x, VOIDmode, temp); } return x; } fmt = GET_RTX_FORMAT (code); for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) { if (fmt[i] == 'e') XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn); if (fmt[i] == 'E') { register int j; for (j = 0; j < XVECLEN (x, i); j++) XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn); } } return x; } /* Optimization: a bit-field instruction whose field happens to be a byte or halfword in memory can be changed to a move instruction. We call here when INSN is an insn to examine or store into a bit-field. BODY is the SET-rtx to be altered. EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0. (Currently this is called only from function.c, and EQUIV_MEM is always 0.) */ static void optimize_bit_field (body, insn, equiv_mem) rtx body; rtx insn; rtx *equiv_mem; { register rtx bitfield; int destflag; rtx seq = 0; enum machine_mode mode; if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT) bitfield = SET_DEST (body), destflag = 1; else bitfield = SET_SRC (body), destflag = 0; /* First check that the field being stored has constant size and position and is in fact a byte or halfword suitably aligned. */ if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT && GET_CODE (XEXP (bitfield, 2)) == CONST_INT && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1)) != BLKmode) && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0) { register rtx memref = 0; /* Now check that the containing word is memory, not a register, and that it is safe to change the machine mode. */ if (GET_CODE (XEXP (bitfield, 0)) == MEM) memref = XEXP (bitfield, 0); else if (GET_CODE (XEXP (bitfield, 0)) == REG && equiv_mem != 0) memref = equiv_mem[REGNO (XEXP (bitfield, 0))]; else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM) memref = SUBREG_REG (XEXP (bitfield, 0)); else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG && equiv_mem != 0 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG) memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]; if (memref && ! mode_dependent_address_p (XEXP (memref, 0)) && ! MEM_VOLATILE_P (memref)) { /* Now adjust the address, first for any subreg'ing that we are now getting rid of, and then for which byte of the word is wanted. */ HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2)); rtx insns; /* Adjust OFFSET to count bits from low-address byte. */ if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN) offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0))) - offset - INTVAL (XEXP (bitfield, 1))); /* Adjust OFFSET to count bytes from low-address byte. */ offset /= BITS_PER_UNIT; if (GET_CODE (XEXP (bitfield, 0)) == SUBREG) { offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD; if (BYTES_BIG_ENDIAN) offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0)))) - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (memref)))); } start_sequence (); memref = change_address (memref, mode, plus_constant (XEXP (memref, 0), offset)); insns = get_insns (); end_sequence (); emit_insns_before (insns, insn); /* Store this memory reference where we found the bit field reference. */ if (destflag) { validate_change (insn, &SET_DEST (body), memref, 1); if (! CONSTANT_ADDRESS_P (SET_SRC (body))) { rtx src = SET_SRC (body); while (GET_CODE (src) == SUBREG && SUBREG_WORD (src) == 0) src = SUBREG_REG (src); if (GET_MODE (src) != GET_MODE (memref)) src = gen_lowpart (GET_MODE (memref), SET_SRC (body)); validate_change (insn, &SET_SRC (body), src, 1); } else if (GET_MODE (SET_SRC (body)) != VOIDmode && GET_MODE (SET_SRC (body)) != GET_MODE (memref)) /* This shouldn't happen because anything that didn't have one of these modes should have got converted explicitly and then referenced through a subreg. This is so because the original bit-field was handled by agg_mode and so its tree structure had the same mode that memref now has. */ abort (); } else { rtx dest = SET_DEST (body); while (GET_CODE (dest) == SUBREG && SUBREG_WORD (dest) == 0 && (GET_MODE_CLASS (GET_MODE (dest)) == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))) && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD)) dest = SUBREG_REG (dest); validate_change (insn, &SET_DEST (body), dest, 1); if (GET_MODE (dest) == GET_MODE (memref)) validate_change (insn, &SET_SRC (body), memref, 1); else { /* Convert the mem ref to the destination mode. */ rtx newreg = gen_reg_rtx (GET_MODE (dest)); start_sequence (); convert_move (newreg, memref, GET_CODE (SET_SRC (body)) == ZERO_EXTRACT); seq = get_insns (); end_sequence (); validate_change (insn, &SET_SRC (body), newreg, 1); } } /* See if we can convert this extraction or insertion into a simple move insn. We might not be able to do so if this was, for example, part of a PARALLEL. If we succeed, write out any needed conversions. If we fail, it is hard to guess why we failed, so don't do anything special; just let the optimization be suppressed. */ if (apply_change_group () && seq) emit_insns_before (seq, insn); } } } /* These routines are responsible for converting virtual register references to the actual hard register references once RTL generation is complete. The following four variables are used for communication between the routines. They contain the offsets of the virtual registers from their respective hard registers. */ static int in_arg_offset; static int var_offset; static int dynamic_offset; static int out_arg_offset; static int cfa_offset; /* In most machines, the stack pointer register is equivalent to the bottom of the stack. */ #ifndef STACK_POINTER_OFFSET #define STACK_POINTER_OFFSET 0 #endif /* If not defined, pick an appropriate default for the offset of dynamically allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS, REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */ #ifndef STACK_DYNAMIC_OFFSET #ifdef ACCUMULATE_OUTGOING_ARGS /* The bottom of the stack points to the actual arguments. If REG_PARM_STACK_SPACE is defined, this includes the space for the register parameters. However, if OUTGOING_REG_PARM_STACK space is not defined, stack space for register parameters is not pushed by the caller, but rather part of the fixed stack areas and hence not included in `current_function_outgoing_args_size'. Nevertheless, we must allow for it when allocating stack dynamic objects. */ #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) #define STACK_DYNAMIC_OFFSET(FNDECL) \ (current_function_outgoing_args_size \ + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET)) #else #define STACK_DYNAMIC_OFFSET(FNDECL) \ (current_function_outgoing_args_size + (STACK_POINTER_OFFSET)) #endif #else #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET #endif #endif /* On a few machines, the CFA coincides with the arg pointer. */ #ifndef ARG_POINTER_CFA_OFFSET #define ARG_POINTER_CFA_OFFSET 0 #endif /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its address taken. DECL is the decl for the object stored in the register, for later use if we do need to force REG into the stack. REG is overwritten by the MEM like in put_reg_into_stack. */ rtx gen_mem_addressof (reg, decl) rtx reg; tree decl; { tree type = TREE_TYPE (decl); rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), REGNO (reg)); SET_ADDRESSOF_DECL (r, decl); /* If the original REG was a user-variable, then so is the REG whose address is being taken. */ REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg); XEXP (reg, 0) = r; PUT_CODE (reg, MEM); PUT_MODE (reg, DECL_MODE (decl)); MEM_VOLATILE_P (reg) = TREE_SIDE_EFFECTS (decl); MEM_SET_IN_STRUCT_P (reg, AGGREGATE_TYPE_P (type)); MEM_ALIAS_SET (reg) = get_alias_set (decl); if (TREE_USED (decl) || DECL_INITIAL (decl) != 0) fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), 0); return reg; } /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */ void flush_addressof (decl) tree decl; { if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL) && DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == MEM && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG) put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0); } /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */ static void put_addressof_into_stack (r, ht) rtx r; struct hash_table *ht; { tree decl = ADDRESSOF_DECL (r); rtx reg = XEXP (r, 0); if (GET_CODE (reg) != REG) abort (); put_reg_into_stack (0, reg, TREE_TYPE (decl), GET_MODE (reg), DECL_MODE (decl), TREE_SIDE_EFFECTS (decl), ADDRESSOF_REGNO (r), TREE_USED (decl) || DECL_INITIAL (decl) != 0, ht); } /* List of replacements made below in purge_addressof_1 when creating bitfield insertions. */ static rtx purge_bitfield_addressof_replacements; /* List of replacements made below in purge_addressof_1 for patterns (MEM (ADDRESSOF (REG ...))). The key of the list entry is the corresponding (ADDRESSOF (REG ...)) and value is a substitution for the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not enough in complex cases, e.g. when some field values can be extracted by usage MEM with narrower mode. */ static rtx purge_addressof_replacements; /* Helper function for purge_addressof. See if the rtx expression at *LOC in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into the stack. */ static void purge_addressof_1 (loc, insn, force, store, ht) rtx *loc; rtx insn; int force, store; struct hash_table *ht; { rtx x; RTX_CODE code; int i, j; char *fmt; /* Re-start here to avoid recursion in common cases. */ restart: x = *loc; if (x == 0) return; code = GET_CODE (x); if (code == ADDRESSOF && GET_CODE (XEXP (x, 0)) == MEM) { rtx insns; /* We must create a copy of the rtx because it was created by overwriting a REG rtx which is always shared. */ rtx sub = copy_rtx (XEXP (XEXP (x, 0), 0)); if (validate_change (insn, loc, sub, 0) || validate_replace_rtx (x, sub, insn)) return; start_sequence (); sub = force_operand (sub, NULL_RTX); if (! validate_change (insn, loc, sub, 0) && ! validate_replace_rtx (x, sub, insn)) abort (); insns = gen_sequence (); end_sequence (); emit_insn_before (insns, insn); return; } else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force) { rtx sub = XEXP (XEXP (x, 0), 0); rtx sub2; if (GET_CODE (sub) == MEM) { sub2 = gen_rtx_MEM (GET_MODE (x), copy_rtx (XEXP (sub, 0))); MEM_COPY_ATTRIBUTES (sub2, sub); RTX_UNCHANGING_P (sub2) = RTX_UNCHANGING_P (sub); sub = sub2; } if (GET_CODE (sub) == REG && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)) { put_addressof_into_stack (XEXP (x, 0), ht); return; } else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub)) { int size_x, size_sub; if (!insn) { /* When processing REG_NOTES look at the list of replacements done on the insn to find the register that X was replaced by. */ rtx tem; for (tem = purge_bitfield_addressof_replacements; tem != NULL_RTX; tem = XEXP (XEXP (tem, 1), 1)) if (rtx_equal_p (x, XEXP (tem, 0))) { *loc = XEXP (XEXP (tem, 1), 0); return; } /* See comment for purge_addressof_replacements. */ for (tem = purge_addressof_replacements; tem != NULL_RTX; tem = XEXP (XEXP (tem, 1), 1)) if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) { rtx z = XEXP (XEXP (tem, 1), 0); if (GET_MODE (x) == GET_MODE (z) || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG)) abort (); /* It can happen that the note may speak of things in a wider (or just different) mode than the code did. This is especially true of REG_RETVAL. */ if (GET_CODE (z) == SUBREG && SUBREG_WORD (z) == 0) z = SUBREG_REG (z); if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD && (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (z)))) { /* This can occur as a result in invalid pointer casts, e.g. float f; ... *(long long int *)&f. ??? We could emit a warning here, but without a line number that wouldn't be very helpful. */ z = gen_rtx_SUBREG (GET_MODE (x), z, 0); } else z = gen_lowpart (GET_MODE (x), z); *loc = z; return; } /* There should always be such a replacement. */ abort (); } size_x = GET_MODE_BITSIZE (GET_MODE (x)); size_sub = GET_MODE_BITSIZE (GET_MODE (sub)); /* Don't even consider working with paradoxical subregs, or the moral equivalent seen here. */ if (size_x <= size_sub && int_mode_for_mode (GET_MODE (sub)) != BLKmode) { /* Do a bitfield insertion to mirror what would happen in memory. */ rtx val, seq; if (store) { rtx p = PREV_INSN (insn); start_sequence (); val = gen_reg_rtx (GET_MODE (x)); if (! validate_change (insn, loc, val, 0)) { /* Discard the current sequence and put the ADDRESSOF on stack. */ end_sequence (); goto give_up; } seq = gen_sequence (); end_sequence (); emit_insn_before (seq, insn); compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), insn, ht); start_sequence (); store_bit_field (sub, size_x, 0, GET_MODE (x), val, GET_MODE_SIZE (GET_MODE (sub)), GET_MODE_SIZE (GET_MODE (sub))); /* Make sure to unshare any shared rtl that store_bit_field might have created. */ for (p = get_insns(); p; p = NEXT_INSN (p)) { reset_used_flags (PATTERN (p)); reset_used_flags (REG_NOTES (p)); reset_used_flags (LOG_LINKS (p)); } unshare_all_rtl (get_insns ()); seq = gen_sequence (); end_sequence (); p = emit_insn_after (seq, insn); if (NEXT_INSN (insn)) compute_insns_for_mem (NEXT_INSN (insn), p ? NEXT_INSN (p) : NULL_RTX, ht); } else { rtx p = PREV_INSN (insn); start_sequence (); val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX, GET_MODE (x), GET_MODE (x), GET_MODE_SIZE (GET_MODE (sub)), GET_MODE_SIZE (GET_MODE (sub))); if (! validate_change (insn, loc, val, 0)) { /* Discard the current sequence and put the ADDRESSOF on stack. */ end_sequence (); goto give_up; } seq = gen_sequence (); end_sequence (); emit_insn_before (seq, insn); compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), insn, ht); } /* Remember the replacement so that the same one can be done on the REG_NOTES. */ purge_bitfield_addressof_replacements = gen_rtx_EXPR_LIST (VOIDmode, x, gen_rtx_EXPR_LIST (VOIDmode, val, purge_bitfield_addressof_replacements)); /* We replaced with a reg -- all done. */ return; } } else if (validate_change (insn, loc, sub, 0)) { /* Remember the replacement so that the same one can be done on the REG_NOTES. */ if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG) { rtx tem; for (tem = purge_addressof_replacements; tem != NULL_RTX; tem = XEXP (XEXP (tem, 1), 1)) if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) { XEXP (XEXP (tem, 1), 0) = sub; return; } purge_addressof_replacements = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0), gen_rtx_EXPR_LIST (VOIDmode, sub, purge_addressof_replacements)); return; } goto restart; } give_up:; /* else give up and put it into the stack */ } else if (code == ADDRESSOF) { put_addressof_into_stack (x, ht); return; } else if (code == SET) { purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht); purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht); return; } /* Scan all subexpressions. */ fmt = GET_RTX_FORMAT (code); for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) { if (*fmt == 'e') purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht); else if (*fmt == 'E') for (j = 0; j < XVECLEN (x, i); j++) purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht); } } /* Return a new hash table entry in HT. */ static struct hash_entry * insns_for_mem_newfunc (he, ht, k) struct hash_entry *he; struct hash_table *ht; hash_table_key k ATTRIBUTE_UNUSED; { struct insns_for_mem_entry *ifmhe; if (he) return he; ifmhe = ((struct insns_for_mem_entry *) hash_allocate (ht, sizeof (struct insns_for_mem_entry))); ifmhe->insns = NULL_RTX; return &ifmhe->he; } /* Return a hash value for K, a REG. */ static unsigned long insns_for_mem_hash (k) hash_table_key k; { /* K is really a RTX. Just use the address as the hash value. */ return (unsigned long) k; } /* Return non-zero if K1 and K2 (two REGs) are the same. */ static boolean insns_for_mem_comp (k1, k2) hash_table_key k1; hash_table_key k2; { return k1 == k2; } struct insns_for_mem_walk_info { /* The hash table that we are using to record which INSNs use which MEMs. */ struct hash_table *ht; /* The INSN we are currently proessing. */ rtx insn; /* Zero if we are walking to find ADDRESSOFs, one if we are walking to find the insns that use the REGs in the ADDRESSOFs. */ int pass; }; /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG that might be used in an ADDRESSOF expression, record this INSN in the hash table given by DATA (which is really a pointer to an insns_for_mem_walk_info structure). */ static int insns_for_mem_walk (r, data) rtx *r; void *data; { struct insns_for_mem_walk_info *ifmwi = (struct insns_for_mem_walk_info *) data; if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF && GET_CODE (XEXP (*r, 0)) == REG) hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0); else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG) { /* Lookup this MEM in the hashtable, creating it if necessary. */ struct insns_for_mem_entry *ifme = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht, *r, /*create=*/0, /*copy=*/0); /* If we have not already recorded this INSN, do so now. Since we process the INSNs in order, we know that if we have recorded it it must be at the front of the list. */ if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn)) { /* We do the allocation on the same obstack as is used for the hash table since this memory will not be used once the hash table is deallocated. */ push_obstacks (&ifmwi->ht->memory, &ifmwi->ht->memory); ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn, ifme->insns); pop_obstacks (); } } return 0; } /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use which REGs in HT. */ static void compute_insns_for_mem (insns, last_insn, ht) rtx insns; rtx last_insn; struct hash_table *ht; { rtx insn; struct insns_for_mem_walk_info ifmwi; ifmwi.ht = ht; for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass) for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn)) if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') { ifmwi.insn = insn; for_each_rtx (&insn, insns_for_mem_walk, &ifmwi); } } /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining (MEM (ADDRESSOF)) patterns, and force any needed registers into the stack. */ void purge_addressof (insns) rtx insns; { rtx insn; struct hash_table ht; /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That requires a fixup pass over the instruction stream to correct INSNs that depended on the REG being a REG, and not a MEM. But, these fixup passes are slow. Furthermore, more MEMs are not mentioned in very many instructions. So, we speed up the process by pre-calculating which REGs occur in which INSNs; that allows us to perform the fixup passes much more quickly. */ hash_table_init (&ht, insns_for_mem_newfunc, insns_for_mem_hash, insns_for_mem_comp); compute_insns_for_mem (insns, NULL_RTX, &ht); for (insn = insns; insn; insn = NEXT_INSN (insn)) if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN) { purge_addressof_1 (&PATTERN (insn), insn, asm_noperands (PATTERN (insn)) > 0, 0, &ht); purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht); } /* Clean up. */ hash_table_free (&ht); purge_bitfield_addressof_replacements = 0; purge_addressof_replacements = 0; } /* Pass through the INSNS of function FNDECL and convert virtual register references to hard register references. */ void instantiate_virtual_regs (fndecl, insns) tree fndecl; rtx insns; { rtx insn; int i; /* Compute the offsets to use for this function. */ in_arg_offset = FIRST_PARM_OFFSET (fndecl); var_offset = STARTING_FRAME_OFFSET; dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl); out_arg_offset = STACK_POINTER_OFFSET; cfa_offset = ARG_POINTER_CFA_OFFSET; /* Scan all variables and parameters of this function. For each that is in memory, instantiate all virtual registers if the result is a valid address. If not, we do it later. That will handle most uses of virtual regs on many machines. */ instantiate_decls (fndecl, 1); /* Initialize recognition, indicating that volatile is OK. */ init_recog (); /* Scan through all the insns, instantiating every virtual register still present. */ for (insn = insns; insn; insn = NEXT_INSN (insn)) if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN) { instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1); instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0); } /* Instantiate the stack slots for the parm registers, for later use in addressof elimination. */ for (i = 0; i < max_parm_reg; ++i) if (parm_reg_stack_loc[i]) instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0); /* Now instantiate the remaining register equivalences for debugging info. These will not be valid addresses. */ instantiate_decls (fndecl, 0); /* Indicate that, from now on, assign_stack_local should use frame_pointer_rtx. */ virtuals_instantiated = 1; } /* Scan all decls in FNDECL (both variables and parameters) and instantiate all virtual registers in their DECL_RTL's. If VALID_ONLY, do this only if the resulting address is still valid. Otherwise, always do it. */ static void instantiate_decls (fndecl, valid_only) tree fndecl; int valid_only; { tree decl; if (DECL_SAVED_INSNS (fndecl)) /* When compiling an inline function, the obstack used for rtl allocation is the maybepermanent_obstack. Calling `resume_temporary_allocation' switches us back to that obstack while we process this function's parameters. */ resume_temporary_allocation (); /* Process all parameters of the function. */ for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) { HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); instantiate_decl (DECL_RTL (decl), size, valid_only); /* If the parameter was promoted, then the incoming RTL mode may be larger than the declared type size. We must use the larger of the two sizes. */ size = MAX (GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))), size); instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only); } /* Now process all variables defined in the function or its subblocks. */ instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only); if (DECL_INLINE (fndecl) || DECL_DEFER_OUTPUT (fndecl)) { /* Save all rtl allocated for this function by raising the high-water mark on the maybepermanent_obstack. */ preserve_data (); /* All further rtl allocation is now done in the current_obstack. */ rtl_in_current_obstack (); } } /* Subroutine of instantiate_decls: Process all decls in the given BLOCK node and all its subblocks. */ static void instantiate_decls_1 (let, valid_only) tree let; int valid_only; { tree t; for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) instantiate_decl (DECL_RTL (t), int_size_in_bytes (TREE_TYPE (t)), valid_only); /* Process all subblocks. */ for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t)) instantiate_decls_1 (t, valid_only); } /* Subroutine of the preceding procedures: Given RTL representing a decl and the size of the object, do any instantiation required. If VALID_ONLY is non-zero, it means that the RTL should only be changed if the new address is valid. */ static void instantiate_decl (x, size, valid_only) rtx x; int size; int valid_only; { enum machine_mode mode; rtx addr; /* If this is not a MEM, no need to do anything. Similarly if the address is a constant or a register that is not a virtual register. */ if (x == 0 || GET_CODE (x) != MEM) return; addr = XEXP (x, 0); if (CONSTANT_P (addr) || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG) || (GET_CODE (addr) == REG && (REGNO (addr) < FIRST_VIRTUAL_REGISTER || REGNO (addr) > LAST_VIRTUAL_REGISTER))) return; /* If we should only do this if the address is valid, copy the address. We need to do this so we can undo any changes that might make the address invalid. This copy is unfortunate, but probably can't be avoided. */ if (valid_only) addr = copy_rtx (addr); instantiate_virtual_regs_1 (&addr, NULL_RTX, 0); if (valid_only) { /* Now verify that the resulting address is valid for every integer or floating-point mode up to and including SIZE bytes long. We do this since the object might be accessed in any mode and frame addresses are shared. */ for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode && GET_MODE_SIZE (mode) <= size; mode = GET_MODE_WIDER_MODE (mode)) if (! memory_address_p (mode, addr)) return; for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode && GET_MODE_SIZE (mode) <= size; mode = GET_MODE_WIDER_MODE (mode)) if (! memory_address_p (mode, addr)) return; } /* Put back the address now that we have updated it and we either know it is valid or we don't care whether it is valid. */ XEXP (x, 0) = addr; } /* Given a pointer to a piece of rtx and an optional pointer to the containing object, instantiate any virtual registers present in it. If EXTRA_INSNS, we always do the replacement and generate any extra insns before OBJECT. If it zero, we do nothing if replacement is not valid. Return 1 if we either had nothing to do or if we were able to do the needed replacement. Return 0 otherwise; we only return zero if EXTRA_INSNS is zero. We first try some simple transformations to avoid the creation of extra pseudos. */ static int instantiate_virtual_regs_1 (loc, object, extra_insns) rtx *loc; rtx object; int extra_insns; { rtx x; RTX_CODE code; rtx new = 0; HOST_WIDE_INT offset = 0; rtx temp; rtx seq; int i, j; char *fmt; /* Re-start here to avoid recursion in common cases. */ restart: x = *loc; if (x == 0) return 1; code = GET_CODE (x); /* Check for some special cases. */ switch (code) { case CONST_INT: case CONST_DOUBLE: case CONST: case SYMBOL_REF: case CODE_LABEL: case PC: case CC0: case ASM_INPUT: case ADDR_VEC: case ADDR_DIFF_VEC: case RETURN: return 1; case SET: /* We are allowed to set the virtual registers. This means that the actual register should receive the source minus the appropriate offset. This is used, for example, in the handling of non-local gotos. */ if (SET_DEST (x) == virtual_incoming_args_rtx) new = arg_pointer_rtx, offset = - in_arg_offset; else if (SET_DEST (x) == virtual_stack_vars_rtx) new = frame_pointer_rtx, offset = - var_offset; else if (SET_DEST (x) == virtual_stack_dynamic_rtx) new = stack_pointer_rtx, offset = - dynamic_offset; else if (SET_DEST (x) == virtual_outgoing_args_rtx) new = stack_pointer_rtx, offset = - out_arg_offset; else if (SET_DEST (x) == virtual_cfa_rtx) new = arg_pointer_rtx, offset = - cfa_offset; if (new) { /* The only valid sources here are PLUS or REG. Just do the simplest possible thing to handle them. */ if (GET_CODE (SET_SRC (x)) != REG && GET_CODE (SET_SRC (x)) != PLUS) abort (); start_sequence (); if (GET_CODE (SET_SRC (x)) != REG) temp = force_operand (SET_SRC (x), NULL_RTX); else temp = SET_SRC (x); temp = force_operand (plus_constant (temp, offset), NULL_RTX); seq = get_insns (); end_sequence (); emit_insns_before (seq, object); SET_DEST (x) = new; if (! validate_change (object, &SET_SRC (x), temp, 0) || ! extra_insns) abort (); return 1; } instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns); loc = &SET_SRC (x); goto restart; case PLUS: /* Handle special case of virtual register plus constant. */ if (CONSTANT_P (XEXP (x, 1))) { rtx old, new_offset; /* Check for (plus (plus VIRT foo) (const_int)) first. */ if (GET_CODE (XEXP (x, 0)) == PLUS) { rtx inner = XEXP (XEXP (x, 0), 0); if (inner == virtual_incoming_args_rtx) new = arg_pointer_rtx, offset = in_arg_offset; else if (inner == virtual_stack_vars_rtx) new = frame_pointer_rtx, offset = var_offset; else if (inner == virtual_stack_dynamic_rtx) new = stack_pointer_rtx, offset = dynamic_offset; else if (inner == virtual_outgoing_args_rtx) new = stack_pointer_rtx, offset = out_arg_offset; else if (inner == virtual_cfa_rtx) new = arg_pointer_rtx, offset = cfa_offset; else { loc = &XEXP (x, 0); goto restart; } instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object, extra_insns); new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1)); } else if (XEXP (x, 0) == virtual_incoming_args_rtx) new = arg_pointer_rtx, offset = in_arg_offset; else if (XEXP (x, 0) == virtual_stack_vars_rtx) new = frame_pointer_rtx, offset = var_offset; else if (XEXP (x, 0) == virtual_stack_dynamic_rtx) new = stack_pointer_rtx, offset = dynamic_offset; else if (XEXP (x, 0) == virtual_outgoing_args_rtx) new = stack_pointer_rtx, offset = out_arg_offset; else if (XEXP (x, 0) == virtual_cfa_rtx) new = arg_pointer_rtx, offset = cfa_offset; else { /* We know the second operand is a constant. Unless the first operand is a REG (which has been already checked), it needs to be checked. */ if (GET_CODE (XEXP (x, 0)) != REG) { loc = &XEXP (x, 0); goto restart; } return 1; } new_offset = plus_constant (XEXP (x, 1), offset); /* If the new constant is zero, try to replace the sum with just the register. */ if (new_offset == const0_rtx && validate_change (object, loc, new, 0)) return 1; /* Next try to replace the register and new offset. There are two changes to validate here and we can't assume that in the case of old offset equals new just changing the register will yield a valid insn. In the interests of a little efficiency, however, we only call validate change once (we don't queue up the changes and then call apply_change_group). */ old = XEXP (x, 0); if (offset == 0 ? ! validate_change (object, &XEXP (x, 0), new, 0) : (XEXP (x, 0) = new, ! validate_change (object, &XEXP (x, 1), new_offset, 0))) { if (! extra_insns) { XEXP (x, 0) = old; return 0; } /* Otherwise copy the new constant into a register and replace constant with that register. */ temp = gen_reg_rtx (Pmode); XEXP (x, 0) = new; if (validate_change (object, &XEXP (x, 1), temp, 0)) emit_insn_before (gen_move_insn (temp, new_offset), object); else { /* If that didn't work, replace this expression with a register containing the sum. */ XEXP (x, 0) = old; new = gen_rtx_PLUS (Pmode, new, new_offset); start_sequence (); temp = force_operand (new, NULL_RTX); seq = get_insns (); end_sequence (); emit_insns_before (seq, object); if (! validate_change (object, loc, temp, 0) && ! validate_replace_rtx (x, temp, object)) abort (); } } return 1; } /* Fall through to generic two-operand expression case. */ case EXPR_LIST: case CALL: case COMPARE: case MINUS: case MULT: case DIV: case UDIV: case MOD: case UMOD: case AND: case IOR: case XOR: case ROTATERT: case ROTATE: case ASHIFTRT: case LSHIFTRT: case ASHIFT: case NE: case EQ: case GE: case GT: case GEU: case GTU: case LE: case LT: case LEU: case LTU: if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1))) instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns); loc = &XEXP (x, 0); goto restart; case MEM: /* Most cases of MEM that convert to valid addresses have already been handled by our scan of decls. The only special handling we need here is to make a copy of the rtx to ensure it isn't being shared if we have to change it to a pseudo. If the rtx is a simple reference to an address via a virtual register, it can potentially be shared. In such cases, first try to make it a valid address, which can also be shared. Otherwise, copy it and proceed normally. First check for common cases that need no processing. These are usually due to instantiation already being done on a previous instance of a shared rtx. */ temp = XEXP (x, 0); if (CONSTANT_ADDRESS_P (temp) #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM || temp == arg_pointer_rtx #endif #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM || temp == hard_frame_pointer_rtx #endif || temp == frame_pointer_rtx) return 1; if (GET_CODE (temp) == PLUS && CONSTANT_ADDRESS_P (XEXP (temp, 1)) && (XEXP (temp, 0) == frame_pointer_rtx #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM || XEXP (temp, 0) == hard_frame_pointer_rtx #endif #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM || XEXP (temp, 0) == arg_pointer_rtx #endif )) return 1; if (temp == virtual_stack_vars_rtx || temp == virtual_incoming_args_rtx || (GET_CODE (temp) == PLUS && CONSTANT_ADDRESS_P (XEXP (temp, 1)) && (XEXP (temp, 0) == virtual_stack_vars_rtx || XEXP (temp, 0) == virtual_incoming_args_rtx))) { /* This MEM may be shared. If the substitution can be done without the need to generate new pseudos, we want to do it in place so all copies of the shared rtx benefit. The call below will only make substitutions if the resulting address is still valid. Note that we cannot pass X as the object in the recursive call since the insn being processed may not allow all valid addresses. However, if we were not passed on object, we can only modify X without copying it if X will have a valid address. ??? Also note that this can still lose if OBJECT is an insn that has less restrictions on an address that some other insn. In that case, we will modify the shared address. This case doesn't seem very likely, though. One case where this could happen is in the case of a USE or CLOBBER reference, but we take care of that below. */ if (instantiate_virtual_regs_1 (&XEXP (x, 0), object ? object : x, 0)) return 1; /* Otherwise make a copy and process that copy. We copy the entire RTL expression since it might be a PLUS which could also be shared. */ *loc = x = copy_rtx (x); } /* Fall through to generic unary operation case. */ case SUBREG: case STRICT_LOW_PART: case NEG: case NOT: case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC: case SIGN_EXTEND: case ZERO_EXTEND: case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: case FLOAT: case FIX: case UNSIGNED_FIX: case UNSIGNED_FLOAT: case ABS: case SQRT: case FFS: /* These case either have just one operand or we know that we need not check the rest of the operands. */ loc = &XEXP (x, 0); goto restart; case USE: case CLOBBER: /* If the operand is a MEM, see if the change is a valid MEM. If not, go ahead and make the invalid one, but do it to a copy. For a REG, just make the recursive call, since there's no chance of a problem. */ if ((GET_CODE (XEXP (x, 0)) == MEM && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0), 0)) || (GET_CODE (XEXP (x, 0)) == REG && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0))) return 1; XEXP (x, 0) = copy_rtx (XEXP (x, 0)); loc = &XEXP (x, 0); goto restart; case REG: /* Try to replace with a PLUS. If that doesn't work, compute the sum in front of this insn and substitute the temporary. */ if (x == virtual_incoming_args_rtx) new = arg_pointer_rtx, offset = in_arg_offset; else if (x == virtual_stack_vars_rtx) new = frame_pointer_rtx, offset = var_offset; else if (x == virtual_stack_dynamic_rtx) new = stack_pointer_rtx, offset = dynamic_offset; else if (x == virtual_outgoing_args_rtx) new = stack_pointer_rtx, offset = out_arg_offset; else if (x == virtual_cfa_rtx) new = arg_pointer_rtx, offset = cfa_offset; if (new) { temp = plus_constant (new, offset); if (!validate_change (object, loc, temp, 0)) { if (! extra_insns) return 0; start_sequence (); temp = force_operand (temp, NULL_RTX); seq = get_insns (); end_sequence (); emit_insns_before (seq, object); if (! validate_change (object, loc, temp, 0) && ! validate_replace_rtx (x, temp, object)) abort (); } } return 1; case ADDRESSOF: if (GET_CODE (XEXP (x, 0)) == REG) return 1; else if (GET_CODE (XEXP (x, 0)) == MEM) { /* If we have a (addressof (mem ..)), do any instantiation inside since we know we'll be making the inside valid when we finally remove the ADDRESSOF. */ instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0); return 1; } break; default: break; } /* Scan all subexpressions. */ fmt = GET_RTX_FORMAT (code); for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) if (*fmt == 'e') { if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns)) return 0; } else if (*fmt == 'E') for (j = 0; j < XVECLEN (x, i); j++) if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object, extra_insns)) return 0; return 1; } /* Optimization: assuming this function does not receive nonlocal gotos, delete the handlers for such, as well as the insns to establish and disestablish them. */ static void delete_handlers () { rtx insn; for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) { /* Delete the handler by turning off the flag that would prevent jump_optimize from deleting it. Also permit deletion of the nonlocal labels themselves if nothing local refers to them. */ if (GET_CODE (insn) == CODE_LABEL) { tree t, last_t; LABEL_PRESERVE_P (insn) = 0; /* Remove it from the nonlocal_label list, to avoid confusing flow. */ for (t = nonlocal_labels, last_t = 0; t; last_t = t, t = TREE_CHAIN (t)) if (DECL_RTL (TREE_VALUE (t)) == insn) break; if (t) { if (! last_t) nonlocal_labels = TREE_CHAIN (nonlocal_labels); else TREE_CHAIN (last_t) = TREE_CHAIN (t); } } if (GET_CODE (insn) == INSN) { int can_delete = 0; rtx t; for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1)) if (reg_mentioned_p (t, PATTERN (insn))) { can_delete = 1; break; } if (can_delete || (nonlocal_goto_stack_level != 0 && reg_mentioned_p (nonlocal_goto_stack_level, PATTERN (insn)))) delete_insn (insn); } } } /* Output a USE for any register use in RTL. This is used with -noreg to mark the extent of lifespan of any registers used in a user-visible variable's DECL_RTL. */ void use_variable (rtl) rtx rtl; { if (GET_CODE (rtl) == REG) /* This is a register variable. */ emit_insn (gen_rtx_USE (VOIDmode, rtl)); else if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == REG && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) && XEXP (rtl, 0) != current_function_internal_arg_pointer) /* This is a variable-sized structure. */ emit_insn (gen_rtx_USE (VOIDmode, XEXP (rtl, 0))); } /* Like use_variable except that it outputs the USEs after INSN instead of at the end of the insn-chain. */ void use_variable_after (rtl, insn) rtx rtl, insn; { if (GET_CODE (rtl) == REG) /* This is a register variable. */ emit_insn_after (gen_rtx_USE (VOIDmode, rtl), insn); else if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == REG && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER) && XEXP (rtl, 0) != current_function_internal_arg_pointer) /* This is a variable-sized structure. */ emit_insn_after (gen_rtx_USE (VOIDmode, XEXP (rtl, 0)), insn); } int max_parm_reg_num () { return max_parm_reg; } /* Return the first insn following those generated by `assign_parms'. */ rtx get_first_nonparm_insn () { if (last_parm_insn) return NEXT_INSN (last_parm_insn); return get_insns (); } /* Return the first NOTE_INSN_BLOCK_BEG note in the function. Crash if there is none. */ rtx get_first_block_beg () { register rtx searcher; register rtx insn = get_first_nonparm_insn (); for (searcher = insn; searcher; searcher = NEXT_INSN (searcher)) if (GET_CODE (searcher) == NOTE && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG) return searcher; abort (); /* Invalid call to this function. (See comments above.) */ return NULL_RTX; } /* Return 1 if EXP is an aggregate type (or a value with aggregate type). This means a type for which function calls must pass an address to the function or get an address back from the function. EXP may be a type node or an expression (whose type is tested). */ int aggregate_value_p (exp) tree exp; { int i, regno, nregs; rtx reg; tree type; if (TREE_CODE_CLASS (TREE_CODE (exp)) == 't') type = exp; else type = TREE_TYPE (exp); if (RETURN_IN_MEMORY (type)) return 1; /* Types that are TREE_ADDRESSABLE must be constructed in memory, and thus can't be returned in registers. */ if (TREE_ADDRESSABLE (type)) return 1; if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type)) return 1; /* Make sure we have suitable call-clobbered regs to return the value in; if not, we must return it in memory. */ reg = hard_function_value (type, 0); /* If we have something other than a REG (e.g. a PARALLEL), then assume it is OK. */ if (GET_CODE (reg) != REG) return 0; regno = REGNO (reg); nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type)); for (i = 0; i < nregs; i++) if (! call_used_regs[regno + i]) return 1; return 0; } /* Assign RTL expressions to the function's parameters. This may involve copying them into registers and using those registers as the RTL for them. If SECOND_TIME is non-zero it means that this function is being called a second time. This is done by integrate.c when a function's compilation is deferred. We need to come back here in case the FUNCTION_ARG macro computes items needed for the rest of the compilation (such as changing which registers are fixed or caller-saved). But suppress writing any insns or setting DECL_RTL of anything in this case. */ void assign_parms (fndecl, second_time) tree fndecl; int second_time; { register tree parm; register rtx entry_parm = 0; register rtx stack_parm = 0; CUMULATIVE_ARGS args_so_far; enum machine_mode promoted_mode, passed_mode; enum machine_mode nominal_mode, promoted_nominal_mode; int unsignedp; /* Total space needed so far for args on the stack, given as a constant and a tree-expression. */ struct args_size stack_args_size; tree fntype = TREE_TYPE (fndecl); tree fnargs = DECL_ARGUMENTS (fndecl); /* This is used for the arg pointer when referring to stack args. */ rtx internal_arg_pointer; /* This is a dummy PARM_DECL that we used for the function result if the function returns a structure. */ tree function_result_decl = 0; #ifdef SETUP_INCOMING_VARARGS int varargs_setup = 0; #endif rtx conversion_insns = 0; /* Nonzero if the last arg is named `__builtin_va_alist', which is used on some machines for old-fashioned non-ANSI varargs.h; this should be stuck onto the stack as if it had arrived there. */ int hide_last_arg = (current_function_varargs && fnargs && (parm = tree_last (fnargs)) != 0 && DECL_NAME (parm) && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), "__builtin_va_alist"))); /* Nonzero if function takes extra anonymous args. This means the last named arg must be on the stack right before the anonymous ones. */ int stdarg = (TYPE_ARG_TYPES (fntype) != 0 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) != void_type_node)); current_function_stdarg = stdarg; /* If the reg that the virtual arg pointer will be translated into is not a fixed reg or is the stack pointer, make a copy of the virtual arg pointer, and address parms via the copy. The frame pointer is considered fixed even though it is not marked as such. The second time through, simply use ap to avoid generating rtx. */ if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM || ! (fixed_regs[ARG_POINTER_REGNUM] || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM)) && ! second_time) internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); else internal_arg_pointer = virtual_incoming_args_rtx; current_function_internal_arg_pointer = internal_arg_pointer; stack_args_size.constant = 0; stack_args_size.var = 0; /* If struct value address is treated as the first argument, make it so. */ if (aggregate_value_p (DECL_RESULT (fndecl)) && ! current_function_returns_pcc_struct && struct_value_incoming_rtx == 0) { tree type = build_pointer_type (TREE_TYPE (fntype)); function_result_decl = build_decl (PARM_DECL, NULL_TREE, type); DECL_ARG_TYPE (function_result_decl) = type; TREE_CHAIN (function_result_decl) = fnargs; fnargs = function_result_decl; } max_parm_reg = LAST_VIRTUAL_REGISTER + 1; parm_reg_stack_loc = (rtx *) savealloc (max_parm_reg * sizeof (rtx)); bzero ((char *) parm_reg_stack_loc, max_parm_reg * sizeof (rtx)); #ifdef INIT_CUMULATIVE_INCOMING_ARGS INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX); #else INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0); #endif /* We haven't yet found an argument that we must push and pretend the caller did. */ current_function_pretend_args_size = 0; for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) { int aggregate = AGGREGATE_TYPE_P (TREE_TYPE (parm)); struct args_size stack_offset; struct args_size arg_size; int passed_pointer = 0; int did_conversion = 0; tree passed_type = DECL_ARG_TYPE (parm); tree nominal_type = TREE_TYPE (parm); int pretend_named; /* Set LAST_NAMED if this is last named arg before some anonymous args. */ int last_named = ((TREE_CHAIN (parm) == 0 || DECL_NAME (TREE_CHAIN (parm)) == 0) && (stdarg || current_function_varargs)); /* Set NAMED_ARG if this arg should be treated as a named arg. For most machines, if this is a varargs/stdarg function, then we treat the last named arg as if it were anonymous too. */ int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named; if (TREE_TYPE (parm) == error_mark_node /* This can happen after weird syntax errors or if an enum type is defined among the parms. */ || TREE_CODE (parm) != PARM_DECL || passed_type == NULL) { DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = gen_rtx_MEM (BLKmode, const0_rtx); TREE_USED (parm) = 1; continue; } /* For varargs.h function, save info about regs and stack space used by the individual args, not including the va_alist arg. */ if (hide_last_arg && last_named) current_function_args_info = args_so_far; /* Find mode of arg as it is passed, and mode of arg as it should be during execution of this function. */ passed_mode = TYPE_MODE (passed_type); nominal_mode = TYPE_MODE (nominal_type); /* If the parm's mode is VOID, its value doesn't matter, and avoid the usual things like emit_move_insn that could crash. */ if (nominal_mode == VOIDmode) { DECL_INCOMING_RTL (parm) = DECL_RTL (parm) = const0_rtx; continue; } /* If the parm is to be passed as a transparent union, use the type of the first field for the tests below. We have already verified that the modes are the same. */ if (DECL_TRANSPARENT_UNION (parm) || TYPE_TRANSPARENT_UNION (passed_type)) passed_type = TREE_TYPE (TYPE_FIELDS (passed_type)); /* See if this arg was passed by invisible reference. It is if it is an object whose size depends on the contents of the object itself or if the machine requires these objects be passed that way. */ if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST && contains_placeholder_p (TYPE_SIZE (passed_type))) || TREE_ADDRESSABLE (passed_type) #ifdef FUNCTION_ARG_PASS_BY_REFERENCE || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode, passed_type, named_arg) #endif ) { passed_type = nominal_type = build_pointer_type (passed_type); passed_pointer = 1; passed_mode = nominal_mode = Pmode; } promoted_mode = passed_mode; #ifdef PROMOTE_FUNCTION_ARGS /* Compute the mode in which the arg is actually extended to. */ unsignedp = TREE_UNSIGNED (passed_type); promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1); #endif /* Let machine desc say which reg (if any) the parm arrives in. 0 means it arrives on the stack. */ #ifdef FUNCTION_INCOMING_ARG entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, passed_type, named_arg); #else entry_parm = FUNCTION_ARG (args_so_far, promoted_mode, passed_type, named_arg); #endif if (entry_parm == 0) promoted_mode = passed_mode; #ifdef SETUP_INCOMING_VARARGS /* If this is the last named parameter, do any required setup for varargs or stdargs. We need to know about the case of this being an addressable type, in which case we skip the registers it would have arrived in. For stdargs, LAST_NAMED will be set for two parameters, the one that is actually the last named, and the dummy parameter. We only want to do this action once. Also, indicate when RTL generation is to be suppressed. */ if (last_named && !varargs_setup) { SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type, current_function_pretend_args_size, second_time); varargs_setup = 1; } #endif /* Determine parm's home in the stack, in case it arrives in the stack or we should pretend it did. Compute the stack position and rtx where the argument arrives and its size. There is one complexity here: If this was a parameter that would have been passed in registers, but wasn't only because it is __builtin_va_alist, we want locate_and_pad_parm to treat it as if it came in a register so that REG_PARM_STACK_SPACE isn't skipped. In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 0 as it was the previous time. */ pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED; locate_and_pad_parm (promoted_mode, passed_type, #ifdef STACK_PARMS_IN_REG_PARM_AREA 1, #else #ifdef FUNCTION_INCOMING_ARG FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, passed_type, pretend_named) != 0, #else FUNCTION_ARG (args_so_far, promoted_mode, passed_type, pretend_named) != 0, #endif #endif fndecl, &stack_args_size, &stack_offset, &arg_size); if (! second_time) { rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); if (offset_rtx == const0_rtx) stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer); else stack_parm = gen_rtx_MEM (promoted_mode, gen_rtx_PLUS (Pmode, internal_arg_pointer, offset_rtx)); /* If this is a memory ref that contains aggregate components, mark it as such for cse and loop optimize. Likewise if it is readonly. */ MEM_SET_IN_STRUCT_P (stack_parm, aggregate); RTX_UNCHANGING_P (stack_parm) = TREE_READONLY (parm); MEM_ALIAS_SET (stack_parm) = get_alias_set (parm); } /* If this parameter was passed both in registers and in the stack, use the copy on the stack. */ if (MUST_PASS_IN_STACK (promoted_mode, passed_type)) entry_parm = 0; #ifdef FUNCTION_ARG_PARTIAL_NREGS /* If this parm was passed part in regs and part in memory, pretend it arrived entirely in memory by pushing the register-part onto the stack. In the special case of a DImode or DFmode that is split, we could put it together in a pseudoreg directly, but for now that's not worth bothering with. */ if (entry_parm) { int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode, passed_type, named_arg); if (nregs > 0) { current_function_pretend_args_size = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) / (PARM_BOUNDARY / BITS_PER_UNIT) * (PARM_BOUNDARY / BITS_PER_UNIT)); if (! second_time) { /* Handle calls that pass values in multiple non-contiguous locations. The Irix 6 ABI has examples of this. */ if (GET_CODE (entry_parm) == PARALLEL) emit_group_store (validize_mem (stack_parm), entry_parm, int_size_in_bytes (TREE_TYPE (parm)), (TYPE_ALIGN (TREE_TYPE (parm)) / BITS_PER_UNIT)); else move_block_from_reg (REGNO (entry_parm), validize_mem (stack_parm), nregs, int_size_in_bytes (TREE_TYPE (parm))); } entry_parm = stack_parm; } } #endif /* If we didn't decide this parm came in a register, by default it came on the stack. */ if (entry_parm == 0) entry_parm = stack_parm; /* Record permanently how this parm was passed. */ if (! second_time) DECL_INCOMING_RTL (parm) = entry_parm; /* If there is actually space on the stack for this parm, count it in stack_args_size; otherwise set stack_parm to 0 to indicate there is no preallocated stack slot for the parm. */ if (entry_parm == stack_parm || (GET_CODE (entry_parm) == PARALLEL && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX) #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE) /* On some machines, even if a parm value arrives in a register there is still an (uninitialized) stack slot allocated for it. ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell whether this parameter already has a stack slot allocated, because an arg block exists only if current_function_args_size is larger than some threshold, and we haven't calculated that yet. So, for now, we just assume that stack slots never exist in this case. */ || REG_PARM_STACK_SPACE (fndecl) > 0 #endif ) { stack_args_size.constant += arg_size.constant; if (arg_size.var) ADD_PARM_SIZE (stack_args_size, arg_size.var); } else /* No stack slot was pushed for this parm. */ stack_parm = 0; /* Update info on where next arg arrives in registers. */ FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode, passed_type, named_arg); /* If this is our second time through, we are done with this parm. */ if (second_time) continue; /* If we can't trust the parm stack slot to be aligned enough for its ultimate type, don't use that slot after entry. We'll make another stack slot, if we need one. */ { int thisparm_boundary = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type); if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary) stack_parm = 0; } /* If parm was passed in memory, and we need to convert it on entry, don't store it back in that same slot. */ if (entry_parm != 0 && nominal_mode != BLKmode && nominal_mode != passed_mode) stack_parm = 0; #if 0 /* Now adjust STACK_PARM to the mode and precise location where this parameter should live during execution, if we discover that it must live in the stack during execution. To make debuggers happier on big-endian machines, we store the value in the last bytes of the space available. */ if (nominal_mode != BLKmode && nominal_mode != passed_mode && stack_parm != 0) { rtx offset_rtx; if (BYTES_BIG_ENDIAN && GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD) stack_offset.constant += (GET_MODE_SIZE (passed_mode) - GET_MODE_SIZE (nominal_mode)); offset_rtx = ARGS_SIZE_RTX (stack_offset); if (offset_rtx == const0_rtx) stack_parm = gen_rtx_MEM (nominal_mode, internal_arg_pointer); else stack_parm = gen_rtx_MEM (nominal_mode, gen_rtx_PLUS (Pmode, internal_arg_pointer, offset_rtx)); /* If this is a memory ref that contains aggregate components, mark it as such for cse and loop optimize. */ MEM_SET_IN_STRUCT_P (stack_parm, aggregate); } #endif /* 0 */ #ifdef STACK_REGS /* We need this "use" info, because the gcc-register->stack-register converter in reg-stack.c needs to know which registers are active at the start of the function call. The actual parameter loading instructions are not always available then anymore, since they might have been optimised away. */ if (GET_CODE (entry_parm) == REG && !(hide_last_arg && last_named)) emit_insn (gen_rtx_USE (GET_MODE (entry_parm), entry_parm)); #endif /* ENTRY_PARM is an RTX for the parameter as it arrives, in the mode in which it arrives. STACK_PARM is an RTX for a stack slot where the parameter can live during the function (in case we want to put it there). STACK_PARM is 0 if no stack slot was pushed for it. Now output code if necessary to convert ENTRY_PARM to the type in which this function declares it, and store that result in an appropriate place, which may be a pseudo reg, may be STACK_PARM, or may be a local stack slot if STACK_PARM is 0. Set DECL_RTL to that place. */ if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL) { /* If a BLKmode arrives in registers, copy it to a stack slot. Handle calls that pass values in multiple non-contiguous locations. The Irix 6 ABI has examples of this. */ if (GET_CODE (entry_parm) == REG || GET_CODE (entry_parm) == PARALLEL) { int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)), UNITS_PER_WORD); /* Note that we will be storing an integral number of words. So we have to be careful to ensure that we allocate an integral number of words. We do this below in the assign_stack_local if space was not allocated in the argument list. If it was, this will not work if PARM_BOUNDARY is not a multiple of BITS_PER_WORD. It isn't clear how to fix this if it becomes a problem. */ if (stack_parm == 0) { stack_parm = assign_stack_local (GET_MODE (entry_parm), size_stored, 0); /* If this is a memory ref that contains aggregate components, mark it as such for cse and loop optimize. */ MEM_SET_IN_STRUCT_P (stack_parm, aggregate); } else if (PARM_BOUNDARY % BITS_PER_WORD != 0) abort (); if (TREE_READONLY (parm)) RTX_UNCHANGING_P (stack_parm) = 1; /* Handle calls that pass values in multiple non-contiguous locations. The Irix 6 ABI has examples of this. */ if (GET_CODE (entry_parm) == PARALLEL) emit_group_store (validize_mem (stack_parm), entry_parm, int_size_in_bytes (TREE_TYPE (parm)), (TYPE_ALIGN (TREE_TYPE (parm)) / BITS_PER_UNIT)); else move_block_from_reg (REGNO (entry_parm), validize_mem (stack_parm), size_stored / UNITS_PER_WORD, int_size_in_bytes (TREE_TYPE (parm))); } DECL_RTL (parm) = stack_parm; } else if (! ((obey_regdecls && ! DECL_REGISTER (parm) && ! DECL_INLINE (fndecl)) /* layout_decl may set this. */ || TREE_ADDRESSABLE (parm) || TREE_SIDE_EFFECTS (parm) /* If -ffloat-store specified, don't put explicit float variables into registers. */ || (flag_float_store && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)) /* Always assign pseudo to structure return or item passed by invisible reference. */ || passed_pointer || parm == function_result_decl) { /* Store the parm in a pseudoregister during the function, but we may need to do it in a wider mode. */ register rtx parmreg; int regno, regnoi = 0, regnor = 0; unsignedp = TREE_UNSIGNED (TREE_TYPE (parm)); promoted_nominal_mode = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0); parmreg = gen_reg_rtx (promoted_nominal_mode); mark_user_reg (parmreg); /* If this was an item that we received a pointer to, set DECL_RTL appropriately. */ if (passed_pointer) { DECL_RTL (parm) = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), parmreg); MEM_SET_IN_STRUCT_P (DECL_RTL (parm), aggregate); } else DECL_RTL (parm) = parmreg; /* Copy the value into the register. */ if (nominal_mode != passed_mode || promoted_nominal_mode != promoted_mode) { int save_tree_used; /* ENTRY_PARM has been converted to PROMOTED_MODE, its mode, by the caller. We now have to convert it to NOMINAL_MODE, if different. However, PARMREG may be in a different mode than NOMINAL_MODE if it is being stored promoted. If ENTRY_PARM is a hard register, it might be in a register not valid for operating in its mode (e.g., an odd-numbered register for a DFmode). In that case, moves are the only thing valid, so we can't do a convert from there. This occurs when the calling sequence allow such misaligned usages. In addition, the conversion may involve a call, which could clobber parameters which haven't been copied to pseudo registers yet. Therefore, we must first copy the parm to a pseudo reg here, and save the conversion until after all parameters have been moved. */ rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); emit_move_insn (tempreg, validize_mem (entry_parm)); push_to_sequence (conversion_insns); tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp); /* TREE_USED gets set erroneously during expand_assignment. */ save_tree_used = TREE_USED (parm); expand_assignment (parm, make_tree (nominal_type, tempreg), 0, 0); TREE_USED (parm) = save_tree_used; conversion_insns = get_insns (); did_conversion = 1; end_sequence (); } else emit_move_insn (parmreg, validize_mem (entry_parm)); /* If we were passed a pointer but the actual value can safely live in a register, put it in one. */ if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode && ! ((obey_regdecls && ! DECL_REGISTER (parm) && ! DECL_INLINE (fndecl)) /* layout_decl may set this. */ || TREE_ADDRESSABLE (parm) || TREE_SIDE_EFFECTS (parm) /* If -ffloat-store specified, don't put explicit float variables into registers. */ || (flag_float_store && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))) { /* We can't use nominal_mode, because it will have been set to Pmode above. We must use the actual mode of the parm. */ parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); mark_user_reg (parmreg); emit_move_insn (parmreg, DECL_RTL (parm)); DECL_RTL (parm) = parmreg; /* STACK_PARM is the pointer, not the parm, and PARMREG is now the parm. */ stack_parm = 0; } #ifdef FUNCTION_ARG_CALLEE_COPIES /* If we are passed an arg by reference and it is our responsibility to make a copy, do it now. PASSED_TYPE and PASSED mode now refer to the pointer, not the original argument, so we must recreate them in the call to FUNCTION_ARG_CALLEE_COPIES. */ /* ??? Later add code to handle the case that if the argument isn't modified, don't do the copy. */ else if (passed_pointer && FUNCTION_ARG_CALLEE_COPIES (args_so_far, TYPE_MODE (DECL_ARG_TYPE (parm)), DECL_ARG_TYPE (parm), named_arg) && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) { rtx copy; tree type = DECL_ARG_TYPE (parm); /* This sequence may involve a library call perhaps clobbering registers that haven't been copied to pseudos yet. */ push_to_sequence (conversion_insns); if (TYPE_SIZE (type) == 0 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) /* This is a variable sized object. */ copy = gen_rtx_MEM (BLKmode, allocate_dynamic_stack_space (expr_size (parm), NULL_RTX, TYPE_ALIGN (type))); else copy = assign_stack_temp (TYPE_MODE (type), int_size_in_bytes (type), 1); MEM_SET_IN_STRUCT_P (copy, AGGREGATE_TYPE_P (type)); RTX_UNCHANGING_P (copy) = TREE_READONLY (parm); store_expr (parm, copy, 0); emit_move_insn (parmreg, XEXP (copy, 0)); if (current_function_check_memory_usage) emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, XEXP (copy, 0), Pmode, GEN_INT (int_size_in_bytes (type)), TYPE_MODE (sizetype), GEN_INT (MEMORY_USE_RW), TYPE_MODE (integer_type_node)); conversion_insns = get_insns (); did_conversion = 1; end_sequence (); } #endif /* FUNCTION_ARG_CALLEE_COPIES */ /* In any case, record the parm's desired stack location in case we later discover it must live in the stack. If it is a COMPLEX value, store the stack location for both halves. */ if (GET_CODE (parmreg) == CONCAT) regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1))); else regno = REGNO (parmreg); if (regno >= max_parm_reg) { rtx *new; int old_max_parm_reg = max_parm_reg; /* It's slow to expand this one register at a time, but it's also rare and we need max_parm_reg to be precisely correct. */ max_parm_reg = regno + 1; new = (rtx *) savealloc (max_parm_reg * sizeof (rtx)); bcopy ((char *) parm_reg_stack_loc, (char *) new, old_max_parm_reg * sizeof (rtx)); bzero ((char *) (new + old_max_parm_reg), (max_parm_reg - old_max_parm_reg) * sizeof (rtx)); parm_reg_stack_loc = new; } if (GET_CODE (parmreg) == CONCAT) { enum machine_mode submode = GET_MODE (XEXP (parmreg, 0)); regnor = REGNO (gen_realpart (submode, parmreg)); regnoi = REGNO (gen_imagpart (submode, parmreg)); if (stack_parm != 0) { parm_reg_stack_loc[regnor] = gen_realpart (submode, stack_parm); parm_reg_stack_loc[regnoi] = gen_imagpart (submode, stack_parm); } else { parm_reg_stack_loc[regnor] = 0; parm_reg_stack_loc[regnoi] = 0; } } else parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; /* Mark the register as eliminable if we did no conversion and it was copied from memory at a fixed offset, and the arg pointer was not copied to a pseudo-reg. If the arg pointer is a pseudo reg or the offset formed an invalid address, such memory-equivalences as we make here would screw up life analysis for it. */ if (nominal_mode == passed_mode && ! did_conversion && stack_parm != 0 && GET_CODE (stack_parm) == MEM && stack_offset.var == 0 && reg_mentioned_p (virtual_incoming_args_rtx, XEXP (stack_parm, 0))) { rtx linsn = get_last_insn (); rtx sinsn, set; /* Mark complex types separately. */ if (GET_CODE (parmreg) == CONCAT) /* Scan backwards for the set of the real and imaginary parts. */ for (sinsn = linsn; sinsn != 0; sinsn = prev_nonnote_insn (sinsn)) { set = single_set (sinsn); if (set != 0 && SET_DEST (set) == regno_reg_rtx [regnoi]) REG_NOTES (sinsn) = gen_rtx_EXPR_LIST (REG_EQUIV, parm_reg_stack_loc[regnoi], REG_NOTES (sinsn)); else if (set != 0 && SET_DEST (set) == regno_reg_rtx [regnor]) REG_NOTES (sinsn) = gen_rtx_EXPR_LIST (REG_EQUIV, parm_reg_stack_loc[regnor], REG_NOTES (sinsn)); } else if ((set = single_set (linsn)) != 0 && SET_DEST (set) == parmreg) REG_NOTES (linsn) = gen_rtx_EXPR_LIST (REG_EQUIV, stack_parm, REG_NOTES (linsn)); } /* For pointer data type, suggest pointer register. */ if (POINTER_TYPE_P (TREE_TYPE (parm))) mark_reg_pointer (parmreg, (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm))) / BITS_PER_UNIT)); } else { /* Value must be stored in the stack slot STACK_PARM during function execution. */ if (promoted_mode != nominal_mode) { /* Conversion is required. */ rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); emit_move_insn (tempreg, validize_mem (entry_parm)); push_to_sequence (conversion_insns); entry_parm = convert_to_mode (nominal_mode, tempreg, TREE_UNSIGNED (TREE_TYPE (parm))); if (stack_parm) { /* ??? This may need a big-endian conversion on sparc64. */ stack_parm = change_address (stack_parm, nominal_mode, NULL_RTX); } conversion_insns = get_insns (); did_conversion = 1; end_sequence (); } if (entry_parm != stack_parm) { if (stack_parm == 0) { stack_parm = assign_stack_local (GET_MODE (entry_parm), GET_MODE_SIZE (GET_MODE (entry_parm)), 0); /* If this is a memory ref that contains aggregate components, mark it as such for cse and loop optimize. */ MEM_SET_IN_STRUCT_P (stack_parm, aggregate); } if (promoted_mode != nominal_mode) { push_to_sequence (conversion_insns); emit_move_insn (validize_mem (stack_parm), validize_mem (entry_parm)); conversion_insns = get_insns (); end_sequence (); } else emit_move_insn (validize_mem (stack_parm), validize_mem (entry_parm)); } if (current_function_check_memory_usage) { push_to_sequence (conversion_insns); emit_library_call (chkr_set_right_libfunc, 1, VOIDmode, 3, XEXP (stack_parm, 0), Pmode, GEN_INT (GET_MODE_SIZE (GET_MODE (entry_parm))), TYPE_MODE (sizetype), GEN_INT (MEMORY_USE_RW), TYPE_MODE (integer_type_node)); conversion_insns = get_insns (); end_sequence (); } DECL_RTL (parm) = stack_parm; } /* If this "parameter" was the place where we are receiving the function's incoming structure pointer, set up the result. */ if (parm == function_result_decl) { tree result = DECL_RESULT (fndecl); tree restype = TREE_TYPE (result); DECL_RTL (result) = gen_rtx_MEM (DECL_MODE (result), DECL_RTL (parm)); MEM_SET_IN_STRUCT_P (DECL_RTL (result), AGGREGATE_TYPE_P (restype)); } if (TREE_THIS_VOLATILE (parm)) MEM_VOLATILE_P (DECL_RTL (parm)) = 1; if (TREE_READONLY (parm)) RTX_UNCHANGING_P (DECL_RTL (parm)) = 1; } /* Output all parameter conversion instructions (possibly including calls) now that all parameters have been copied out of hard registers. */ emit_insns (conversion_insns); last_parm_insn = get_last_insn (); current_function_args_size = stack_args_size.constant; /* Adjust function incoming argument size for alignment and minimum length. */ #ifdef REG_PARM_STACK_SPACE #ifndef MAYBE_REG_PARM_STACK_SPACE current_function_args_size = MAX (current_function_args_size, REG_PARM_STACK_SPACE (fndecl)); #endif #endif #ifdef STACK_BOUNDARY #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) current_function_args_size = ((current_function_args_size + STACK_BYTES - 1) / STACK_BYTES) * STACK_BYTES; #endif #ifdef ARGS_GROW_DOWNWARD current_function_arg_offset_rtx = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant) : expand_expr (size_binop (MINUS_EXPR, stack_args_size.var, size_int (-stack_args_size.constant)), NULL_RTX, VOIDmode, EXPAND_MEMORY_USE_BAD)); #else current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size); #endif /* See how many bytes, if any, of its args a function should try to pop on return. */ current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl), current_function_args_size); /* For stdarg.h function, save info about regs and stack space used by the named args. */ if (!hide_last_arg) current_function_args_info = args_so_far; /* Set the rtx used for the function return value. Put this in its own variable so any optimizers that need this information don't have to include tree.h. Do this here so it gets done when an inlined function gets output. */ current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl)); } /* Indicate whether REGNO is an incoming argument to the current function that was promoted to a wider mode. If so, return the RTX for the register (to get its mode). PMODE and PUNSIGNEDP are set to the mode that REGNO is promoted from and whether the promotion was signed or unsigned. */ #ifdef PROMOTE_FUNCTION_ARGS rtx promoted_input_arg (regno, pmode, punsignedp) int regno; enum machine_mode *pmode; int *punsignedp; { tree arg; for (arg = DECL_ARGUMENTS (current_function_decl); arg; arg = TREE_CHAIN (arg)) if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG && REGNO (DECL_INCOMING_RTL (arg)) == regno && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg))) { enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg)); int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg)); mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1); if (mode == GET_MODE (DECL_INCOMING_RTL (arg)) && mode != DECL_MODE (arg)) { *pmode = DECL_MODE (arg); *punsignedp = unsignedp; return DECL_INCOMING_RTL (arg); } } return 0; } #endif /* Compute the size and offset from the start of the stacked arguments for a parm passed in mode PASSED_MODE and with type TYPE. INITIAL_OFFSET_PTR points to the current offset into the stacked arguments. The starting offset and size for this parm are returned in *OFFSET_PTR and *ARG_SIZE_PTR, respectively. IN_REGS is non-zero if the argument will be passed in registers. It will never be set if REG_PARM_STACK_SPACE is not defined. FNDECL is the function in which the argument was defined. There are two types of rounding that are done. The first, controlled by FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument list to be aligned to the specific boundary (in bits). This rounding affects the initial and starting offsets, but not the argument size. The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, optionally rounds the size of the parm to PARM_BOUNDARY. The initial offset is not affected by this rounding, while the size always is and the starting offset may be. */ /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case; initial_offset_ptr is positive because locate_and_pad_parm's callers pass in the total size of args so far as initial_offset_ptr. arg_size_ptr is always positive.*/ void locate_and_pad_parm (passed_mode, type, in_regs, fndecl, initial_offset_ptr, offset_ptr, arg_size_ptr) enum machine_mode passed_mode; tree type; int in_regs; tree fndecl ATTRIBUTE_UNUSED; struct args_size *initial_offset_ptr; struct args_size *offset_ptr; struct args_size *arg_size_ptr; { tree sizetree = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type); int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); #ifdef REG_PARM_STACK_SPACE /* If we have found a stack parm before we reach the end of the area reserved for registers, skip that area. */ if (! in_regs) { int reg_parm_stack_space = 0; #ifdef MAYBE_REG_PARM_STACK_SPACE reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; #else reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); #endif if (reg_parm_stack_space > 0) { if (initial_offset_ptr->var) { initial_offset_ptr->var = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), size_int (reg_parm_stack_space)); initial_offset_ptr->constant = 0; } else if (initial_offset_ptr->constant < reg_parm_stack_space) initial_offset_ptr->constant = reg_parm_stack_space; } } #endif /* REG_PARM_STACK_SPACE */ arg_size_ptr->var = 0; arg_size_ptr->constant = 0; #ifdef ARGS_GROW_DOWNWARD if (initial_offset_ptr->var) { offset_ptr->constant = 0; offset_ptr->var = size_binop (MINUS_EXPR, integer_zero_node, initial_offset_ptr->var); } else { offset_ptr->constant = - initial_offset_ptr->constant; offset_ptr->var = 0; } if (where_pad != none && (TREE_CODE (sizetree) != INTEGER_CST || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); SUB_PARM_SIZE (*offset_ptr, sizetree); if (where_pad != downward) pad_to_arg_alignment (offset_ptr, boundary); if (initial_offset_ptr->var) { arg_size_ptr->var = size_binop (MINUS_EXPR, size_binop (MINUS_EXPR, integer_zero_node, initial_offset_ptr->var), offset_ptr->var); } else { arg_size_ptr->constant = (- initial_offset_ptr->constant - offset_ptr->constant); } #else /* !ARGS_GROW_DOWNWARD */ pad_to_arg_alignment (initial_offset_ptr, boundary); *offset_ptr = *initial_offset_ptr; #ifdef PUSH_ROUNDING if (passed_mode != BLKmode) sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree))); #endif /* Pad_below needs the pre-rounded size to know how much to pad below so this must be done before rounding up. */ if (where_pad == downward /* However, BLKmode args passed in regs have their padding done elsewhere. The stack slot must be able to hold the entire register. */ && !(in_regs && passed_mode == BLKmode)) pad_below (offset_ptr, passed_mode, sizetree); if (where_pad != none && (TREE_CODE (sizetree) != INTEGER_CST || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY))) sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); ADD_PARM_SIZE (*arg_size_ptr, sizetree); #endif /* ARGS_GROW_DOWNWARD */ } /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. BOUNDARY is measured in bits, but must be a multiple of a storage unit. */ static void pad_to_arg_alignment (offset_ptr, boundary) struct args_size *offset_ptr; int boundary; { int boundary_in_bytes = boundary / BITS_PER_UNIT; if (boundary > BITS_PER_UNIT) { if (offset_ptr->var) { offset_ptr->var = #ifdef ARGS_GROW_DOWNWARD round_down #else round_up #endif (ARGS_SIZE_TREE (*offset_ptr), boundary / BITS_PER_UNIT); offset_ptr->constant = 0; /*?*/ } else offset_ptr->constant = #ifdef ARGS_GROW_DOWNWARD FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes); #else CEIL_ROUND (offset_ptr->constant, boundary_in_bytes); #endif } } #ifndef ARGS_GROW_DOWNWARD static void pad_below (offset_ptr, passed_mode, sizetree) struct args_size *offset_ptr; enum machine_mode passed_mode; tree sizetree; { if (passed_mode != BLKmode) { if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) offset_ptr->constant += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) - GET_MODE_SIZE (passed_mode)); } else { if (TREE_CODE (sizetree) != INTEGER_CST || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY) { /* Round the size up to multiple of PARM_BOUNDARY bits. */ tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); /* Add it in. */ ADD_PARM_SIZE (*offset_ptr, s2); SUB_PARM_SIZE (*offset_ptr, sizetree); } } } #endif #ifdef ARGS_GROW_DOWNWARD static tree round_down (value, divisor) tree value; int divisor; { return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, size_int (divisor)), size_int (divisor)); } #endif /* Walk the tree of blocks describing the binding levels within a function and warn about uninitialized variables. This is done after calling flow_analysis and before global_alloc clobbers the pseudo-regs to hard regs. */ void uninitialized_vars_warning (block) tree block; { register tree decl, sub; for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) { if (TREE_CODE (decl) == VAR_DECL /* These warnings are unreliable for and aggregates because assigning the fields one by one can fail to convince flow.c that the entire aggregate was initialized. Unions are troublesome because members may be shorter. */ && ! AGGREGATE_TYPE_P (TREE_TYPE (decl)) && DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == REG /* Global optimizations can make it difficult to determine if a particular variable has been initialized. However, a VAR_DECL with a nonzero DECL_INITIAL had an initializer, so do not claim it is potentially uninitialized. We do not care about the actual value in DECL_INITIAL, so we do not worry that it may be a dangling pointer. */ && DECL_INITIAL (decl) == NULL_TREE && regno_uninitialized (REGNO (DECL_RTL (decl)))) warning_with_decl (decl, "`%s' might be used uninitialized in this function"); if (TREE_CODE (decl) == VAR_DECL && DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == REG && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) warning_with_decl (decl, "variable `%s' might be clobbered by `longjmp' or `vfork'"); } for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) uninitialized_vars_warning (sub); } /* Do the appropriate part of uninitialized_vars_warning but for arguments instead of local variables. */ void setjmp_args_warning () { register tree decl; for (decl = DECL_ARGUMENTS (current_function_decl); decl; decl = TREE_CHAIN (decl)) if (DECL_RTL (decl) != 0 && GET_CODE (DECL_RTL (decl)) == REG && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) warning_with_decl (decl, "argument `%s' might be clobbered by `longjmp' or `vfork'"); } /* If this function call setjmp, put all vars into the stack unless they were declared `register'. */ void setjmp_protect (block) tree block; { register tree decl, sub; for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) && DECL_RTL (decl) != 0 && (GET_CODE (DECL_RTL (decl)) == REG || (GET_CODE (DECL_RTL (decl)) == MEM && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) /* If this variable came from an inline function, it must be that its life doesn't overlap the setjmp. If there was a setjmp in the function, it would already be in memory. We must exclude such variable because their DECL_RTL might be set to strange things such as virtual_stack_vars_rtx. */ && ! DECL_FROM_INLINE (decl) && ( #ifdef NON_SAVING_SETJMP /* If longjmp doesn't restore the registers, don't put anything in them. */ NON_SAVING_SETJMP || #endif ! DECL_REGISTER (decl))) put_var_into_stack (decl); for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) setjmp_protect (sub); } /* Like the previous function, but for args instead of local variables. */ void setjmp_protect_args () { register tree decl; for (decl = DECL_ARGUMENTS (current_function_decl); decl; decl = TREE_CHAIN (decl)) if ((TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == PARM_DECL) && DECL_RTL (decl) != 0 && (GET_CODE (DECL_RTL (decl)) == REG || (GET_CODE (DECL_RTL (decl)) == MEM && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) && ( /* If longjmp doesn't restore the registers, don't put anything in them. */ #ifdef NON_SAVING_SETJMP NON_SAVING_SETJMP || #endif ! DECL_REGISTER (decl))) put_var_into_stack (decl); } /* Return the context-pointer register corresponding to DECL, or 0 if it does not need one. */ rtx lookup_static_chain (decl) tree decl; { tree context = decl_function_context (decl); tree link; if (context == 0 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl))) return 0; /* We treat inline_function_decl as an alias for the current function because that is the inline function whose vars, types, etc. are being merged into the current function. See expand_inline_function. */ if (context == current_function_decl || context == inline_function_decl) return virtual_stack_vars_rtx; for (link = context_display; link; link = TREE_CHAIN (link)) if (TREE_PURPOSE (link) == context) return RTL_EXPR_RTL (TREE_VALUE (link)); abort (); } /* Convert a stack slot address ADDR for variable VAR (from a containing function) into an address valid in this function (using a static chain). */ rtx fix_lexical_addr (addr, var) rtx addr; tree var; { rtx basereg; HOST_WIDE_INT displacement; tree context = decl_function_context (var); struct function *fp; rtx base = 0; /* If this is the present function, we need not do anything. */ if (context == current_function_decl || context == inline_function_decl) return addr; for (fp = outer_function_chain; fp; fp = fp->next) if (fp->decl == context) break; if (fp == 0) abort (); if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM) addr = XEXP (XEXP (addr, 0), 0); /* Decode given address as base reg plus displacement. */ if (GET_CODE (addr) == REG) basereg = addr, displacement = 0; else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1)); else abort (); /* We accept vars reached via the containing function's incoming arg pointer and via its stack variables pointer. */ if (basereg == fp->internal_arg_pointer) { /* If reached via arg pointer, get the arg pointer value out of that function's stack frame. There are two cases: If a separate ap is needed, allocate a slot in the outer function for it and dereference it that way. This is correct even if the real ap is actually a pseudo. Otherwise, just adjust the offset from the frame pointer to compensate. */ #ifdef NEED_SEPARATE_AP rtx addr; if (fp->arg_pointer_save_area == 0) fp->arg_pointer_save_area = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp); addr = fix_lexical_addr (XEXP (fp->arg_pointer_save_area, 0), var); addr = memory_address (Pmode, addr); base = copy_to_reg (gen_rtx_MEM (Pmode, addr)); #else displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET); base = lookup_static_chain (var); #endif } else if (basereg == virtual_stack_vars_rtx) { /* This is the same code as lookup_static_chain, duplicated here to avoid an extra call to decl_function_context. */ tree link; for (link = context_display; link; link = TREE_CHAIN (link)) if (TREE_PURPOSE (link) == context) { base = RTL_EXPR_RTL (TREE_VALUE (link)); break; } } if (base == 0) abort (); /* Use same offset, relative to appropriate static chain or argument pointer. */ return plus_constant (base, displacement); } /* Return the address of the trampoline for entering nested fn FUNCTION. If necessary, allocate a trampoline (in the stack frame) and emit rtl to initialize its contents (at entry to this function). */ rtx trampoline_address (function) tree function; { tree link; tree rtlexp; rtx tramp; struct function *fp; tree fn_context; /* Find an existing trampoline and return it. */ for (link = trampoline_list; link; link = TREE_CHAIN (link)) if (TREE_PURPOSE (link) == function) return round_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0)); for (fp = outer_function_chain; fp; fp = fp->next) for (link = fp->trampoline_list; link; link = TREE_CHAIN (link)) if (TREE_PURPOSE (link) == function) { tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0), function); return round_trampoline_addr (tramp); } /* None exists; we must make one. */ /* Find the `struct function' for the function containing FUNCTION. */ fp = 0; fn_context = decl_function_context (function); if (fn_context != current_function_decl && fn_context != inline_function_decl) for (fp = outer_function_chain; fp; fp = fp->next) if (fp->decl == fn_context) break; /* Allocate run-time space for this trampoline (usually in the defining function's stack frame). */ #ifdef ALLOCATE_TRAMPOLINE tramp = ALLOCATE_TRAMPOLINE (fp); #else /* If rounding needed, allocate extra space to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */ #ifdef TRAMPOLINE_ALIGNMENT #define TRAMPOLINE_REAL_SIZE \ (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1) #else #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE) #endif if (fp != 0) tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp); else tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0); #endif /* Record the trampoline for reuse and note it for later initialization by expand_function_end. */ if (fp != 0) { push_obstacks (fp->function_maybepermanent_obstack, fp->function_maybepermanent_obstack); rtlexp = make_node (RTL_EXPR); RTL_EXPR_RTL (rtlexp) = tramp; fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list); pop_obstacks (); } else { /* Make the RTL_EXPR node temporary, not momentary, so that the trampoline_list doesn't become garbage. */ int momentary = suspend_momentary (); rtlexp = make_node (RTL_EXPR); resume_momentary (momentary); RTL_EXPR_RTL (rtlexp) = tramp; trampoline_list = tree_cons (function, rtlexp, trampoline_list); } tramp = fix_lexical_addr (XEXP (tramp, 0), function); return round_trampoline_addr (tramp); } /* Given a trampoline address, round it to multiple of TRAMPOLINE_ALIGNMENT. */ static rtx round_trampoline_addr (tramp) rtx tramp; { #ifdef TRAMPOLINE_ALIGNMENT /* Round address up to desired boundary. */ rtx temp = gen_reg_rtx (Pmode); temp = expand_binop (Pmode, add_optab, tramp, GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1), temp, 0, OPTAB_LIB_WIDEN); tramp = expand_binop (Pmode, and_optab, temp, GEN_INT (- TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT), temp, 0, OPTAB_LIB_WIDEN); #endif return tramp; } /* The functions identify_blocks and reorder_blocks provide a way to reorder the tree of BLOCK nodes, for optimizers that reshuffle or duplicate portions of the RTL code. Call identify_blocks before changing the RTL, and call reorder_blocks after. */ /* Put all this function's BLOCK nodes including those that are chained onto the first block into a vector, and return it. Also store in each NOTE for the beginning or end of a block the index of that block in the vector. The arguments are BLOCK, the chain of top-level blocks of the function, and INSNS, the insn chain of the function. */ tree * identify_blocks (block, insns) tree block; rtx insns; { int n_blocks; tree *block_vector; int *block_stack; int depth = 0; int next_block_number = 1; int current_block_number = 1; rtx insn; if (block == 0) return 0; n_blocks = all_blocks (block, 0); block_vector = (tree *) xmalloc (n_blocks * sizeof (tree)); block_stack = (int *) alloca (n_blocks * sizeof (int)); all_blocks (block, block_vector); for (insn = insns; insn; insn = NEXT_INSN (insn)) if (GET_CODE (insn) == NOTE) { if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) { block_stack[depth++] = current_block_number; current_block_number = next_block_number; NOTE_BLOCK_NUMBER (insn) = next_block_number++; } if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) { NOTE_BLOCK_NUMBER (insn) = current_block_number; current_block_number = block_stack[--depth]; } } if (n_blocks != next_block_number) abort (); return block_vector; } /* Given BLOCK_VECTOR which was returned by identify_blocks, and a revised instruction chain, rebuild the tree structure of BLOCK nodes to correspond to the new order of RTL. The new block tree is inserted below TOP_BLOCK. Returns the current top-level block. */ tree reorder_blocks (block_vector, block, insns) tree *block_vector; tree block; rtx insns; { tree current_block = block; rtx insn; if (block_vector == 0) return block; /* Prune the old trees away, so that it doesn't get in the way. */ BLOCK_SUBBLOCKS (current_block) = 0; BLOCK_CHAIN (current_block) = 0; for (insn = insns; insn; insn = NEXT_INSN (insn)) if (GET_CODE (insn) == NOTE) { if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) { tree block = block_vector[NOTE_BLOCK_NUMBER (insn)]; /* If we have seen this block before, copy it. */ if (TREE_ASM_WRITTEN (block)) block = copy_node (block); BLOCK_SUBBLOCKS (block) = 0; TREE_ASM_WRITTEN (block) = 1; BLOCK_SUPERCONTEXT (block) = current_block; BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block); BLOCK_SUBBLOCKS (current_block) = block; current_block = block; NOTE_SOURCE_FILE (insn) = 0; } if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) { BLOCK_SUBBLOCKS (current_block) = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); current_block = BLOCK_SUPERCONTEXT (current_block); NOTE_SOURCE_FILE (insn) = 0; } } BLOCK_SUBBLOCKS (current_block) = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); return current_block; } /* Reverse the order of elements in the chain T of blocks, and return the new head of the chain (old last element). */ static tree blocks_nreverse (t) tree t; { register tree prev = 0, decl, next; for (decl = t; decl; decl = next) { next = BLOCK_CHAIN (decl); BLOCK_CHAIN (decl) = prev; prev = decl; } return prev; } /* Count the subblocks of the list starting with BLOCK, and list them all into the vector VECTOR. Also clear TREE_ASM_WRITTEN in all blocks. */ static int all_blocks (block, vector) tree block; tree *vector; { int n_blocks = 0; while (block) { TREE_ASM_WRITTEN (block) = 0; /* Record this block. */ if (vector) vector[n_blocks] = block; ++n_blocks; /* Record the subblocks, and their subblocks... */ n_blocks += all_blocks (BLOCK_SUBBLOCKS (block), vector ? vector + n_blocks : 0); block = BLOCK_CHAIN (block); } return n_blocks; } /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node) and initialize static variables for generating RTL for the statements of the function. */ void init_function_start (subr, filename, line) tree subr; char *filename; int line; { init_stmt_for_function (); cse_not_expected = ! optimize; /* Caller save not needed yet. */ caller_save_needed = 0; /* No stack slots have been made yet. */ stack_slot_list = 0; /* There is no stack slot for handling nonlocal gotos. */ nonlocal_goto_handler_slots = 0; nonlocal_goto_stack_level = 0; /* No labels have been declared for nonlocal use. */ nonlocal_labels = 0; nonlocal_goto_handler_labels = 0; /* No function calls so far in this function. */ function_call_count = 0; /* No parm regs have been allocated. (This is important for output_inline_function.) */ max_parm_reg = LAST_VIRTUAL_REGISTER + 1; /* Initialize the RTL mechanism. */ init_emit (); /* Initialize the queue of pending postincrement and postdecrements, and some other info in expr.c. */ init_expr (); /* We haven't done register allocation yet. */ reg_renumber = 0; init_const_rtx_hash_table (); current_function_name = (*decl_printable_name) (subr, 2); /* Nonzero if this is a nested function that uses a static chain. */ current_function_needs_context = (decl_function_context (current_function_decl) != 0 && ! DECL_NO_STATIC_CHAIN (current_function_decl)); /* Set if a call to setjmp is seen. */ current_function_calls_setjmp = 0; /* Set if a call to longjmp is seen. */ current_function_calls_longjmp = 0; current_function_calls_alloca = 0; current_function_has_nonlocal_label = 0; current_function_has_nonlocal_goto = 0; current_function_contains_functions = 0; current_function_is_leaf = 0; current_function_sp_is_unchanging = 0; current_function_uses_only_leaf_regs = 0; current_function_has_computed_jump = 0; current_function_is_thunk = 0; current_function_returns_pcc_struct = 0; current_function_returns_struct = 0; current_function_epilogue_delay_list = 0; current_function_uses_const_pool = 0; current_function_uses_pic_offset_table = 0; current_function_cannot_inline = 0; /* We have not yet needed to make a label to jump to for tail-recursion. */ tail_recursion_label = 0; /* We haven't had a need to make a save area for ap yet. */ arg_pointer_save_area = 0; /* No stack slots allocated yet. */ frame_offset = 0; /* No SAVE_EXPRs in this function yet. */ save_expr_regs = 0; /* No RTL_EXPRs in this function yet. */ rtl_expr_chain = 0; /* Set up to allocate temporaries. */ init_temp_slots (); /* Within function body, compute a type's size as soon it is laid out. */ immediate_size_expand++; /* We haven't made any trampolines for this function yet. */ trampoline_list = 0; init_pending_stack_adjust (); inhibit_defer_pop = 0; current_function_outgoing_args_size = 0; /* Prevent ever trying to delete the first instruction of a function. Also tell final how to output a linenum before the function prologue. Note linenums could be missing, e.g. when compiling a Java .class file. */ if (line > 0) emit_line_note (filename, line); /* Make sure first insn is a note even if we don't want linenums. This makes sure the first insn will never be deleted. Also, final expects a note to appear there. */ emit_note (NULL_PTR, NOTE_INSN_DELETED); /* Set flags used by final.c. */ if (aggregate_value_p (DECL_RESULT (subr))) { #ifdef PCC_STATIC_STRUCT_RETURN current_function_returns_pcc_struct = 1; #endif current_function_returns_struct = 1; } /* Warn if this value is an aggregate type, regardless of which calling convention we are using for it. */ if (warn_aggregate_return && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)))) warning ("function returns an aggregate"); current_function_returns_pointer = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr))); /* Indicate that we need to distinguish between the return value of the present function and the return value of a function being called. */ rtx_equal_function_value_matters = 1; /* Indicate that we have not instantiated virtual registers yet. */ virtuals_instantiated = 0; /* Indicate we have no need of a frame pointer yet. */ frame_pointer_needed = 0; /* By default assume not varargs or stdarg. */ current_function_varargs = 0; current_function_stdarg = 0; } /* Indicate that the current function uses extra args not explicitly mentioned in the argument list in any fashion. */ void mark_varargs () { current_function_varargs = 1; } /* Expand a call to __main at the beginning of a possible main function. */ #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main) #undef HAS_INIT_SECTION #define HAS_INIT_SECTION #endif #ifndef GEN_CALL__MAIN #define GEN_CALL__MAIN \ do { \ emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0, \ VOIDmode, 0); \ } while (0) #endif void expand_main_function () { #if defined(INVOKE__main) || !defined (HAS_INIT_SECTION) GEN_CALL__MAIN; #endif /* not HAS_INIT_SECTION */ } extern struct obstack permanent_obstack; /* Start the RTL for a new function, and set variables used for emitting RTL. SUBR is the FUNCTION_DECL node. PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with the function's parameters, which must be run at any return statement. */ void expand_function_start (subr, parms_have_cleanups) tree subr; int parms_have_cleanups; { register int i; tree tem; rtx last_ptr = NULL_RTX; /* Make sure volatile mem refs aren't considered valid operands of arithmetic insns. */ init_recog_no_volatile (); /* Set this before generating any memory accesses. */ current_function_check_memory_usage = (flag_check_memory_usage && ! DECL_NO_CHECK_MEMORY_USAGE (current_function_decl)); current_function_instrument_entry_exit = (flag_instrument_function_entry_exit && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); /* If function gets a static chain arg, store it in the stack frame. Do this first, so it gets the first stack slot offset. */ if (current_function_needs_context) { last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); /* Delay copying static chain if it is not a register to avoid conflicts with regs used for parameters. */ if (! SMALL_REGISTER_CLASSES || GET_CODE (static_chain_incoming_rtx) == REG) emit_move_insn (last_ptr, static_chain_incoming_rtx); } /* If the parameters of this function need cleaning up, get a label for the beginning of the code which executes those cleanups. This must be done before doing anything with return_label. */ if (parms_have_cleanups) cleanup_label = gen_label_rtx (); else cleanup_label = 0; /* Make the label for return statements to jump to, if this machine does not have a one-instruction return and uses an epilogue, or if it returns a structure, or if it has parm cleanups. */ #ifdef HAVE_return if (cleanup_label == 0 && HAVE_return && ! current_function_instrument_entry_exit && ! current_function_returns_pcc_struct && ! (current_function_returns_struct && ! optimize)) return_label = 0; else return_label = gen_label_rtx (); #else return_label = gen_label_rtx (); #endif /* Initialize rtx used to return the value. */ /* Do this before assign_parms so that we copy the struct value address before any library calls that assign parms might generate. */ /* Decide whether to return the value in memory or in a register. */ if (aggregate_value_p (DECL_RESULT (subr))) { /* Returning something that won't go in a register. */ register rtx value_address = 0; #ifdef PCC_STATIC_STRUCT_RETURN if (current_function_returns_pcc_struct) { int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); value_address = assemble_static_space (size); } else #endif { /* Expect to be passed the address of a place to store the value. If it is passed as an argument, assign_parms will take care of it. */ if (struct_value_incoming_rtx) { value_address = gen_reg_rtx (Pmode); emit_move_insn (value_address, struct_value_incoming_rtx); } } if (value_address) { DECL_RTL (DECL_RESULT (subr)) = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address); MEM_SET_IN_STRUCT_P (DECL_RTL (DECL_RESULT (subr)), AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)))); } } else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) /* If return mode is void, this decl rtl should not be used. */ DECL_RTL (DECL_RESULT (subr)) = 0; else if (parms_have_cleanups || current_function_instrument_entry_exit) { /* If function will end with cleanup code for parms, compute the return values into a pseudo reg, which we will copy into the true return register after the cleanups are done. */ enum machine_mode mode = DECL_MODE (DECL_RESULT (subr)); #ifdef PROMOTE_FUNCTION_RETURN tree type = TREE_TYPE (DECL_RESULT (subr)); int unsignedp = TREE_UNSIGNED (type); mode = promote_mode (type, mode, &unsignedp, 1); #endif DECL_RTL (DECL_RESULT (subr)) = gen_reg_rtx (mode); } else /* Scalar, returned in a register. */ { #ifdef FUNCTION_OUTGOING_VALUE DECL_RTL (DECL_RESULT (subr)) = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); #else DECL_RTL (DECL_RESULT (subr)) = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr); #endif /* Mark this reg as the function's return value. */ if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG) { REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1; /* Needed because we may need to move this to memory in case it's a named return value whose address is taken. */ DECL_REGISTER (DECL_RESULT (subr)) = 1; } } /* Initialize rtx for parameters and local variables. In some cases this requires emitting insns. */ assign_parms (subr, 0); /* Copy the static chain now if it wasn't a register. The delay is to avoid conflicts with the parameter passing registers. */ if (SMALL_REGISTER_CLASSES && current_function_needs_context) if (GET_CODE (static_chain_incoming_rtx) != REG) emit_move_insn (last_ptr, static_chain_incoming_rtx); /* The following was moved from init_function_start. The move is supposed to make sdb output more accurate. */ /* Indicate the beginning of the function body, as opposed to parm setup. */ emit_note (NULL_PTR, NOTE_INSN_FUNCTION_BEG); /* If doing stupid allocation, mark parms as born here. */ if (GET_CODE (get_last_insn ()) != NOTE) emit_note (NULL_PTR, NOTE_INSN_DELETED); parm_birth_insn = get_last_insn (); if (obey_regdecls) { for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) use_variable (regno_reg_rtx[i]); if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) use_variable (current_function_internal_arg_pointer); } context_display = 0; if (current_function_needs_context) { /* Fetch static chain values for containing functions. */ tem = decl_function_context (current_function_decl); /* If not doing stupid register allocation copy the static chain pointer into a pseudo. If we have small register classes, copy the value from memory if static_chain_incoming_rtx is a REG. If we do stupid register allocation, we use the stack address generated above. */ if (tem && ! obey_regdecls) { /* If the static chain originally came in a register, put it back there, then move it out in the next insn. The reason for this peculiar code is to satisfy function integration. */ if (SMALL_REGISTER_CLASSES && GET_CODE (static_chain_incoming_rtx) == REG) emit_move_insn (static_chain_incoming_rtx, last_ptr); last_ptr = copy_to_reg (static_chain_incoming_rtx); } while (tem) { tree rtlexp = make_node (RTL_EXPR); RTL_EXPR_RTL (rtlexp) = last_ptr; context_display = tree_cons (tem, rtlexp, context_display); tem = decl_function_context (tem); if (tem == 0) break; /* Chain thru stack frames, assuming pointer to next lexical frame is found at the place we always store it. */ #ifdef FRAME_GROWS_DOWNWARD last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode)); #endif last_ptr = copy_to_reg (gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr))); /* If we are not optimizing, ensure that we know that this piece of context is live over the entire function. */ if (! optimize) save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr, save_expr_regs); } } if (current_function_instrument_entry_exit) { rtx fun = DECL_RTL (current_function_decl); if (GET_CODE (fun) == MEM) fun = XEXP (fun, 0); else abort (); emit_library_call (profile_function_entry_libfunc, 0, VOIDmode, 2, fun, Pmode, expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 0, hard_frame_pointer_rtx), Pmode); } /* After the display initializations is where the tail-recursion label should go, if we end up needing one. Ensure we have a NOTE here since some things (like trampolines) get placed before this. */ tail_recursion_reentry = emit_note (NULL_PTR, NOTE_INSN_DELETED); /* Evaluate now the sizes of any types declared among the arguments. */ for (tem = nreverse (get_pending_sizes ()); tem; tem = TREE_CHAIN (tem)) { expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, EXPAND_MEMORY_USE_BAD); /* Flush the queue in case this parameter declaration has side-effects. */ emit_queue (); } /* Make sure there is a line number after the function entry setup code. */ force_next_line_note (); } /* Generate RTL for the end of the current function. FILENAME and LINE are the current position in the source file. It is up to language-specific callers to do cleanups for parameters-- or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */ void expand_function_end (filename, line, end_bindings) char *filename; int line; int end_bindings; { register int i; tree link; #ifdef TRAMPOLINE_TEMPLATE static rtx initial_trampoline; #endif #ifdef NON_SAVING_SETJMP /* Don't put any variables in registers if we call setjmp on a machine that fails to restore the registers. */ if (NON_SAVING_SETJMP && current_function_calls_setjmp) { if (DECL_INITIAL (current_function_decl) != error_mark_node) setjmp_protect (DECL_INITIAL (current_function_decl)); setjmp_protect_args (); } #endif /* Save the argument pointer if a save area was made for it. */ if (arg_pointer_save_area) { /* arg_pointer_save_area may not be a valid memory address, so we have to check it and fix it if necessary. */ rtx seq; start_sequence (); emit_move_insn (validize_mem (arg_pointer_save_area), virtual_incoming_args_rtx); seq = gen_sequence (); end_sequence (); emit_insn_before (seq, tail_recursion_reentry); } /* Initialize any trampolines required by this function. */ for (link = trampoline_list; link; link = TREE_CHAIN (link)) { tree function = TREE_PURPOSE (link); rtx context = lookup_static_chain (function); rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link)); #ifdef TRAMPOLINE_TEMPLATE rtx blktramp; #endif rtx seq; #ifdef TRAMPOLINE_TEMPLATE /* First make sure this compilation has a template for initializing trampolines. */ if (initial_trampoline == 0) { end_temporary_allocation (); initial_trampoline = gen_rtx_MEM (BLKmode, assemble_trampoline_template ()); resume_temporary_allocation (); } #endif /* Generate insns to initialize the trampoline. */ start_sequence (); tramp = round_trampoline_addr (XEXP (tramp, 0)); #ifdef TRAMPOLINE_TEMPLATE blktramp = change_address (initial_trampoline, BLKmode, tramp); emit_block_move (blktramp, initial_trampoline, GEN_INT (TRAMPOLINE_SIZE), TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); #endif INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context); seq = get_insns (); end_sequence (); /* Put those insns at entry to the containing function (this one). */ emit_insns_before (seq, tail_recursion_reentry); } /* If we are doing stack checking and this function makes calls, do a stack probe at the start of the function to ensure we have enough space for another stack frame. */ if (flag_stack_check && ! STACK_CHECK_BUILTIN) { rtx insn, seq; for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) if (GET_CODE (insn) == CALL_INSN) { start_sequence (); probe_stack_range (STACK_CHECK_PROTECT, GEN_INT (STACK_CHECK_MAX_FRAME_SIZE)); seq = get_insns (); end_sequence (); emit_insns_before (seq, tail_recursion_reentry); break; } } /* Warn about unused parms if extra warnings were specified. */ if (warn_unused && extra_warnings) { tree decl; for (decl = DECL_ARGUMENTS (current_function_decl); decl; decl = TREE_CHAIN (decl)) if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) warning_with_decl (decl, "unused parameter `%s'"); } /* Delete handlers for nonlocal gotos if nothing uses them. */ if (nonlocal_goto_handler_slots != 0 && ! current_function_has_nonlocal_label) delete_handlers (); /* End any sequences that failed to be closed due to syntax errors. */ while (in_sequence_p ()) end_sequence (); /* Outside function body, can't compute type's actual size until next function's body starts. */ immediate_size_expand--; /* If doing stupid register allocation, mark register parms as dying here. */ if (obey_regdecls) { rtx tem; for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++) use_variable (regno_reg_rtx[i]); /* Likewise for the regs of all the SAVE_EXPRs in the function. */ for (tem = save_expr_regs; tem; tem = XEXP (tem, 1)) { use_variable (XEXP (tem, 0)); use_variable_after (XEXP (tem, 0), parm_birth_insn); } if (current_function_internal_arg_pointer != virtual_incoming_args_rtx) use_variable (current_function_internal_arg_pointer); } clear_pending_stack_adjust (); do_pending_stack_adjust (); /* Mark the end of the function body. If control reaches this insn, the function can drop through without returning a value. */ emit_note (NULL_PTR, NOTE_INSN_FUNCTION_END); /* Must mark the last line number note in the function, so that the test coverage code can avoid counting the last line twice. This just tells the code to ignore the immediately following line note, since there already exists a copy of this note somewhere above. This line number note is still needed for debugging though, so we can't delete it. */ if (flag_test_coverage) emit_note (NULL_PTR, NOTE_REPEATED_LINE_NUMBER); /* Output a linenumber for the end of the function. SDB depends on this. */ emit_line_note_force (filename, line); /* Output the label for the actual return from the function, if one is expected. This happens either because a function epilogue is used instead of a return instruction, or because a return was done with a goto in order to run local cleanups, or because of pcc-style structure returning. */ if (return_label) emit_label (return_label); /* C++ uses this. */ if (end_bindings) expand_end_bindings (0, 0, 0); /* Now handle any leftover exception regions that may have been created for the parameters. */ { rtx last = get_last_insn (); rtx label; expand_leftover_cleanups (); /* If the above emitted any code, may sure we jump around it. */ if (last != get_last_insn ()) { label = gen_label_rtx (); last = emit_jump_insn_after (gen_jump (label), last); last = emit_barrier_after (last); emit_label (label); } } if (current_function_instrument_entry_exit) { rtx fun = DECL_RTL (current_function_decl); if (GET_CODE (fun) == MEM) fun = XEXP (fun, 0); else abort (); emit_library_call (profile_function_exit_libfunc, 0, VOIDmode, 2, fun, Pmode, expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 0, hard_frame_pointer_rtx), Pmode); } /* If we had calls to alloca, and this machine needs an accurate stack pointer to exit the function, insert some code to save and restore the stack pointer. */ #ifdef EXIT_IGNORE_STACK if (! EXIT_IGNORE_STACK) #endif if (current_function_calls_alloca) { rtx tem = 0; emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); } /* If scalar return value was computed in a pseudo-reg, copy that to the hard return register. */ if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0 && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl))) >= FIRST_PSEUDO_REGISTER)) { rtx real_decl_result; #ifdef FUNCTION_OUTGOING_VALUE real_decl_result = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), current_function_decl); #else real_decl_result = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)), current_function_decl); #endif REG_FUNCTION_VALUE_P (real_decl_result) = 1; /* If this is a BLKmode structure being returned in registers, then use the mode computed in expand_return. */ if (GET_MODE (real_decl_result) == BLKmode) PUT_MODE (real_decl_result, GET_MODE (DECL_RTL (DECL_RESULT (current_function_decl)))); emit_move_insn (real_decl_result, DECL_RTL (DECL_RESULT (current_function_decl))); emit_insn (gen_rtx_USE (VOIDmode, real_decl_result)); /* The delay slot scheduler assumes that current_function_return_rtx holds the hard register containing the return value, not a temporary pseudo. */ current_function_return_rtx = real_decl_result; } /* If returning a structure, arrange to return the address of the value in a place where debuggers expect to find it. If returning a structure PCC style, the caller also depends on this value. And current_function_returns_pcc_struct is not necessarily set. */ if (current_function_returns_struct || current_function_returns_pcc_struct) { rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); #ifdef FUNCTION_OUTGOING_VALUE rtx outgoing = FUNCTION_OUTGOING_VALUE (build_pointer_type (type), current_function_decl); #else rtx outgoing = FUNCTION_VALUE (build_pointer_type (type), current_function_decl); #endif /* Mark this as a function return value so integrate will delete the assignment and USE below when inlining this function. */ REG_FUNCTION_VALUE_P (outgoing) = 1; emit_move_insn (outgoing, value_address); use_variable (outgoing); } /* If this is an implementation of __throw, do what's necessary to communicate between __builtin_eh_return and the epilogue. */ expand_eh_return (); /* Output a return insn if we are using one. Otherwise, let the rtl chain end here, to drop through into the epilogue. */ #ifdef HAVE_return if (HAVE_return) { emit_jump_insn (gen_return ()); emit_barrier (); } #endif /* Fix up any gotos that jumped out to the outermost binding level of the function. Must follow emitting RETURN_LABEL. */ /* If you have any cleanups to do at this point, and they need to create temporary variables, then you will lose. */ expand_fixups (get_insns ()); } /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */ static int *prologue; static int *epilogue; /* Create an array that records the INSN_UIDs of INSNS (either a sequence or a single insn). */ #if defined (HAVE_prologue) || defined (HAVE_epilogue) static int * record_insns (insns) rtx insns; { int *vec; if (GET_CODE (insns) == SEQUENCE) { int len = XVECLEN (insns, 0); vec = (int *) oballoc ((len + 1) * sizeof (int)); vec[len] = 0; while (--len >= 0) vec[len] = INSN_UID (XVECEXP (insns, 0, len)); } else { vec = (int *) oballoc (2 * sizeof (int)); vec[0] = INSN_UID (insns); vec[1] = 0; } return vec; } /* Determine how many INSN_UIDs in VEC are part of INSN. */ static int contains (insn, vec) rtx insn; int *vec; { register int i, j; if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE) { int count = 0; for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) for (j = 0; vec[j]; j++) if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == vec[j]) count++; return count; } else { for (j = 0; vec[j]; j++) if (INSN_UID (insn) == vec[j]) return 1; } return 0; } #endif /* HAVE_prologue || HAVE_epilogue */ /* Generate the prologue and epilogue RTL if the machine supports it. Thread this into place with notes indicating where the prologue ends and where the epilogue begins. Update the basic block information when possible. */ void thread_prologue_and_epilogue_insns (f) rtx f ATTRIBUTE_UNUSED; { - int insertted = 0; + int inserted = 0; +#ifdef HAVE_prologue + rtx prologue_end = NULL_RTX; +#endif prologue = 0; #ifdef HAVE_prologue if (HAVE_prologue) { rtx seq; start_sequence (); seq = gen_prologue(); emit_insn (seq); /* Retain a map of the prologue insns. */ if (GET_CODE (seq) != SEQUENCE) seq = get_insns (); prologue = record_insns (seq); - emit_note (NULL, NOTE_INSN_PROLOGUE_END); + prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END); seq = gen_sequence (); end_sequence (); /* If optimization is off, and perhaps in an empty function, the entry block will have no successors. */ if (ENTRY_BLOCK_PTR->succ) { /* Can't deal with multiple successsors of the entry block. */ if (ENTRY_BLOCK_PTR->succ->succ_next) abort (); insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ); - insertted = 1; + inserted = 1; } else emit_insn_after (seq, f); } #endif epilogue = 0; #ifdef HAVE_epilogue if (HAVE_epilogue) { edge e; basic_block bb = 0; rtx tail = get_last_insn (); /* ??? This is gastly. If function returns were not done via uses, but via mark_regs_live_at_end, we could use insert_insn_on_edge and all of this uglyness would go away. */ switch (optimize) { default: /* If the exit block has no non-fake predecessors, we don't need an epilogue. Furthermore, only pay attention to the fallthru predecessors; if (conditional) return insns were generated, by definition we do not need to emit epilogue insns. */ for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next) if ((e->flags & EDGE_FAKE) == 0 && (e->flags & EDGE_FALLTHRU) != 0) break; if (e == NULL) break; /* We can't handle multiple epilogues -- if one is needed, we won't be able to place it multiple times. ??? Fix epilogue expanders to not assume they are the last thing done compiling the function. Either that or copy_rtx each insn. ??? Blah, it's not a simple expression to assert that we've exactly one fallthru exit edge. */ bb = e->src; tail = bb->end; /* ??? If the last insn of the basic block is a jump, then we are creating a new basic block. Wimp out and leave these insns outside any block. */ if (GET_CODE (tail) == JUMP_INSN) bb = 0; /* FALLTHRU */ case 0: { rtx prev, seq, first_use; /* Move the USE insns at the end of a function onto a list. */ prev = tail; if (GET_CODE (prev) == BARRIER || GET_CODE (prev) == NOTE) prev = prev_nonnote_insn (prev); first_use = 0; if (prev && GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == USE) { /* If the end of the block is the use, grab hold of something else so that we emit barriers etc in the right place. */ if (prev == tail) { do tail = PREV_INSN (tail); while (GET_CODE (tail) == INSN && GET_CODE (PATTERN (tail)) == USE); } do { rtx use = prev; prev = prev_nonnote_insn (prev); remove_insn (use); if (first_use) { NEXT_INSN (use) = first_use; PREV_INSN (first_use) = use; } else NEXT_INSN (use) = NULL_RTX; first_use = use; } while (prev && GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == USE); } /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the epilogue insns, the USE insns at the end of a function, the jump insn that returns, and then a BARRIER. */ if (GET_CODE (tail) != BARRIER) { prev = next_nonnote_insn (tail); if (!prev || GET_CODE (prev) != BARRIER) emit_barrier_after (tail); } seq = gen_epilogue (); prev = tail; tail = emit_jump_insn_after (seq, tail); /* Insert the USE insns immediately before the return insn, which must be the last instruction emitted in the sequence. */ if (first_use) emit_insns_before (first_use, tail); emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev); /* Update the tail of the basic block. */ if (bb) bb->end = tail; /* Retain a map of the epilogue insns. */ epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail); } } } #endif - if (insertted) + if (inserted) commit_edge_insertions (); + +#ifdef HAVE_prologue + if (prologue_end) + { + rtx insn, prev; + + /* GDB handles `break f' by setting a breakpoint on the first + line note *after* the prologue. Which means (1) that if + there are line number notes before where we inserted the + prologue we should move them, and (2) if there is no such + note, then we should generate one at the prologue. */ + + for (insn = prologue_end; insn ; insn = prev) + { + prev = PREV_INSN (insn); + if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) + { + /* Note that we cannot reorder the first insn in the + chain, since rest_of_compilation relies on that + remaining constant. Do the next best thing. */ + if (prev == NULL) + { + emit_line_note_after (NOTE_SOURCE_FILE (insn), + NOTE_LINE_NUMBER (insn), + prologue_end); + NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED; + } + else + reorder_insns (insn, insn, prologue_end); + } + } + + insn = NEXT_INSN (prologue_end); + if (! insn || GET_CODE (insn) != NOTE || NOTE_LINE_NUMBER (insn) <= 0) + { + for (insn = next_active_insn (f); insn ; insn = PREV_INSN (insn)) + { + if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) + { + emit_line_note_after (NOTE_SOURCE_FILE (insn), + NOTE_LINE_NUMBER (insn), + prologue_end); + break; + } + } + } + } + #endif } /* Reposition the prologue-end and epilogue-begin notes after instruction scheduling and delayed branch scheduling. */ void reposition_prologue_and_epilogue_notes (f) rtx f ATTRIBUTE_UNUSED; { #if defined (HAVE_prologue) || defined (HAVE_epilogue) /* Reposition the prologue and epilogue notes. */ if (n_basic_blocks) { int len; if (prologue) { register rtx insn, note = 0; /* Scan from the beginning until we reach the last prologue insn. We apparently can't depend on basic_block_{head,end} after reorg has run. */ for (len = 0; prologue[len]; len++) ; for (insn = f; len && insn; insn = NEXT_INSN (insn)) { if (GET_CODE (insn) == NOTE) { if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END) note = insn; } else if ((len -= contains (insn, prologue)) == 0) { rtx next; /* Find the prologue-end note if we haven't already, and move it to just after the last prologue insn. */ if (note == 0) { for (note = insn; (note = NEXT_INSN (note));) if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END) break; } next = NEXT_INSN (note); /* Whether or not we can depend on BLOCK_HEAD, attempt to keep it up-to-date. */ if (BLOCK_HEAD (0) == note) BLOCK_HEAD (0) = next; remove_insn (note); add_insn_after (note, insn); } } } if (epilogue) { register rtx insn, note = 0; /* Scan from the end until we reach the first epilogue insn. We apparently can't depend on basic_block_{head,end} after reorg has run. */ for (len = 0; epilogue[len]; len++) ; for (insn = get_last_insn (); len && insn; insn = PREV_INSN (insn)) { if (GET_CODE (insn) == NOTE) { if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG) note = insn; } else if ((len -= contains (insn, epilogue)) == 0) { /* Find the epilogue-begin note if we haven't already, and move it to just before the first epilogue insn. */ if (note == 0) { for (note = insn; (note = PREV_INSN (note));) if (GET_CODE (note) == NOTE && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG) break; } /* Whether or not we can depend on BLOCK_HEAD, attempt to keep it up-to-date. */ if (n_basic_blocks && BLOCK_HEAD (n_basic_blocks-1) == insn) BLOCK_HEAD (n_basic_blocks-1) = note; remove_insn (note); add_insn_before (note, insn); } } } } #endif /* HAVE_prologue or HAVE_epilogue */ } Index: head/contrib/gcc/invoke.texi =================================================================== --- head/contrib/gcc/invoke.texi (revision 60969) +++ head/contrib/gcc/invoke.texi (revision 60970) @@ -1,6780 +1,6794 @@ @c Copyright (C) 1988, 89, 92-98, 1999 Free Software Foundation, Inc. @c This is part of the GCC manual. @c For copying conditions, see the file gcc.texi. @c $FreeBSD$ @node Invoking GCC @chapter GCC Command Options @cindex GCC command options @cindex command options @cindex options, GCC command When you invoke GCC, it normally does preprocessing, compilation, assembly and linking. The ``overall options'' allow you to stop this process at an intermediate stage. For example, the @samp{-c} option says not to run the linker. Then the output consists of object files output by the assembler. Other options are passed on to one stage of processing. Some options control the preprocessor and others the compiler itself. Yet other options control the assembler and linker; most of these are not documented here, since you rarely need to use any of them. @cindex C compilation options Most of the command line options that you can use with GCC are useful for C programs; when an option is only useful with another language (usually C++), the explanation says so explicitly. If the description for a particular option does not mention a source language, you can use that option with all supported languages. @cindex C++ compilation options @xref{Invoking G++,,Compiling C++ Programs}, for a summary of special options for compiling C++ programs. @cindex grouping options @cindex options, grouping The @code{gcc} program accepts options and file names as operands. Many options have multiletter names; therefore multiple single-letter options may @emph{not} be grouped: @samp{-dr} is very different from @w{@samp{-d -r}}. @cindex order of options @cindex options, order You can mix options and other arguments. For the most part, the order you use doesn't matter. Order does matter when you use several options of the same kind; for example, if you specify @samp{-L} more than once, the directories are searched in the order specified. Many options have long names starting with @samp{-f} or with @samp{-W}---for example, @samp{-fforce-mem}, @samp{-fstrength-reduce}, @samp{-Wformat} and so on. Most of these have both positive and negative forms; the negative form of @samp{-ffoo} would be @samp{-fno-foo}. This manual documents only one of these two forms, whichever one is not the default. @menu * Option Summary:: Brief list of all options, without explanations. * Overall Options:: Controlling the kind of output: an executable, object files, assembler files, or preprocessed source. * Invoking G++:: Compiling C++ programs. * C Dialect Options:: Controlling the variant of C language compiled. * C++ Dialect Options:: Variations on C++. * Warning Options:: How picky should the compiler be? * Debugging Options:: Symbol tables, measurements, and debugging dumps. * Optimize Options:: How much optimization? * Preprocessor Options:: Controlling header files and macro definitions. Also, getting dependency information for Make. * Assembler Options:: Passing options to the assembler. * Link Options:: Specifying libraries and so on. * Directory Options:: Where to find header files and libraries. Where to find the compiler executable files. * Target Options:: Running a cross-compiler, or an old version of GCC. * Submodel Options:: Specifying minor hardware or convention variations, such as 68010 vs 68020. * Code Gen Options:: Specifying conventions for function calls, data layout and register usage. * Environment Variables:: Env vars that affect GCC. * Running Protoize:: Automatically adding or removing function prototypes. @end menu @node Option Summary @section Option Summary Here is a summary of all the options, grouped by type. Explanations are in the following sections. @table @emph @item Overall Options @xref{Overall Options,,Options Controlling the Kind of Output}. @smallexample -c -S -E -o @var{file} -pipe -v --help -x @var{language} @end smallexample @item C Language Options @xref{C Dialect Options,,Options Controlling C Dialect}. @smallexample -ansi -fstd -fallow-single-precision -fcond-mismatch -fno-asm -fno-builtin -ffreestanding -fhosted -fsigned-bitfields -fsigned-char -funsigned-bitfields -funsigned-char -fwritable-strings -traditional -traditional-cpp -trigraphs @end smallexample @item C++ Language Options @xref{C++ Dialect Options,,Options Controlling C++ Dialect}. @smallexample -fno-access-control -fcheck-new -fconserve-space -fdollars-in-identifiers -fno-elide-constructors -fexternal-templates -ffor-scope -fno-for-scope -fno-gnu-keywords -fguiding-decls -fhandle-signatures -fhonor-std -fhuge-objects -fno-implicit-templates -finit-priority -fno-implement-inlines -fname-mangling-version-@var{n} -fno-default-inline -foperator-names -fno-optional-diags -fpermissive -frepo -fstrict-prototype -fsquangle -ftemplate-depth-@var{n} -fthis-is-variable -fvtable-thunks -nostdinc++ -Wctor-dtor-privacy -Wno-deprecated -Weffc++ -Wno-non-template-friend -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wno-pmf-conversions -Wreorder -Wsign-promo -Wsynth @end smallexample @item Warning Options @xref{Warning Options,,Options to Request or Suppress Warnings}. @smallexample -fsyntax-only -pedantic -pedantic-errors -w -W -Wall -Waggregate-return -Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment -Wconversion -Werror -Wformat -Wid-clash-@var{len} -Wimplicit -Wimplicit-int -Wimplicit-function-declaration -Wimport -Werror-implicit-function-declaration -Winline -Wlarger-than-@var{len} -Wlong-long -Wmain -Wmissing-declarations -Wmissing-noreturn -Wmissing-prototypes -Wmultichar -Wnested-externs -Wno-import -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wshadow -Wsign-compare -Wstrict-prototypes -Wswitch -Wtraditional -Wtrigraphs -Wundef -Wuninitialized -Wunused -Wwrite-strings -Wunknown-pragmas @end smallexample @item Debugging Options @xref{Debugging Options,,Options for Debugging Your Program or GCC}. @smallexample -a -ax -d@var{letters} -fdump-unnumbered -fpretend-float -fprofile-arcs -ftest-coverage -g -g@var{level} -gcoff -gdwarf -gdwarf-1 -gdwarf-1+ -gdwarf-2 -ggdb -gstabs -gstabs+ -gxcoff -gxcoff+ -p -pg -print-file-name=@var{library} -print-libgcc-file-name -print-prog-name=@var{program} -print-search-dirs -save-temps @end smallexample @item Optimization Options @xref{Optimize Options,,Options that Control Optimization}. @smallexample -fbranch-probabilities -foptimize-register-moves -fcaller-saves -fcse-follow-jumps -fcse-skip-blocks -fdelayed-branch -fexpensive-optimizations -ffast-math -ffloat-store -fforce-addr -fforce-mem -fdata-sections -ffunction-sections -fgcse -finline-functions -finline-limit-@var{n} -fkeep-inline-functions -fno-default-inline -fno-defer-pop -fno-function-cse -fno-inline -fno-peephole -fomit-frame-pointer -fregmove -frerun-cse-after-loop -frerun-loop-opt -fschedule-insns -fschedule-insns2 -fstrength-reduce -fthread-jumps -funroll-all-loops -funroll-loops -fmove-all-movables -freduce-all-givs -fstrict-aliasing -O -O0 -O1 -O2 -O3 -Os @end smallexample @item Preprocessor Options @xref{Preprocessor Options,,Options Controlling the Preprocessor}. @smallexample -A@var{question}(@var{answer}) -C -dD -dM -dN -D@var{macro}@r{[}=@var{defn}@r{]} -E -H -idirafter @var{dir} -include @var{file} -imacros @var{file} -iprefix @var{file} -iwithprefix @var{dir} -iwithprefixbefore @var{dir} -isystem @var{dir} -isystem-c++ @var{dir} -M -MD -MM -MMD -MG -nostdinc -P -trigraphs -undef -U@var{macro} -Wp,@var{option} @end smallexample @item Assembler Option @xref{Assembler Options,,Passing Options to the Assembler}. @smallexample -Wa,@var{option} @end smallexample @item Linker Options @xref{Link Options,,Options for Linking}. @smallexample @var{object-file-name} -l@var{library} -nostartfiles -nodefaultlibs -nostdlib -s -static -shared -symbolic -Wl,@var{option} -Xlinker @var{option} -u @var{symbol} @end smallexample @item Directory Options @xref{Directory Options,,Options for Directory Search}. @smallexample -B@var{prefix} -I@var{dir} -I- -L@var{dir} -specs=@var{file} @end smallexample @item Target Options @c I wrote this xref this way to avoid overfull hbox. -- rms @xref{Target Options}. @smallexample -b @var{machine} -V @var{version} @end smallexample @item Machine Dependent Options @xref{Submodel Options,,Hardware Models and Configurations}. @smallexample @emph{M680x0 Options} -m68000 -m68020 -m68020-40 -m68020-60 -m68030 -m68040 -m68060 -mcpu32 -m5200 -m68881 -mbitfield -mc68000 -mc68020 -mfpa -mnobitfield -mrtd -mshort -msoft-float -malign-int @emph{VAX Options} -mg -mgnu -munix @emph{SPARC Options} -mcpu=@var{cpu type} -mtune=@var{cpu type} -mcmodel=@var{code model} -malign-jumps=@var{num} -malign-loops=@var{num} -malign-functions=@var{num} -m32 -m64 -mapp-regs -mbroken-saverestore -mcypress -mepilogue -mflat -mfpu -mhard-float -mhard-quad-float -mimpure-text -mlive-g0 -mno-app-regs -mno-epilogue -mno-flat -mno-fpu -mno-impure-text -mno-stack-bias -mno-unaligned-doubles -msoft-float -msoft-quad-float -msparclite -mstack-bias -msupersparc -munaligned-doubles -mv8 @emph{Convex Options} -mc1 -mc2 -mc32 -mc34 -mc38 -margcount -mnoargcount -mlong32 -mlong64 -mvolatile-cache -mvolatile-nocache @emph{AMD29K Options} -m29000 -m29050 -mbw -mnbw -mdw -mndw -mlarge -mnormal -msmall -mkernel-registers -mno-reuse-arg-regs -mno-stack-check -mno-storem-bug -mreuse-arg-regs -msoft-float -mstack-check -mstorem-bug -muser-registers @emph{ARM Options} -mapcs-frame -mno-apcs-frame -mapcs-26 -mapcs-32 -mapcs-stack-check -mno-apcs-stack-check -mapcs-float -mno-apcs-float -mapcs-reentrant -mno-apcs-reentrant -msched-prolog -mno-sched-prolog -mlittle-endian -mbig-endian -mwords-little-endian -mshort-load-bytes -mno-short-load-bytes -mshort-load-words -mno-short-load-words -msoft-float -mhard-float -mfpe -mthumb-interwork -mno-thumb-interwork -mcpu= -march= -mfpe= -mstructure-size-boundary= -mbsd -mxopen -mno-symrename -mabort-on-noreturn -mno-sched-prolog @emph{Thumb Options} -mtpcs-frame -mno-tpcs-frame -mtpcs-leaf-frame -mno-tpcs-leaf-frame -mlittle-endian -mbig-endian -mthumb-interwork -mno-thumb-interwork -mstructure-size-boundary= @emph{MN10200 Options} -mrelax @emph{MN10300 Options} -mmult-bug -mno-mult-bug -mrelax @emph{M32R/D Options} -mcode-model=@var{model type} -msdata=@var{sdata type} -G @var{num} @emph{M88K Options} -m88000 -m88100 -m88110 -mbig-pic -mcheck-zero-division -mhandle-large-shift -midentify-revision -mno-check-zero-division -mno-ocs-debug-info -mno-ocs-frame-position -mno-optimize-arg-area -mno-serialize-volatile -mno-underscores -mocs-debug-info -mocs-frame-position -moptimize-arg-area -mserialize-volatile -mshort-data-@var{num} -msvr3 -msvr4 -mtrap-large-shift -muse-div-instruction -mversion-03.00 -mwarn-passed-structs @emph{RS/6000 and PowerPC Options} -mcpu=@var{cpu type} -mtune=@var{cpu type} -mpower -mno-power -mpower2 -mno-power2 -mpowerpc -mno-powerpc -mpowerpc-gpopt -mno-powerpc-gpopt -mpowerpc-gfxopt -mno-powerpc-gfxopt -mnew-mnemonics -mno-new-mnemonics -mfull-toc -mminimal-toc -mno-fop-in-toc -mno-sum-in-toc -maix64 -maix32 -mxl-call -mno-xl-call -mthreads -mpe -msoft-float -mhard-float -mmultiple -mno-multiple -mstring -mno-string -mupdate -mno-update -mfused-madd -mno-fused-madd -mbit-align -mno-bit-align -mstrict-align -mno-strict-align -mrelocatable -mno-relocatable -mrelocatable-lib -mno-relocatable-lib -mtoc -mno-toc -mlittle -mlittle-endian -mbig -mbig-endian -mcall-aix -mcall-sysv -mprototype -mno-prototype -msim -mmvme -mads -myellowknife -memb -msdata -msdata=@var{opt} -G @var{num} @emph{RT Options} -mcall-lib-mul -mfp-arg-in-fpregs -mfp-arg-in-gregs -mfull-fp-blocks -mhc-struct-return -min-line-mul -mminimum-fp-blocks -mnohc-struct-return @emph{MIPS Options} -mabicalls -mcpu=@var{cpu type} -membedded-data -membedded-pic -mfp32 -mfp64 -mgas -mgp32 -mgp64 -mgpopt -mhalf-pic -mhard-float -mint64 -mips1 -mips2 -mips3 -mips4 -mlong64 -mlong32 -mlong-calls -mmemcpy -mmips-as -mmips-tfile -mno-abicalls -mno-embedded-data -mno-embedded-pic -mno-gpopt -mno-long-calls -mno-memcpy -mno-mips-tfile -mno-rnames -mno-stats -mrnames -msoft-float -m4650 -msingle-float -mmad -mstats -EL -EB -G @var{num} -nocpp -mabi=32 -mabi=n32 -mabi=64 -mabi=eabi @emph{i386 Options} -mcpu=@var{cpu type} -march=@var{cpu type} -m386 -m486 -malign-double -mieee-fp -mno-fancy-math-387 -mno-fp-ret-in-387 -mno-ieee-fp -mno-wide-multiply -mprofiler-epilogue -mrtd -msoft-float -msvr3-shlib -mreg-alloc=@var{list} -mregparm=@var{num} -malign-jumps=@var{num} -malign-loops=@var{num} -malign-functions=@var{num} -mpreferred-stack-boundary=@var{num} @emph{HPPA Options} -march=@var{architecture type} -mbig-switch -mdisable-fpregs -mdisable-indexing -mfast-indirect-calls -mgas -mjump-in-delay -mlong-load-store -mno-big-switch -mno-disable-fpregs -mno-disable-indexing -mno-fast-indirect-calls -mno-gas -mno-jump-in-delay -mno-long-load-store -mno-portable-runtime -mno-soft-float -mno-space -mno-space-regs -msoft-float -mpa-risc-1-0 -mpa-risc-1-1 -mpa-risc-2-0 -mportable-runtime -mschedule=@var{cpu type} -mspace -mspace-regs @emph{Intel 960 Options} -m@var{cpu type} -masm-compat -mclean-linkage -mcode-align -mcomplex-addr -mleaf-procedures -mic-compat -mic2.0-compat -mic3.0-compat -mintel-asm -mno-clean-linkage -mno-code-align -mno-complex-addr -mno-leaf-procedures -mno-old-align -mno-strict-align -mno-tail-call -mnumerics -mold-align -msoft-float -mstrict-align -mtail-call @emph{DEC Alpha Options} -mfp-regs -mno-fp-regs -mno-soft-float -msoft-float -malpha-as -mgas -mieee -mieee-with-inexact -mieee-conformant -mfp-trap-mode=@var{mode} -mfp-rounding-mode=@var{mode} -mtrap-precision=@var{mode} -mbuild-constants -mcpu=@var{cpu type} -mbwx -mno-bwx -mcix -mno-cix -mmax -mno-max -mmemory-latency=@var{time} @emph{Clipper Options} -mc300 -mc400 @emph{H8/300 Options} -mrelax -mh -ms -mint32 -malign-300 @emph{SH Options} -m1 -m2 -m3 -m3e -mb -ml -mdalign -mrelax @emph{System V Options} -Qy -Qn -YP,@var{paths} -Ym,@var{dir} @emph{ARC Options} -EB -EL -mmangle-cpu -mcpu=@var{cpu} -mtext=@var{text section} -mdata=@var{data section} -mrodata=@var{readonly data section} @emph{TMS320C3x/C4x Options} -mcpu=@var{cpu} -mbig -msmall -mregparm -mmemparm -mfast-fix -mmpyi -mbk -mti -mdp-isr-reload -mrpts=@var{count} -mrptb -mdb -mloop-unsigned -mparallel-insns -mparallel-mpy -mpreserve-float @emph{V850 Options} -mlong-calls -mno-long-calls -mep -mno-ep -mprolog-function -mno-prolog-function -mspace -mtda=@var{n} -msda=@var{n} -mzda=@var{n} -mv850 -mbig-switch @emph{NS32K Options} -m32032 -m32332 -m32532 -m32081 -m32381 -mmult-add -mnomult-add -msoft-float -mrtd -mnortd -mregparam -mnoregparam -msb -mnosb -mbitfield -mnobitfield -mhimem -mnohimem @end smallexample @item Code Generation Options @xref{Code Gen Options,,Options for Code Generation Conventions}. @smallexample -fcall-saved-@var{reg} -fcall-used-@var{reg} -fexceptions -ffixed-@var{reg} -finhibit-size-directive -fcheck-memory-usage -fprefix-function-name -fno-common -fno-ident -fno-gnu-linker -fpcc-struct-return -fpic -fPIC -freg-struct-return -fshared-data -fshort-enums -fshort-double -fvolatile -fvolatile-global -fvolatile-static -fverbose-asm -fpack-struct -fstack-check -fargument-alias -fargument-noalias -fargument-noalias-global -fleading-underscore @end smallexample @end table @menu * Overall Options:: Controlling the kind of output: an executable, object files, assembler files, or preprocessed source. * C Dialect Options:: Controlling the variant of C language compiled. * C++ Dialect Options:: Variations on C++. * Warning Options:: How picky should the compiler be? * Debugging Options:: Symbol tables, measurements, and debugging dumps. * Optimize Options:: How much optimization? * Preprocessor Options:: Controlling header files and macro definitions. Also, getting dependency information for Make. * Assembler Options:: Passing options to the assembler. * Link Options:: Specifying libraries and so on. * Directory Options:: Where to find header files and libraries. Where to find the compiler executable files. * Target Options:: Running a cross-compiler, or an old version of GCC. @end menu @node Overall Options @section Options Controlling the Kind of Output Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order. The first three stages apply to an individual source file, and end by producing an object file; linking combines all the object files (those newly compiled, and those specified as input) into an executable file. @cindex file name suffix For any given input file, the file name suffix determines what kind of compilation is done: @table @code @item @var{file}.c C source code which must be preprocessed. @item @var{file}.i C source code which should not be preprocessed. @item @var{file}.ii C++ source code which should not be preprocessed. @item @var{file}.m Objective-C source code. Note that you must link with the library @file{libobjc.a} to make an Objective-C program work. @item @var{file}.h C header file (not to be compiled or linked). @item @var{file}.cc @itemx @var{file}.cxx @itemx @var{file}.cpp @itemx @var{file}.C C++ source code which must be preprocessed. Note that in @samp{.cxx}, the last two letters must both be literally @samp{x}. Likewise, @samp{.C} refers to a literal capital C. @item @var{file}.s Assembler code. @item @var{file}.S Assembler code which must be preprocessed. @item @var{other} An object file to be fed straight into linking. Any file name with no recognized suffix is treated this way. @end table You can specify the input language explicitly with the @samp{-x} option: @table @code @item -x @var{language} Specify explicitly the @var{language} for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next @samp{-x} option. Possible values for @var{language} are: @example c objective-c c++ c-header cpp-output c++-cpp-output assembler assembler-with-cpp @end example @item -x none Turn off any specification of a language, so that subsequent files are handled according to their file name suffixes (as they are if @samp{-x} has not been used at all). @end table If you only want some of the stages of compilation, you can use @samp{-x} (or filename suffixes) to tell @code{gcc} where to start, and one of the options @samp{-c}, @samp{-S}, or @samp{-E} to say where @code{gcc} is to stop. Note that some combinations (for example, @samp{-x cpp-output -E} instruct @code{gcc} to do nothing at all. @table @code @item -c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file. By default, the object file name for a source file is made by replacing the suffix @samp{.c}, @samp{.i}, @samp{.s}, etc., with @samp{.o}. Unrecognized input files, not requiring compilation or assembly, are ignored. @item -S Stop after the stage of compilation proper; do not assemble. The output is in the form of an assembler code file for each non-assembler input file specified. By default, the assembler file name for a source file is made by replacing the suffix @samp{.c}, @samp{.i}, etc., with @samp{.s}. Input files that don't require compilation are ignored. @item -E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output. Input files which don't require preprocessing are ignored. @cindex output file option @item -o @var{file} Place output in file @var{file}. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code. Since only one output file can be specified, it does not make sense to use @samp{-o} when compiling more than one input file, unless you are producing an executable file as output. If @samp{-o} is not specified, the default is to put an executable file in @file{a.out}, the object file for @file{@var{source}.@var{suffix}} in @file{@var{source}.o}, its assembler file in @file{@var{source}.s}, and all preprocessed C source on standard output.@refill @item -v Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper. @item -pipe Use pipes rather than temporary files for communication between the various stages of compilation. This fails to work on some systems where the assembler is unable to read from a pipe; but the GNU assembler has no trouble. @item --help Print (on the standard output) a description of the command line options understood by @code{gcc}. If the @code{-v} option is also specified then @code{--help} will also be passed on to the various processes invoked by @code{gcc}, so that they can display the command line options they accept. If the @code{-W} option is also specified then command line options which have no documentation associated with them will also be displayed. @end table @node Invoking G++ @section Compiling C++ Programs @cindex suffixes for C++ source @cindex C++ source file suffixes C++ source files conventionally use one of the suffixes @samp{.C}, @samp{.cc}, @samp{.cpp}, @samp{.c++}, @samp{.cp}, or @samp{.cxx}; preprocessed C++ files use the suffix @samp{.ii}. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name @code{gcc}). @findex g++ @findex c++ However, C++ programs often require class libraries as well as a compiler that understands the C++ language---and under some circumstances, you might want to compile programs from standard input, or otherwise without a suffix that flags them as C++ programs. @code{g++} is a program that calls GCC with the default language set to C++, and automatically specifies linking against the C++ library. On many systems, the script @code{g++} is also installed with the name @code{c++}. @cindex invoking @code{g++} When you compile C++ programs, you may specify many of the same command-line options that you use for compiling programs in any language; or command-line options meaningful for C and related languages; or options that are meaningful only for C++ programs. @xref{C Dialect Options,,Options Controlling C Dialect}, for explanations of options for languages related to C. @xref{C++ Dialect Options,,Options Controlling C++ Dialect}, for explanations of options that are meaningful only for C++ programs. @node C Dialect Options @section Options Controlling C Dialect @cindex dialect options @cindex language dialect options @cindex options, dialect The following options control the dialect of C (or languages derived from C, such as C++ and Objective C) that the compiler accepts: @table @code @cindex ANSI support @item -ansi In C mode, support all ANSI standard C programs. In C++ mode, remove GNU extensions that conflict with ANSI C++. @c shouldn't we be saying "ISO"? This turns off certain features of GCC that are incompatible with ANSI C (when compiling C code), or of ANSI standard C++ (when compiling C++ code), such as the @code{asm} and @code{typeof} keywords, and predefined macros such as @code{unix} and @code{vax} that identify the type of system you are using. It also enables the undesirable and rarely used ANSI trigraph feature. For the C compiler, it disables recognition of C++ style @samp{//} comments as well as the @code{inline} keyword. For the C++ compiler, @samp{-foperator-names} is enabled as well. The alternate keywords @code{__asm__}, @code{__extension__}, @code{__inline__} and @code{__typeof__} continue to work despite @samp{-ansi}. You would not want to use them in an ANSI C program, of course, but it is useful to put them in header files that might be included in compilations done with @samp{-ansi}. Alternate predefined macros such as @code{__unix__} and @code{__vax__} are also available, with or without @samp{-ansi}. The @samp{-ansi} option does not cause non-ANSI programs to be rejected gratuitously. For that, @samp{-pedantic} is required in addition to @samp{-ansi}. @xref{Warning Options}. The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi} option is used. Some header files may notice this macro and refrain from declaring certain functions or defining certain macros that the ANSI standard doesn't call for; this is to avoid interfering with any programs that might use these names for other things. The functions @code{alloca}, @code{abort}, @code{exit}, and @code{_exit} are not builtin functions when @samp{-ansi} is used. @item -fstd= Determine the language standard. A value for this option must be provided; possible values are @itemize @minus @item iso9899:1990 Same as -ansi @item iso9899:199409 ISO C as modified in amend. 1 @item iso9899:199x ISO C 9x @item c89 same as -std=iso9899:1990 @item c9x same as -std=iso9899:199x @item gnu89 default, iso9899:1990 + gnu extensions @item gnu9x iso9899:199x + gnu extensions @end itemize Even when this option is not specified, you can still use some of the features of newer standards in so far as they do not conflict with previous C standards. For example, you may use @code{__restrict__} even when -fstd=c9x is not specified. @item -fno-asm Do not recognize @code{asm}, @code{inline} or @code{typeof} as a keyword, so that code can use these words as identifiers. You can use the keywords @code{__asm__}, @code{__inline__} and @code{__typeof__} instead. @samp{-ansi} implies @samp{-fno-asm}. In C++, this switch only affects the @code{typeof} keyword, since @code{asm} and @code{inline} are standard keywords. You may want to use the @samp{-fno-gnu-keywords} flag instead, as it also disables the other, C++-specific, extension keywords such as @code{headof}. @item -fno-builtin @cindex builtin functions @findex abort @findex abs @findex alloca @findex cos @findex exit @findex fabs @findex ffs @findex labs @findex memcmp @findex memcpy @findex sin @findex sqrt @findex strcmp @findex strcpy @findex strlen Don't recognize builtin functions that do not begin with @samp{__builtin_} as prefix. Currently, the functions affected include @code{abort}, @code{abs}, @code{alloca}, @code{cos}, @code{exit}, @code{fabs}, @code{ffs}, @code{labs}, @code{memcmp}, @code{memcpy}, @code{sin}, @code{sqrt}, @code{strcmp}, @code{strcpy}, and @code{strlen}. GCC normally generates special code to handle certain builtin functions more efficiently; for instance, calls to @code{alloca} may become single instructions that adjust the stack directly, and calls to @code{memcpy} may become inline copy loops. The resulting code is often both smaller and faster, but since the function calls no longer appear as such, you cannot set a breakpoint on those calls, nor can you change the behavior of the functions by linking with a different library. The @samp{-ansi} option prevents @code{alloca} and @code{ffs} from being builtin functions, since these functions do not have an ANSI standard meaning. @item -fhosted @cindex hosted environment Assert that compilation takes place in a hosted environment. This implies @samp{-fbuiltin}. A hosted environment is one in which the entire standard library is available, and in which @code{main} has a return type of @code{int}. Examples are nearly everything except a kernel. This is equivalent to @samp{-fno-freestanding}. @item -ffreestanding @cindex hosted environment Assert that compilation takes place in a freestanding environment. This implies @samp{-fno-builtin}. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at @code{main}. The most obvious example is an OS kernel. This is equivalent to @samp{-fno-hosted}. @item -trigraphs Support ANSI C trigraphs. You don't want to know about this brain-damage. The @samp{-ansi} option implies @samp{-trigraphs}. @cindex traditional C language @cindex C language, traditional @item -traditional Attempt to support some aspects of traditional C compilers. Specifically: @itemize @bullet @item All @code{extern} declarations take effect globally even if they are written inside of a function definition. This includes implicit declarations of functions. @item The newer keywords @code{typeof}, @code{inline}, @code{signed}, @code{const} and @code{volatile} are not recognized. (You can still use the alternative keywords such as @code{__typeof__}, @code{__inline__}, and so on.) @item Comparisons between pointers and integers are always allowed. @item Integer types @code{unsigned short} and @code{unsigned char} promote to @code{unsigned int}. @item Out-of-range floating point literals are not an error. @item Certain constructs which ANSI regards as a single invalid preprocessing number, such as @samp{0xe-0xd}, are treated as expressions instead. @item String ``constants'' are not necessarily constant; they are stored in writable space, and identical looking constants are allocated separately. (This is the same as the effect of @samp{-fwritable-strings}.) @cindex @code{longjmp} and automatic variables @item All automatic variables not declared @code{register} are preserved by @code{longjmp}. Ordinarily, GNU C follows ANSI C: automatic variables not declared @code{volatile} may be clobbered. @item @kindex \x @kindex \a @cindex escape sequences, traditional The character escape sequences @samp{\x} and @samp{\a} evaluate as the literal characters @samp{x} and @samp{a} respectively. Without @w{@samp{-traditional}}, @samp{\x} is a prefix for the hexadecimal representation of a character, and @samp{\a} produces a bell. @end itemize You may wish to use @samp{-fno-builtin} as well as @samp{-traditional} if your program uses names that are normally GNU C builtin functions for other purposes of its own. You cannot use @samp{-traditional} if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use @samp{-traditional} on such systems to compile files that include any system headers. The @samp{-traditional} option also enables @samp{-traditional-cpp}, which is described next. @item -traditional-cpp Attempt to support some aspects of traditional C preprocessors. Specifically: @itemize @bullet @item Comments convert to nothing at all, rather than to a space. This allows traditional token concatenation. @item In a preprocessing directive, the @samp{#} symbol must appear as the first character of a line. @item Macro arguments are recognized within string constants in a macro definition (and their values are stringified, though without additional quote marks, when they appear in such a context). The preprocessor always considers a string constant to end at a newline. @item @cindex detecting @w{@samp{-traditional}} The predefined macro @code{__STDC__} is not defined when you use @samp{-traditional}, but @code{__GNUC__} is (since the GNU extensions which @code{__GNUC__} indicates are not affected by @samp{-traditional}). If you need to write header files that work differently depending on whether @samp{-traditional} is in use, by testing both of these predefined macros you can distinguish four situations: GNU C, traditional GNU C, other ANSI C compilers, and other old C compilers. The predefined macro @code{__STDC_VERSION__} is also not defined when you use @samp{-traditional}. @xref{Standard Predefined,,Standard Predefined Macros,cpp.info,The C Preprocessor}, for more discussion of these and other predefined macros. @item @cindex string constants vs newline @cindex newline vs string constants The preprocessor considers a string constant to end at a newline (unless the newline is escaped with @samp{\}). (Without @w{@samp{-traditional}}, string constants can contain the newline character as typed.) @end itemize @item -fcond-mismatch Allow conditional expressions with mismatched types in the second and third arguments. The value of such an expression is void. @item -funsigned-char Let the type @code{char} be unsigned, like @code{unsigned char}. Each kind of machine has a default for what @code{char} should be. It is either like @code{unsigned char} by default or like @code{signed char} by default. Ideally, a portable program should always use @code{signed char} or @code{unsigned char} when it depends on the signedness of an object. But many programs have been written to use plain @code{char} and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. This option, and its inverse, let you make such a program work with the opposite default. The type @code{char} is always a distinct type from each of @code{signed char} or @code{unsigned char}, even though its behavior is always just like one of those two. @item -fsigned-char Let the type @code{char} be signed, like @code{signed char}. Note that this is equivalent to @samp{-fno-unsigned-char}, which is the negative form of @samp{-funsigned-char}. Likewise, the option @samp{-fno-signed-char} is equivalent to @samp{-funsigned-char}. You may wish to use @samp{-fno-builtin} as well as @samp{-traditional} if your program uses names that are normally GNU C builtin functions for other purposes of its own. You cannot use @samp{-traditional} if you include any header files that rely on ANSI C features. Some vendors are starting to ship systems with ANSI C header files and you cannot use @samp{-traditional} on such systems to compile files that include any system headers. @item -fsigned-bitfields @itemx -funsigned-bitfields @itemx -fno-signed-bitfields @itemx -fno-unsigned-bitfields These options control whether a bitfield is signed or unsigned, when the declaration does not use either @code{signed} or @code{unsigned}. By default, such a bitfield is signed, because this is consistent: the basic integer types such as @code{int} are signed types. However, when @samp{-traditional} is used, bitfields are all unsigned no matter what. @item -fwritable-strings Store string constants in the writable data segment and don't uniquize them. This is for compatibility with old programs which assume they can write into string constants. The option @samp{-traditional} also has this effect. Writing into string constants is a very bad idea; ``constants'' should be constant. @item -fallow-single-precision Do not promote single precision math operations to double precision, even when compiling with @samp{-traditional}. Traditional K&R C promotes all floating point operations to double precision, regardless of the sizes of the operands. On the architecture for which you are compiling, single precision may be faster than double precision. If you must use @samp{-traditional}, but want to use single precision operations when the operands are single precision, use this option. This option has no effect when compiling with ANSI or GNU C conventions (the default). @end table @node C++ Dialect Options @section Options Controlling C++ Dialect @cindex compiler options, C++ @cindex C++ options, command line @cindex options, C++ This section describes the command-line options that are only meaningful for C++ programs; but you can also use most of the GNU compiler options regardless of what language your program is in. For example, you might compile a file @code{firstClass.C} like this: @example g++ -g -frepo -O -c firstClass.C @end example @noindent In this example, only @samp{-frepo} is an option meant only for C++ programs; you can use the other options with any language supported by GCC. Here is a list of options that are @emph{only} for compiling C++ programs: @table @code @item -fno-access-control Turn off all access checking. This switch is mainly useful for working around bugs in the access control code. @item -fcheck-new Check that the pointer returned by @code{operator new} is non-null before attempting to modify the storage allocated. The current Working Paper requires that @code{operator new} never return a null pointer, so this check is normally unnecessary. An alternative to using this option is to specify that your @code{operator new} does not throw any exceptions; if you declare it @samp{throw()}, g++ will check the return value. See also @samp{new (nothrow)}. @item -fconserve-space Put uninitialized or runtime-initialized global variables into the common segment, as C does. This saves space in the executable at the cost of not diagnosing duplicate definitions. If you compile with this flag and your program mysteriously crashes after @code{main()} has completed, you may have an object that is being destroyed twice because two definitions were merged. This option is no longer useful on most targets, now that support has been added for putting variables into BSS without making them common. @item -fdollars-in-identifiers Accept @samp{$} in identifiers. You can also explicitly prohibit use of @samp{$} with the option @samp{-fno-dollars-in-identifiers}. (GNU C allows @samp{$} by default on most target systems, but there are a few exceptions.) Traditional C allowed the character @samp{$} to form part of identifiers. However, ANSI C and C++ forbid @samp{$} in identifiers. @item -fno-elide-constructors The C++ standard allows an implementation to omit creating a temporary which is only used to initialize another object of the same type. Specifying this option disables that optimization, and forces g++ to call the copy constructor in all cases. @item -fexternal-templates Cause template instantiations to obey @samp{#pragma interface} and @samp{implementation}; template instances are emitted or not according to the location of the template definition. @xref{Template Instantiation}, for more information. This option is deprecated. @item -falt-external-templates Similar to -fexternal-templates, but template instances are emitted or not according to the place where they are first instantiated. @xref{Template Instantiation}, for more information. This option is deprecated. @item -ffor-scope @itemx -fno-for-scope If -ffor-scope is specified, the scope of variables declared in a @i{for-init-statement} is limited to the @samp{for} loop itself, as specified by the draft C++ standard. If -fno-for-scope is specified, the scope of variables declared in a @i{for-init-statement} extends to the end of the enclosing scope, as was the case in old versions of gcc, and other (traditional) implementations of C++. The default if neither flag is given to follow the standard, but to allow and give a warning for old-style code that would otherwise be invalid, or have different behavior. @item -fno-gnu-keywords Do not recognize @code{classof}, @code{headof}, @code{signature}, @code{sigof} or @code{typeof} as a keyword, so that code can use these words as identifiers. You can use the keywords @code{__classof__}, @code{__headof__}, @code{__signature__}, @code{__sigof__}, and @code{__typeof__} instead. @samp{-ansi} implies @samp{-fno-gnu-keywords}. @item -fguiding-decls Treat a function declaration with the same type as a potential function template instantiation as though it declares that instantiation, not a normal function. If a definition is given for the function later in the translation unit (or another translation unit if the target supports weak symbols), that definition will be used; otherwise the template will be instantiated. This behavior reflects the C++ language prior to September 1996, when guiding declarations were removed. This option implies @samp{-fname-mangling-version-0}, and will not work with other name mangling versions. Like all options that change the ABI, all C++ code, @emph{including libgcc.a} must be built with the same setting of this option. @item -fhandle-signatures Recognize the @code{signature} and @code{sigof} keywords for specifying abstract types. The default (@samp{-fno-handle-signatures}) is not to recognize them. @xref{C++ Signatures, Type Abstraction using Signatures}. @item -fhonor-std Treat the @code{namespace std} as a namespace, instead of ignoring it. For compatibility with earlier versions of g++, the compiler will, by default, ignore @code{namespace-declarations}, @code{using-declarations}, @code{using-directives}, and @code{namespace-names}, if they involve @code{std}. @item -fhuge-objects Support virtual function calls for objects that exceed the size representable by a @samp{short int}. Users should not use this flag by default; if you need to use it, the compiler will tell you so. This flag is not useful when compiling with -fvtable-thunks. Like all options that change the ABI, all C++ code, @emph{including libgcc} must be built with the same setting of this option. @item -fno-implicit-templates Never emit code for non-inline templates which are instantiated implicitly (i.e. by use); only emit code for explicit instantiations. @xref{Template Instantiation}, for more information. @item -fno-implicit-inline-templates Don't emit code for implicit instantiations of inline templates, either. The default is to handle inlines differently so that compiles with and without optimization will need the same set of explicit instantiations. @item -finit-priority Support @samp{__attribute__ ((init_priority (n)))} for controlling the order of initialization of file-scope objects. On ELF targets, this requires GNU ld 2.10 or later. @item -fno-implement-inlines To save space, do not emit out-of-line copies of inline functions controlled by @samp{#pragma implementation}. This will cause linker errors if these functions are not inlined everywhere they are called. @item -fname-mangling-version-@var{n} Control the way in which names are mangled. Version 0 is compatible with versions of g++ before 2.8. Version 1 is the default. Version 1 will allow correct mangling of function templates. For example, version 0 mangling does not mangle foo and foo given this declaration: @example template void foo(T t); @end example Like all options that change the ABI, all C++ code, @emph{including libgcc} must be built with the same setting of this option. @item -foperator-names Recognize the operator name keywords @code{and}, @code{bitand}, @code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} as synonyms for the symbols they refer to. @samp{-ansi} implies @samp{-foperator-names}. @item -fno-optional-diags Disable diagnostics that the standard says a compiler does not need to issue. Currently, the only such diagnostic issued by g++ is the one for a name having multiple meanings within a class. @item -fpermissive Downgrade messages about nonconformant code from errors to warnings. By default, g++ effectively sets @samp{-pedantic-errors} without @samp{-pedantic}; this option reverses that. This behavior and this option are superceded by @samp{-pedantic}, which works as it does for GNU C. @item -frepo Enable automatic template instantiation. This option also implies @samp{-fno-implicit-templates}. @xref{Template Instantiation}, for more information. @item -fno-rtti Disable generation of the information used by C++ runtime type identification features (@samp{dynamic_cast} and @samp{typeid}). If you don't use those parts of the language (or exception handling, which uses @samp{dynamic_cast} internally), you can save some space by using this flag. @item -fstrict-prototype Within an @samp{extern "C"} linkage specification, treat a function declaration with no arguments, such as @samp{int foo ();}, as declaring the function to take no arguments. Normally, such a declaration means that the function @code{foo} can take any combination of arguments, as in C. @samp{-pedantic} implies @samp{-fstrict-prototype} unless overridden with @samp{-fno-strict-prototype}. Specifying this option will also suppress implicit declarations of functions. This flag no longer affects declarations with C++ linkage. @item -fsquangle @itemx -fno-squangle @samp{-fsquangle} will enable a compressed form of name mangling for identifiers. In particular, it helps to shorten very long names by recognizing types and class names which occur more than once, replacing them with special short ID codes. This option also requires any C++ libraries being used to be compiled with this option as well. The compiler has this disabled (the equivalent of @samp{-fno-squangle}) by default. Like all options that change the ABI, all C++ code, @emph{including libgcc.a} must be built with the same setting of this option. @item -ftemplate-depth-@var{n} Set the maximum instantiation depth for template classes to @var{n}. A limit on the template instantiation depth is needed to detect endless recursions during template class instantiation. ANSI/ISO C++ conforming programs must not rely on a maximum depth greater than 17. @item -fthis-is-variable Permit assignment to @code{this}. The incorporation of user-defined free store management into C++ has made assignment to @samp{this} an anachronism. Therefore, by default it is invalid to assign to @code{this} within a class member function; that is, GNU C++ treats @samp{this} in a member function of class @code{X} as a non-lvalue of type @samp{X *}. However, for backwards compatibility, you can make it valid with @samp{-fthis-is-variable}. -@item -fvtable-thunks +@item -fvtable-thunks=@var{thunks-version} Use @samp{thunks} to implement the virtual function dispatch table (@samp{vtable}). The traditional (cfront-style) approach to implementing vtables was to store a pointer to the function and two offsets for adjusting the @samp{this} pointer at the call site. Newer implementations store a single pointer to a @samp{thunk} function which does any necessary adjustment and then calls the target function. +The original implementation of thunks (version 1) had a bug regarding +virtual base classes; this bug is fixed with version 2 of the thunks +implementation. With setting the version to 2, compatibility to the +version 1 thunks is provided, at the cost of extra machine code. Version +3 does not include this compatibility. + This option also enables a heuristic for controlling emission of vtables; if a class has any non-inline virtual functions, the vtable will be emitted in the translation unit containing the first one of those. Like all options that change the ABI, all C++ code, @emph{including -libgcc.a} must be built with the same setting of this option. +libgcc.a} must be built with the same setting of this option. Since +version 1 and version 2 are also incompatible (for classes with virtual +bases defining virtual functions), all code must also be compiled with +the same version. + +On some targets (e.g. Linux/GNU), version 2 thunks are the default. On these +targets, no option or -fvtable-thunks will produce version 2 thunks. On +all other targets, not giving the option will use the traditional +implementation, and -fvtable-thunks will produce version 2 thunks. @item -nostdinc++ Do not search for header files in the standard directories specific to C++, but do still search the other standard directories. (This option is used when building the C++ library.) @end table In addition, these optimization, warning, and code generation options have meanings only for C++ programs: @table @code @item -fno-default-inline Do not assume @samp{inline} for functions defined inside a class scope. @xref{Optimize Options,,Options That Control Optimization}. Note that these functions will have linkage like inline functions; they just won't be inlined by default. @item -Wctor-dtor-privacy (C++ only) Warn when a class seems unusable, because all the constructors or destructors in a class are private and the class has no friends or public static member functions. @item -Wnon-virtual-dtor (C++ only) Warn when a class declares a non-virtual destructor that should probably be virtual, because it looks like the class will be used polymorphically. @item -Wreorder (C++ only) @cindex reordering, warning @cindex warning for reordering of member initializers Warn when the order of member initializers given in the code does not match the order in which they must be executed. For instance: @smallexample struct A @{ int i; int j; A(): j (0), i (1) @{ @} @}; @end smallexample Here the compiler will warn that the member initializers for @samp{i} and @samp{j} will be rearranged to match the declaration order of the members. @end table The following @samp{-W@dots{}} options are not affected by @samp{-Wall}. @table @code @item -Weffc++ (C++ only) Warn about violations of various style guidelines from Scott Meyers' @cite{Effective C++} books. If you use this option, you should be aware that the standard library headers do not obey all of these guidelines; you can use @samp{grep -v} to filter out those warnings. @item -Wno-deprecated (C++ only) Do not warn about usage of deprecated features. @xref{Deprecated Features}. @item -Wno-non-template-friend (C++ only) Disable warnings when non-templatized friend functions are declared within a template. With the advent of explicit template specification support in g++, if the name of the friend is an unqualified-id (ie, @samp{friend foo(int)}), the C++ language specification demands that the friend declare or define an ordinary, nontemplate function. (Section 14.5.3). Before g++ implemented explicit specification, unqualified-ids could be interpreted as a particular specialization of a templatized function. Because this non-conforming behavior is no longer the default behavior for g++, @samp{-Wnon-template-friend} allows the compiler to check existing code for potential trouble spots, and is on by default. This new compiler behavior can also be turned off with the flag @samp{-fguiding-decls}, which activates the older, non-specification compiler code, or with @samp{-Wno-non-template-friend} which keeps the conformant compiler code but disables the helpful warning. @item -Wold-style-cast (C++ only) Warn if an old-style (C-style) cast is used within a C++ program. The new-style casts (@samp{static_cast}, @samp{reinterpret_cast}, and @samp{const_cast}) are less vulnerable to unintended effects. @item -Woverloaded-virtual (C++ only) @cindex overloaded virtual fn, warning @cindex warning for overloaded virtual fn Warn when a derived class function declaration may be an error in defining a virtual function. In a derived class, the definitions of virtual functions must match the type signature of a virtual function declared in the base class. With this option, the compiler warns when you define a function with the same name as a virtual function, but with a type signature that does not match any declarations from the base class. @item -Wno-pmf-conversions (C++ only) Disable the diagnostic for converting a bound pointer to member function to a plain pointer. @item -Wsign-promo (C++ only) Warn when overload resolution chooses a promotion from unsigned or enumeral type to a signed type over a conversion to an unsigned type of the same size. Previous versions of g++ would try to preserve unsignedness, but the standard mandates the current behavior. @item -Wsynth (C++ only) @cindex warning for synthesized methods @cindex synthesized methods, warning Warn when g++'s synthesis behavior does not match that of cfront. For instance: @smallexample struct A @{ operator int (); A& operator = (int); @}; main () @{ A a,b; a = b; @} @end smallexample In this example, g++ will synthesize a default @samp{A& operator = (const A&);}, while cfront will use the user-defined @samp{operator =}. @end table @node Warning Options @section Options to Request or Suppress Warnings @cindex options to control warnings @cindex warning messages @cindex messages, warning @cindex suppressing warnings Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there may have been an error. You can request many specific warnings with options beginning @samp{-W}, for example @samp{-Wimplicit} to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning @samp{-Wno-} to turn off warnings; for example, @samp{-Wno-implicit}. This manual lists only one of the two forms, whichever is not the default. These options control the amount and kinds of warnings produced by GCC: @table @code @cindex syntax checking @item -fsyntax-only Check the code for syntax errors, but don't do anything beyond that. @item -pedantic Issue all the warnings demanded by strict ANSI C and ISO C++; reject all programs that use forbidden extensions. Valid ANSI C and ISO C++ programs should compile properly with or without this option (though a rare few will require @samp{-ansi}). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected. @samp{-pedantic} does not cause warning messages for use of the alternate keywords whose names begin and end with @samp{__}. Pedantic warnings are also disabled in the expression that follows @code{__extension__}. However, only system header files should use these escape routes; application programs should avoid them. @xref{Alternate Keywords}. This option is not intended to be @i{useful}; it exists only to satisfy pedants who would otherwise claim that GCC fails to support the ANSI standard. Some users try to use @samp{-pedantic} to check programs for strict ANSI C conformance. They soon find that it does not do quite what they want: it finds some non-ANSI practices, but not all---only those for which ANSI C @emph{requires} a diagnostic. A feature to report any failure to conform to ANSI C might be useful in some instances, but would require considerable additional work and would be quite different from @samp{-pedantic}. We don't have plans to support such a feature in the near future. @item -pedantic-errors Like @samp{-pedantic}, except that errors are produced rather than warnings. @item -w Inhibit all warning messages. @item -Wno-import Inhibit warning messages about the use of @samp{#import}. @item -Wchar-subscripts Warn if an array subscript has type @code{char}. This is a common cause of error, as programmers often forget that this type is signed on some machines. @item -Wcomment Warn whenever a comment-start sequence @samp{/*} appears in a @samp{/*} comment, or whenever a Backslash-Newline appears in a @samp{//} comment. @item -Wformat Check calls to @code{printf} and @code{scanf}, etc., to make sure that the arguments supplied have types appropriate to the format string specified. @item -Wimplicit-int Warn when a declaration does not specify a type. @item -Wimplicit-function-declaration @itemx -Werror-implicit-function-declaration Give a warning (or error) whenever a function is used before being declared. @item -Wimplicit Same as @samp{-Wimplicit-int} and @samp{-Wimplicit-function-}@* @samp{declaration}. @item -Wmain Warn if the type of @samp{main} is suspicious. @samp{main} should be a function with external linkage, returning int, taking either zero arguments, two, or three arguments of appropriate types. @item -Wmultichar Warn if a multicharacter constant (@samp{'FOOF'}) is used. Usually they indicate a typo in the user's code, as they have implementation-defined values, and should not be used in portable code. @item -Wparentheses Warn if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about. Also warn about constructions where there may be confusion to which @code{if} statement an @code{else} branch belongs. Here is an example of such a case: @smallexample @{ if (a) if (b) foo (); else bar (); @} @end smallexample In C, every @code{else} branch belongs to the innermost possible @code{if} statement, which in this example is @code{if (b)}. This is often not what the programmer expected, as illustrated in the above example by indentation the programmer chose. When there is the potential for this confusion, GNU C will issue a warning when this flag is specified. To eliminate the warning, add explicit braces around the innermost @code{if} statement so there is no way the @code{else} could belong to the enclosing @code{if}. The resulting code would look like this: @smallexample @{ if (a) @{ if (b) foo (); else bar (); @} @} @end smallexample @item -Wreturn-type Warn whenever a function is defined with a return-type that defaults to @code{int}. Also warn about any @code{return} statement with no return-value in a function whose return-type is not @code{void}. @item -Wswitch Warn whenever a @code{switch} statement has an index of enumeral type and lacks a @code{case} for one or more of the named codes of that enumeration. (The presence of a @code{default} label prevents this warning.) @code{case} labels outside the enumeration range also provoke warnings when this option is used. @item -Wtrigraphs Warn if any trigraphs are encountered (assuming they are enabled). @item -Wunused Warn whenever a variable is unused aside from its declaration, whenever a function is declared static but never defined, whenever a label is declared but not used, and whenever a statement computes a result that is explicitly not used. In order to get a warning about an unused function parameter, you must specify both @samp{-W} and @samp{-Wunused}. To suppress this warning for an expression, simply cast it to void. For unused variables, parameters and labels, use the @samp{unused} attribute (@pxref{Variable Attributes}). @item -Wuninitialized An automatic variable is used without first being initialized. These warnings are possible only in optimizing compilation, because they require data flow information that is computed only when optimizing. If you don't specify @samp{-O}, you simply won't get these warnings. These warnings occur only for variables that are candidates for register allocation. Therefore, they do not occur for a variable that is declared @code{volatile}, or whose address is taken, or whose size is other than 1, 2, 4 or 8 bytes. Also, they do not occur for structures, unions or arrays, even when they are in registers. Note that there may be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data flow analysis before the warnings are printed. These warnings are made optional because GCC is not smart enough to see all the reasons why the code might be correct despite appearing to have an error. Here is one example of how this can happen: @smallexample @{ int x; switch (y) @{ case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; @} foo (x); @} @end smallexample @noindent If the value of @code{y} is always 1, 2 or 3, then @code{x} is always initialized, but GCC doesn't know this. Here is another common case: @smallexample @{ int save_y; if (change_y) save_y = y, y = new_y; @dots{} if (change_y) y = save_y; @} @end smallexample @noindent This has no bug because @code{save_y} is used only if it is set. Some spurious warnings can be avoided if you declare all the functions you use that never return as @code{noreturn}. @xref{Function Attributes}. @item -Wunknown-pragmas @cindex warning for unknown pragmas @cindex unknown pragmas, warning @cindex pragmas, warning of unknown Warn when a #pragma directive is encountered which is not understood by GCC. If this command line option is used, warnings will even be issued for unknown pragmas in system header files. This is not the case if the warnings were only enabled by the @samp{-Wall} command line option. @item -Wall All of the above @samp{-W} options combined. This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. @end table The following @samp{-W@dots{}} options are not implied by @samp{-Wall}. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. @table @code @item -W Print extra warning messages for these events: @itemize @bullet @cindex @code{longjmp} warnings @item A nonvolatile automatic variable might be changed by a call to @code{longjmp}. These warnings as well are possible only in optimizing compilation. The compiler sees only the calls to @code{setjmp}. It cannot know where @code{longjmp} will be called; in fact, a signal handler could call it at any point in the code. As a result, you may get a warning even when there is in fact no problem because @code{longjmp} cannot in fact be called at the place which would cause a problem. @item A function can return either with or without a value. (Falling off the end of the function body is considered returning without a value.) For example, this function would evoke such a warning: @smallexample @group foo (a) @{ if (a > 0) return a; @} @end group @end smallexample @item An expression-statement or the left-hand side of a comma expression contains no side effects. To suppress the warning, cast the unused expression to void. For example, an expression such as @samp{x[i,j]} will cause a warning, but @samp{x[(void)i,j]} will not. @item An unsigned value is compared against zero with @samp{<} or @samp{<=}. @item A comparison like @samp{x<=y<=z} appears; this is equivalent to @samp{(x<=y ? 1 : 0) <= z}, which is a different interpretation from that of ordinary mathematical notation. @item Storage-class specifiers like @code{static} are not the first things in a declaration. According to the C Standard, this usage is obsolescent. @item If @samp{-Wall} or @samp{-Wunused} is also specified, warn about unused arguments. @item A comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. (But don't warn if @samp{-Wno-sign-compare} is also specified.) @item An aggregate has a partly bracketed initializer. For example, the following code would evoke such a warning, because braces are missing around the initializer for @code{x.h}: @smallexample struct s @{ int f, g; @}; struct t @{ struct s h; int i; @}; struct t x = @{ 1, 2, 3 @}; @end smallexample @item An aggregate has an initializer which does not initialize all members. For example, the following code would cause such a warning, because @code{x.h} would be implicitly initialized to zero: @smallexample struct s @{ int f, g, h; @}; struct s x = @{ 3, 4 @}; @end smallexample @end itemize @item -Wtraditional Warn about certain constructs that behave differently in traditional and ANSI C. @itemize @bullet @item Macro arguments occurring within string constants in the macro body. These would substitute the argument in traditional C, but are part of the constant in ANSI C. @item A function declared external in one block and then used after the end of the block. @item A @code{switch} statement has an operand of type @code{long}. @item A non-@code{static} function declaration follows a @code{static} one. This construct is not accepted by some traditional C compilers. @end itemize @item -Wundef Warn if an undefined identifier is evaluated in an @samp{#if} directive. @item -Wshadow Warn whenever a local variable shadows another local variable. @item -Wid-clash-@var{len} Warn whenever two distinct identifiers match in the first @var{len} characters. This may help you prepare a program that will compile with certain obsolete, brain-damaged compilers. @item -Wlarger-than-@var{len} Warn whenever an object of larger than @var{len} bytes is defined. @item -Wpointer-arith Warn about anything that depends on the ``size of'' a function type or of @code{void}. GNU C assigns these types a size of 1, for convenience in calculations with @code{void *} pointers and pointers to functions. @item -Wbad-function-cast Warn whenever a function call is cast to a non-matching type. For example, warn if @code{int malloc()} is cast to @code{anything *}. @item -Wcast-qual Warn whenever a pointer is cast so as to remove a type qualifier from the target type. For example, warn if a @code{const char *} is cast to an ordinary @code{char *}. @item -Wcast-align Warn whenever a pointer is cast such that the required alignment of the target is increased. For example, warn if a @code{char *} is cast to an @code{int *} on machines where integers can only be accessed at two- or four-byte boundaries. @item -Wwrite-strings Give string constants the type @code{const char[@var{length}]} so that copying the address of one into a non-@code{const} @code{char *} pointer will get a warning. These warnings will help you find at compile time code that can try to write into a string constant, but only if you have been very careful about using @code{const} in declarations and prototypes. Otherwise, it will just be a nuisance; this is why we did not make @samp{-Wall} request these warnings. @item -Wconversion Warn if a prototype causes a type conversion that is different from what would happen to the same argument in the absence of a prototype. This includes conversions of fixed point to floating and vice versa, and conversions changing the width or signedness of a fixed point argument except when the same as the default promotion. Also, warn if a negative integer constant expression is implicitly converted to an unsigned type. For example, warn about the assignment @code{x = -1} if @code{x} is unsigned. But do not warn about explicit casts like @code{(unsigned) -1}. @item -Wsign-compare @cindex warning for comparison of signed and unsigned values @cindex comparison of signed and unsigned values, warning @cindex signed and unsigned values, comparison warning Warn when a comparison between signed and unsigned values could produce an incorrect result when the signed value is converted to unsigned. This warning is also enabled by @samp{-W}; to get the other warnings of @samp{-W} without this warning, use @samp{-W -Wno-sign-compare}. @item -Waggregate-return Warn if any functions that return structures or unions are defined or called. (In languages where you can return an array, this also elicits a warning.) @item -Wstrict-prototypes Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration which specifies the argument types.) @item -Wmissing-prototypes Warn if a global function is defined without a previous prototype declaration. This warning is issued even if the definition itself provides a prototype. The aim is to detect global functions that fail to be declared in header files. @item -Wmissing-declarations Warn if a global function is defined without a previous declaration. Do so even if the definition itself provides a prototype. Use this option to detect global functions that are not declared in header files. @item -Wmissing-noreturn Warn about functions which might be candidates for attribute @code{noreturn}. Note these are only possible candidates, not absolute ones. Care should be taken to manually verify functions actually do not ever return before adding the @code{noreturn} attribute, otherwise subtle code generation bugs could be introduced. @item -Wredundant-decls Warn if anything is declared more than once in the same scope, even in cases where multiple declaration is valid and changes nothing. @item -Wnested-externs Warn if an @code{extern} declaration is encountered within an function. @item -Winline Warn if a function can not be inlined, and either it was declared as inline, or else the @samp{-finline-functions} option was given. @item -Wlong-long Warn if @samp{long long} type is used. This is default. To inhibit the warning messages, use @samp{-Wno-long-long}. Flags @samp{-Wlong-long} and @samp{-Wno-long-long} are taken into account only when @samp{-pedantic} flag is used. @item -Werror Make all warnings into errors. @end table @node Debugging Options @section Options for Debugging Your Program or GCC @cindex options, debugging @cindex debugging information options GCC has various special options that are used for debugging either your program or GCC: @table @code @item -g Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF). GDB can work with this debugging information. On most systems that use stabs format, @samp{-g} enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use @samp{-gstabs+}, @samp{-gstabs}, @samp{-gxcoff+}, @samp{-gxcoff}, @samp{-gdwarf-1+}, or @samp{-gdwarf-1} (see below). Unlike most other C compilers, GCC allows you to use @samp{-g} with @samp{-O}. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops. Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs. The following options are useful when GCC is generated with the capability for more than one debugging format. @item -ggdb Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible. @item -gstabs Produce debugging information in stabs format (if that is supported), without GDB extensions. This is the format used by DBX on most BSD systems. On MIPS, Alpha and System V Release 4 systems this option produces stabs debugging output which is not understood by DBX or SDB. On System V Release 4 systems this option requires the GNU assembler. @item -gstabs+ Produce debugging information in stabs format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program. @item -gcoff Produce debugging information in COFF format (if that is supported). This is the format used by SDB on most System V systems prior to System V Release 4. @item -gxcoff Produce debugging information in XCOFF format (if that is supported). This is the format used by the DBX debugger on IBM RS/6000 systems. @item -gxcoff+ Produce debugging information in XCOFF format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program, and may cause assemblers other than the GNU assembler (GAS) to fail with an error. @item -gdwarf Produce debugging information in DWARF version 1 format (if that is supported). This is the format used by SDB on most System V Release 4 systems. @item -gdwarf+ Produce debugging information in DWARF version 1 format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program. @item -gdwarf-2 Produce debugging information in DWARF version 2 format (if that is supported). This is the format used by DBX on IRIX 6. @item -g@var{level} @itemx -ggdb@var{level} @itemx -gstabs@var{level} @itemx -gcoff@var{level} @itemx -gxcoff@var{level} @itemx -gdwarf@var{level} @itemx -gdwarf-2@var{level} Request debugging information and also use @var{level} to specify how much information. The default level is 2. Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, but no information about local variables and no line numbers. Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use @samp{-g3}. @cindex @code{prof} @item -p Generate extra code to write profile information suitable for the analysis program @code{prof}. You must use this option when compiling the source files you want data about, and you must also use it when linking. @cindex @code{gprof} @item -pg Generate extra code to write profile information suitable for the analysis program @code{gprof}. You must use this option when compiling the source files you want data about, and you must also use it when linking. @cindex @code{tcov} @item -a Generate extra code to write profile information for basic blocks, which will record the number of times each basic block is executed, the basic block start address, and the function name containing the basic block. If @samp{-g} is used, the line number and filename of the start of the basic block will also be recorded. If not overridden by the machine description, the default action is to append to the text file @file{bb.out}. This data could be analyzed by a program like @code{tcov}. Note, however, that the format of the data is not what @code{tcov} expects. Eventually GNU @code{gprof} should be extended to process this data. @item -Q Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes. @item -ax Generate extra code to profile basic blocks. Your executable will produce output that is a superset of that produced when @samp{-a} is used. Additional output is the source and target address of the basic blocks where a jump takes place, the number of times a jump is executed, and (optionally) the complete sequence of basic blocks being executed. The output is appended to file @file{bb.out}. You can examine different profiling aspects without recompilation. Your executable will read a list of function names from file @file{bb.in}. Profiling starts when a function on the list is entered and stops when that invocation is exited. To exclude a function from profiling, prefix its name with `-'. If a function name is not unique, you can disambiguate it by writing it in the form @samp{/path/filename.d:functionname}. Your executable will write the available paths and filenames in file @file{bb.out}. Several function names have a special meaning: @table @code @item __bb_jumps__ Write source, target and frequency of jumps to file @file{bb.out}. @item __bb_hidecall__ Exclude function calls from frequency count. @item __bb_showret__ Include function returns in frequency count. @item __bb_trace__ Write the sequence of basic blocks executed to file @file{bbtrace.gz}. The file will be compressed using the program @samp{gzip}, which must exist in your @code{PATH}. On systems without the @samp{popen} function, the file will be named @file{bbtrace} and will not be compressed. @strong{Profiling for even a few seconds on these systems will produce a very large file.} Note: @code{__bb_hidecall__} and @code{__bb_showret__} will not affect the sequence written to @file{bbtrace.gz}. @end table Here's a short example using different profiling parameters in file @file{bb.in}. Assume function @code{foo} consists of basic blocks 1 and 2 and is called twice from block 3 of function @code{main}. After the calls, block 3 transfers control to block 4 of @code{main}. With @code{__bb_trace__} and @code{main} contained in file @file{bb.in}, the following sequence of blocks is written to file @file{bbtrace.gz}: 0 3 1 2 1 2 4. The return from block 2 to block 3 is not shown, because the return is to a point inside the block and not to the top. The block address 0 always indicates, that control is transferred to the trace from somewhere outside the observed functions. With @samp{-foo} added to @file{bb.in}, the blocks of function @code{foo} are removed from the trace, so only 0 3 4 remains. With @code{__bb_jumps__} and @code{main} contained in file @file{bb.in}, jump frequencies will be written to file @file{bb.out}. The frequencies are obtained by constructing a trace of blocks and incrementing a counter for every neighbouring pair of blocks in the trace. The trace 0 3 1 2 1 2 4 displays the following frequencies: @example Jump from block 0x0 to block 0x3 executed 1 time(s) Jump from block 0x3 to block 0x1 executed 1 time(s) Jump from block 0x1 to block 0x2 executed 2 time(s) Jump from block 0x2 to block 0x1 executed 1 time(s) Jump from block 0x2 to block 0x4 executed 1 time(s) @end example With @code{__bb_hidecall__}, control transfer due to call instructions is removed from the trace, that is the trace is cut into three parts: 0 3 4, 0 1 2 and 0 1 2. With @code{__bb_showret__}, control transfer due to return instructions is added to the trace. The trace becomes: 0 3 1 2 3 1 2 3 4. Note, that this trace is not the same, as the sequence written to @file{bbtrace.gz}. It is solely used for counting jump frequencies. @item -fprofile-arcs Instrument @dfn{arcs} during compilation. For each function of your program, GCC creates a program flow graph, then finds a spanning tree for the graph. Only arcs that are not on the spanning tree have to be instrumented: the compiler adds code to count the number of times that these arcs are executed. When an arc is the only exit or only entrance to a block, the instrumentation code can be added to the block; otherwise, a new basic block must be created to hold the instrumentation code. Since not every arc in the program must be instrumented, programs compiled with this option run faster than programs compiled with @samp{-a}, which adds instrumentation code to every basic block in the program. The tradeoff: since @code{gcov} does not have execution counts for all branches, it must start with the execution counts for the instrumented branches, and then iterate over the program flow graph until the entire graph has been solved. Hence, @code{gcov} runs a little more slowly than a program which uses information from @samp{-a}. @samp{-fprofile-arcs} also makes it possible to estimate branch probabilities, and to calculate basic block execution counts. In general, basic block execution counts do not give enough information to estimate all branch probabilities. When the compiled program exits, it saves the arc execution counts to a file called @file{@var{sourcename}.da}. Use the compiler option @samp{-fbranch-probabilities} (@pxref{Optimize Options,,Options that Control Optimization}) when recompiling, to optimize using estimated branch probabilities. @need 2000 @item -ftest-coverage Create data files for the @code{gcov} code-coverage utility (@pxref{Gcov,, @code{gcov}: a GCC Test Coverage Program}). The data file names begin with the name of your source file: @table @code @item @var{sourcename}.bb A mapping from basic blocks to line numbers, which @code{gcov} uses to associate basic block execution counts with line numbers. @item @var{sourcename}.bbg A list of all arcs in the program flow graph. This allows @code{gcov} to reconstruct the program flow graph, so that it can compute all basic block and arc execution counts from the information in the @code{@var{sourcename}.da} file (this last file is the output from @samp{-fprofile-arcs}). @end table @item -Q Makes the compiler print out each function name as it is compiled, and print some statistics about each pass when it finishes. @item -d@var{letters} Says to make debugging dumps during compilation at times specified by @var{letters}. This is used for debugging the compiler. The file names for most of the dumps are made by appending a word to the source file name (e.g. @file{foo.c.rtl} or @file{foo.c.jump}). Here are the possible letters for use in @var{letters}, and their meanings: @table @samp @item b Dump after computing branch probabilities, to @file{@var{file}.bp}. @item c Dump after instruction combination, to the file @file{@var{file}.combine}. @item d Dump after delayed branch scheduling, to @file{@var{file}.dbr}. @item D Dump all macro definitions, at the end of preprocessing, in addition to normal output. @item r Dump after RTL generation, to @file{@var{file}.rtl}. @item j Dump after first jump optimization, to @file{@var{file}.jump}. @item F Dump after purging ADDRESSOF, to @file{@var{file}.addressof}. @item f Dump after flow analysis, to @file{@var{file}.flow}. @item g Dump after global register allocation, to @file{@var{file}.greg}. @item G Dump after GCSE, to @file{@var{file}.gcse}. @item j Dump after first jump optimization, to @file{@var{file}.jump}. @item J Dump after last jump optimization, to @file{@var{file}.jump2}. @item k Dump after conversion from registers to stack, to @file{@var{file}.stack}. @item l Dump after local register allocation, to @file{@var{file}.lreg}. @item L Dump after loop optimization, to @file{@var{file}.loop}. @item M Dump after performing the machine dependent reorganisation pass, to @file{@var{file}.mach}. @item N Dump after the register move pass, to @file{@var{file}.regmove}. @item r Dump after RTL generation, to @file{@var{file}.rtl}. @item R Dump after the second instruction scheduling pass, to @file{@var{file}.sched2}. @item s Dump after CSE (including the jump optimization that sometimes follows CSE), to @file{@var{file}.cse}. @item S Dump after the first instruction scheduling pass, to @file{@var{file}.sched}. @item t Dump after the second CSE pass (including the jump optimization that sometimes follows CSE), to @file{@var{file}.cse2}. @item a Produce all the dumps listed above. @item m Print statistics on memory usage, at the end of the run, to standard error. @item p Annotate the assembler output with a comment indicating which pattern and alternative was used. The length of each instruction is also printed. @item x Just generate RTL for a function instead of compiling it. Usually used with @samp{r}. @item y Dump debugging information during parsing, to standard error. @item A Annotate the assembler output with miscellaneous debugging information. @end table @item -fdump-unnumbered When doing debugging dumps (see -d option above), suppress instruction numbers and line number note output. This makes it more feasible to use diff on debugging dumps for compiler invokations with different options, in particular with and without -g. @item -fpretend-float When running a cross-compiler, pretend that the target machine uses the same floating point format as the host machine. This causes incorrect output of the actual floating constants, but the actual instruction sequence will probably be the same as GCC would make when running on the target machine. @item -save-temps Store the usual ``temporary'' intermediate files permanently; place them in the current directory and name them based on the source file. Thus, compiling @file{foo.c} with @samp{-c -save-temps} would produce files @file{foo.i} and @file{foo.s}, as well as @file{foo.o}. @item -print-file-name=@var{library} Print the full absolute name of the library file @var{library} that would be used when linking---and don't do anything else. With this option, GCC does not compile or link anything; it just prints the file name. @item -print-prog-name=@var{program} Like @samp{-print-file-name}, but searches for a program such as @samp{cpp}. @item -print-libgcc-file-name Same as @samp{-print-file-name=libgcc.a}. This is useful when you use @samp{-nostdlib} or @samp{-nodefaultlibs} but you do want to link with @file{libgcc.a}. You can do @example gcc -nostdlib @var{files}@dots{} `gcc -print-libgcc-file-name` @end example @item -print-search-dirs Print the name of the configured installation directory and a list of program and library directories gcc will search---and don't do anything else. This is useful when gcc prints the error message @samp{installation problem, cannot exec cpp: No such file or directory}. To resolve this you either need to put @file{cpp} and the other compiler components where gcc expects to find them, or you can set the environment variable @code{GCC_EXEC_PREFIX} to the directory where you installed them. Don't forget the trailing '/'. @xref{Environment Variables}. @end table @node Optimize Options @section Options That Control Optimization @cindex optimize options @cindex options, optimization These options control various sorts of optimizations: @table @code @item -O @itemx -O1 Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function. Without @samp{-O}, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code. Without @samp{-O}, the compiler only allocates variables declared @code{register} in registers. The resulting compiled code is a little worse than produced by PCC without @samp{-O}. With @samp{-O}, the compiler tries to reduce code size and execution time. When you specify @samp{-O}, the compiler turns on @samp{-fthread-jumps} and @samp{-fdefer-pop} on all machines. The compiler turns on @samp{-fdelayed-branch} on machines that have delay slots, and @samp{-fomit-frame-pointer} on machines that can support debugging even without a frame pointer. On some machines the compiler also turns on other flags.@refill @item -O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify @samp{-O2}. As compared to @samp{-O}, this option increases both compilation time and the performance of the generated code. @samp{-O2} turns on all optional optimizations except for loop unrolling, function inlining, and strict aliasing optimizations. It also turns on the @samp{-fforce-mem} option on all machines and frame pointer elimination on machines where doing so does not interfere with debugging. @item -O3 Optimize yet more. @samp{-O3} turns on all optimizations specified by @samp{-O2} and also turns on the @samp{inline-functions} option. @item -O0 Do not optimize. @item -Os Optimize for size. @samp{-Os} enables all @samp{-O2} optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size. If you use multiple @samp{-O} options, with or without level numbers, the last such option is the one that is effective. @end table Options of the form @samp{-f@var{flag}} specify machine-independent flags. Most flags have both positive and negative forms; the negative form of @samp{-ffoo} would be @samp{-fno-foo}. In the table below, only one of the forms is listed---the one which is not the default. You can figure out the other form by either removing @samp{no-} or adding it. @table @code @item -ffloat-store Do not store floating point variables in registers, and inhibit other options that might change whether a floating point value is taken from a register or memory. @cindex floating point precision This option prevents undesirable excess precision on machines such as the 68000 where the floating registers (of the 68881) keep more precision than a @code{double} is supposed to have. Similarly for the x86 architecture. For most programs, the excess precision does only good, but a few programs rely on the precise definition of IEEE floating point. Use @samp{-ffloat-store} for such programs, after modifying them to store all pertinent intermediate computations into variables. @item -fno-default-inline Do not make member functions inline by default merely because they are defined inside the class scope (C++ only). Otherwise, when you specify @w{@samp{-O}}, member functions defined inside class scope are compiled inline by default; i.e., you don't need to add @samp{inline} in front of the member function name. @item -fno-defer-pop Always pop the arguments to each function call as soon as that function returns. For machines which must pop arguments after a function call, the compiler normally lets arguments accumulate on the stack for several function calls and pops them all at once. @item -fforce-mem Force memory operands to be copied into registers before doing arithmetic on them. This produces better code by making all memory references potential common subexpressions. When they are not common subexpressions, instruction combination should eliminate the separate register-load. The @samp{-O2} option turns on this option. @item -fforce-addr Force memory address constants to be copied into registers before doing arithmetic on them. This may produce better code just as @samp{-fforce-mem} may. @item -fomit-frame-pointer Don't keep the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. @strong{It also makes debugging impossible on some machines.} @ifset INTERNALS On some machines, such as the Vax, this flag has no effect, because the standard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn't exist. The machine-description macro @code{FRAME_POINTER_REQUIRED} controls whether a target machine supports this flag. @xref{Registers}.@refill @end ifset @ifclear INTERNALS On some machines, such as the Vax, this flag has no effect, because the standard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn't exist. The machine-description macro @code{FRAME_POINTER_REQUIRED} controls whether a target machine supports this flag. @xref{Registers,,Register Usage, gcc.info, Using and Porting GCC}.@refill @end ifclear @item -fno-inline Don't pay attention to the @code{inline} keyword. Normally this option is used to keep the compiler from expanding any functions inline. Note that if you are not optimizing, no functions can be expanded inline. @item -finline-functions Integrate all simple functions into their callers. The compiler heuristically decides which functions are simple enough to be worth integrating in this way. If all calls to a given function are integrated, and the function is declared @code{static}, then the function is normally not output as assembler code in its own right. @item -finline-limit-@var{n} By default, gcc limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (ie marked with the inline keyword or defined within the class definition in c++). @var{n} is the size of functions that can be inlined in number of pseudo instructions (not counting parameter handling). The default value of n is 10000. Increasing this value can result in more inlined code at the cost of compilation time and memory consumption. Decreasing usually makes the compilation faster and less code will be inlined (which presumably means slower programs). This option is particularly useful for programs that use inlining heavily such as those based on recursive templates with c++. @emph{Note:} pseudo instruction represents, in this particular context, an abstract measurement of function's size. In no way, it represents a count of assembly instructions and as such its exact meaning might change from one release to an another. @item -fkeep-inline-functions Even if all calls to a given function are integrated, and the function is declared @code{static}, nevertheless output a separate run-time callable version of the function. This switch does not affect @code{extern inline} functions. @item -fkeep-static-consts Emit variables declared @code{static const} when optimization isn't turned on, even if the variables aren't referenced. GCC enables this option by default. If you want to force the compiler to check if the variable was referenced, regardless of whether or not optimization is turned on, use the @samp{-fno-keep-static-consts} option. @item -fno-function-cse Do not put function addresses in registers; make each instruction that calls a constant function contain the function's address explicitly. This option results in less efficient code, but some strange hacks that alter the assembler output may be confused by the optimizations performed when this option is not used. @item -ffast-math This option allows GCC to violate some ANSI or IEEE rules and/or specifications in the interest of optimizing code for speed. For example, it allows the compiler to assume arguments to the @code{sqrt} function are non-negative numbers and that no floating-point values are NaNs. This option should never be turned on by any @samp{-O} option since it can result in incorrect output for programs which depend on an exact implementation of IEEE or ANSI rules/specifications for math functions. @end table @c following causes underfulls.. they don't look great, but we deal. @c --mew 26jan93 The following options control specific optimizations. The @samp{-O2} option turns on all of these optimizations except @samp{-funroll-loops} @samp{-funroll-all-loops}, and @samp{-fstrict-aliasing}. On most machines, the @samp{-O} option turns on the @samp{-fthread-jumps} and @samp{-fdelayed-branch} options, but specific machines may handle it differently. You can use the following flags in the rare cases when ``fine-tuning'' of optimizations to be performed is desired. @table @code @item -fstrength-reduce Perform the optimizations of loop strength reduction and elimination of iteration variables. @item -fthread-jumps Perform optimizations where we check to see if a jump branches to a location where another comparison subsumed by the first is found. If so, the first branch is redirected to either the destination of the second branch or a point immediately following it, depending on whether the condition is known to be true or false. @item -fcse-follow-jumps In common subexpression elimination, scan through jump instructions when the target of the jump is not reached by any other path. For example, when CSE encounters an @code{if} statement with an @code{else} clause, CSE will follow the jump when the condition tested is false. @item -fcse-skip-blocks This is similar to @samp{-fcse-follow-jumps}, but causes CSE to follow jumps which conditionally skip over blocks. When CSE encounters a simple @code{if} statement with no else clause, @samp{-fcse-skip-blocks} causes CSE to follow the jump around the body of the @code{if}. @item -frerun-cse-after-loop Re-run common subexpression elimination after loop optimizations has been performed. @item -frerun-loop-opt Run the loop optimizer twice. @item -fgcse Perform a global common subexpression elimination pass. This pass also performs global constant and copy propagation. @item -fexpensive-optimizations Perform a number of minor optimizations that are relatively expensive. @item -foptimize-register-moves @itemx -fregmove Attempt to reassign register numbers in move instructions and as operands of other simple instructions in order to maximize the amount of register tying. This is especially helpful on machines with two-operand instructions. GCC enables this optimization by default with @samp{-O2} or higher. Note @code{-fregmove} and @code{-foptimize-register-moves} are the same optimization. @item -fdelayed-branch If supported for the target machine, attempt to reorder instructions to exploit instruction slots available after delayed branch instructions. @item -fschedule-insns If supported for the target machine, attempt to reorder instructions to eliminate execution stalls due to required data being unavailable. This helps machines that have slow floating point or memory load instructions by allowing other instructions to be issued until the result of the load or floating point instruction is required. @item -fschedule-insns2 Similar to @samp{-fschedule-insns}, but requests an additional pass of instruction scheduling after register allocation has been done. This is especially useful on machines with a relatively small number of registers and where memory load instructions take more than one cycle. @item -ffunction-sections @itemx -fdata-sections Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. Use these options on systems where the linker can perform optimizations to improve locality of reference in the instruction space. HPPA processors running HP-UX and Sparc processors running Solaris 2 have linkers with such optimizations. Other systems using the ELF object format as well as AIX may have these optimizations in the future. Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker will create larger object and executable files and will also be slower. You will not be able to use @code{gprof} on all systems if you specify this option and you may have problems with debugging if you specify both this option and @samp{-g}. @item -fcaller-saves Enable values to be allocated in registers that will be clobbered by function calls, by emitting extra instructions to save and restore the registers around such calls. Such allocation is done only when it seems to result in better code than would otherwise be produced. This option is always enabled by default on certain machines, usually those which have no call-preserved registers to use instead. For all machines, optimization level 2 and higher enables this flag by default. @item -funroll-loops Perform the optimization of loop unrolling. This is only done for loops whose number of iterations can be determined at compile time or run time. @samp{-funroll-loops} implies both @samp{-fstrength-reduce} and @samp{-frerun-cse-after-loop}. @item -funroll-all-loops Perform the optimization of loop unrolling. This is done for all loops and usually makes programs run more slowly. @samp{-funroll-all-loops} implies @samp{-fstrength-reduce} as well as @samp{-frerun-cse-after-loop}. @item -fmove-all-movables Forces all invariant computations in loops to be moved outside the loop. @item -freduce-all-givs Forces all general-induction variables in loops to be strength-reduced. @emph{Note:} When compiling programs written in Fortran, @samp{-fmove-all-movables} and @samp{-freduce-all-givs} are enabled by default when you use the optimizer. These options may generate better or worse code; results are highly dependent on the structure of loops within the source code. These two options are intended to be removed someday, once they have helped determine the efficacy of various approaches to improving loop optimizations. Please let us (@code{gcc@@gcc.gnu.org} and @code{fortran@@gnu.org}) know how use of these options affects the performance of your production code. We're very interested in code that runs @emph{slower} when these options are @emph{enabled}. @item -fno-peephole Disable any machine-specific peephole optimizations. @item -fbranch-probabilities After running a program compiled with @samp{-fprofile-arcs} (@pxref{Debugging Options,, Options for Debugging Your Program or @code{gcc}}), you can compile it a second time using @samp{-fbranch-probabilities}, to improve optimizations based on guessing the path a branch might take. @ifset INTERNALS With @samp{-fbranch-probabilities}, GCC puts a @samp{REG_EXEC_COUNT} note on the first instruction of each basic block, and a @samp{REG_BR_PROB} note on each @samp{JUMP_INSN} and @samp{CALL_INSN}. These can be used to improve optimization. Currently, they are only used in one place: in @file{reorg.c}, instead of guessing which path a branch is mostly to take, the @samp{REG_BR_PROB} values are used to exactly determine which path is taken more often. @end ifset @item -fstrict-aliasing Allows the compiler to assume the strictest aliasing rules applicable to the language being compiled. For C (and C++), this activates optimizations based on the type of expressions. In particular, an object of one type is assumed never to reside at the same address as an object of a different type, unless the types are almost the same. For example, an @code{unsigned int} can alias an @code{int}, but not a @code{void*} or a @code{double}. A character type may alias any other type. Pay special attention to code like this: @example union a_union @{ int i; double d; @}; int f() @{ a_union t; t.d = 3.0; return t.i; @} @end example The practice of reading from a different union member than the one most recently written to (called ``type-punning'') is common. Even with @samp{-fstrict-aliasing}, type-punning is allowed, provided the memory is accessed through the union type. So, the code above will work as expected. However, this code might not: @example int f() @{ a_union t; int* ip; t.d = 3.0; ip = &t.i; return *ip; @} @end example @ifset INTERNALS Every language that wishes to perform language-specific alias analysis should define a function that computes, given an @code{tree} node, an alias set for the node. Nodes in different alias sets are not allowed to alias. For an example, see the C front-end function @code{c_get_alias_set}. @end ifset @end table @node Preprocessor Options @section Options Controlling the Preprocessor @cindex preprocessor options @cindex options, preprocessor These options control the C preprocessor, which is run on each C source file before actual compilation. If you use the @samp{-E} option, nothing is done except preprocessing. Some of these options make sense only together with @samp{-E} because they cause the preprocessor output to be unsuitable for actual compilation. @table @code @item -include @var{file} Process @var{file} as input before processing the regular input file. In effect, the contents of @var{file} are compiled first. Any @samp{-D} and @samp{-U} options on the command line are always processed before @samp{-include @var{file}}, regardless of the order in which they are written. All the @samp{-include} and @samp{-imacros} options are processed in the order in which they are written. @item -imacros @var{file} Process @var{file} as input, discarding the resulting output, before processing the regular input file. Because the output generated from @var{file} is discarded, the only effect of @samp{-imacros @var{file}} is to make the macros defined in @var{file} available for use in the main input. Any @samp{-D} and @samp{-U} options on the command line are always processed before @samp{-imacros @var{file}}, regardless of the order in which they are written. All the @samp{-include} and @samp{-imacros} options are processed in the order in which they are written. @item -idirafter @var{dir} @cindex second include path Add the directory @var{dir} to the second include path. The directories on the second include path are searched when a header file is not found in any of the directories in the main include path (the one that @samp{-I} adds to). @item -iprefix @var{prefix} Specify @var{prefix} as the prefix for subsequent @samp{-iwithprefix} options. @item -iwithprefix @var{dir} Add a directory to the second include path. The directory's name is made by concatenating @var{prefix} and @var{dir}, where @var{prefix} was specified previously with @samp{-iprefix}. If you have not specified a prefix yet, the directory containing the installed passes of the compiler is used as the default. @item -iwithprefixbefore @var{dir} Add a directory to the main include path. The directory's name is made by concatenating @var{prefix} and @var{dir}, as in the case of @samp{-iwithprefix}. @item -isystem @var{dir} Add a directory to the beginning of the second include path, marking it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. @item -nostdinc Do not search the standard system directories for header files. Only the directories you have specified with @samp{-I} options (and the current directory, if appropriate) are searched. @xref{Directory Options}, for information on @samp{-I}. By using both @samp{-nostdinc} and @samp{-I-}, you can limit the include-file search path to only those directories you specify explicitly. @item -undef Do not predefine any nonstandard macros. (Including architecture flags). @item -E Run only the C preprocessor. Preprocess all the C source files specified and output the results to standard output or to the specified output file. @item -C Tell the preprocessor not to discard comments. Used with the @samp{-E} option. @item -P Tell the preprocessor not to generate @samp{#line} directives. Used with the @samp{-E} option. @cindex make @cindex dependencies, make @item -M Tell the preprocessor to output a rule suitable for @code{make} describing the dependencies of each object file. For each source file, the preprocessor outputs one @code{make}-rule whose target is the object file name for that source file and whose dependencies are all the @code{#include} header files it uses. This rule may be a single line or may be continued with @samp{\}-newline if it is long. The list of rules is printed on standard output instead of the preprocessed C program. @samp{-M} implies @samp{-E}. Another way to specify output of a @code{make} rule is by setting the environment variable @code{DEPENDENCIES_OUTPUT} (@pxref{Environment Variables}). @item -MM Like @samp{-M} but the output mentions only the user header files included with @samp{#include "@var{file}"}. System header files included with @samp{#include <@var{file}>} are omitted. @item -MD Like @samp{-M} but the dependency information is written to a file made by replacing ".c" with ".d" at the end of the input file names. This is in addition to compiling the file as specified---@samp{-MD} does not inhibit ordinary compilation the way @samp{-M} does. In Mach, you can use the utility @code{md} to merge multiple dependency files into a single dependency file suitable for using with the @samp{make} command. @item -MMD Like @samp{-MD} except mention only user header files, not system header files. @item -MG Treat missing header files as generated files and assume they live in the same directory as the source file. If you specify @samp{-MG}, you must also specify either @samp{-M} or @samp{-MM}. @samp{-MG} is not supported with @samp{-MD} or @samp{-MMD}. @item -H Print the name of each header file used, in addition to other normal activities. @item -A@var{question}(@var{answer}) Assert the answer @var{answer} for @var{question}, in case it is tested with a preprocessing conditional such as @samp{#if #@var{question}(@var{answer})}. @samp{-A-} disables the standard assertions that normally describe the target machine. @item -D@var{macro} Define macro @var{macro} with the string @samp{1} as its definition. @item -D@var{macro}=@var{defn} Define macro @var{macro} as @var{defn}. All instances of @samp{-D} on the command line are processed before any @samp{-U} options. @item -U@var{macro} Undefine macro @var{macro}. @samp{-U} options are evaluated after all @samp{-D} options, but before any @samp{-include} and @samp{-imacros} options. @item -dM Tell the preprocessor to output only a list of the macro definitions that are in effect at the end of preprocessing. Used with the @samp{-E} option. @item -dD Tell the preprocessing to pass all macro definitions into the output, in their proper sequence in the rest of the output. @item -dN Like @samp{-dD} except that the macro arguments and contents are omitted. Only @samp{#define @var{name}} is included in the output. @item -trigraphs Support ANSI C trigraphs. The @samp{-ansi} option also has this effect. @item -Wp,@var{option} Pass @var{option} as an option to the preprocessor. If @var{option} contains commas, it is split into multiple options at the commas. @end table @node Assembler Options @section Passing Options to the Assembler @c prevent bad page break with this line You can pass options to the assembler. @table @code @item -Wa,@var{option} Pass @var{option} as an option to the assembler. If @var{option} contains commas, it is split into multiple options at the commas. @end table @node Link Options @section Options for Linking @cindex link options @cindex options, linking These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler is not doing a link step. @table @code @cindex file names @item @var{object-file-name} A file name that does not end in a special recognized suffix is considered to name an object file or library. (Object files are distinguished from libraries by the linker according to the file contents.) If linking is done, these object files are used as input to the linker. @item -c @itemx -S @itemx -E If any of these options is used, then the linker is not run, and object file names should not be used as arguments. @xref{Overall Options}. @cindex Libraries @item -l@var{library} Search the library named @var{library} when linking. It makes a difference where in the command you write this option; the linker searches processes libraries and object files in the order they are specified. Thus, @samp{foo.o -lz bar.o} searches library @samp{z} after file @file{foo.o} but before @file{bar.o}. If @file{bar.o} refers to functions in @samp{z}, those functions may not be loaded. The linker searches a standard list of directories for the library, which is actually a file named @file{lib@var{library}.a}. The linker then uses this file as if it had been specified precisely by name. The directories searched include several standard system directories plus any that you specify with @samp{-L}. Normally the files found this way are library files---archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an @samp{-l} option and specifying a file name is that @samp{-l} surrounds @var{library} with @samp{lib} and @samp{.a} and searches several directories. @item -lobjc You need this special case of the @samp{-l} option in order to link an Objective C program. @item -nostartfiles Do not use the standard system startup files when linking. The standard system libraries are used normally, unless @code{-nostdlib} or @code{-nodefaultlibs} is used. @item -nodefaultlibs Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker. The standard startup files are used normally, unless @code{-nostartfiles} is used. The compiler may generate calls to memcmp, memset, and memcpy for System V (and ANSI C) environments or to bcopy and bzero for BSD environments. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified. @item -nostdlib Do not use the standard system startup files or libraries when linking. No startup files and only the libraries you specify will be passed to the linker. The compiler may generate calls to memcmp, memset, and memcpy for System V (and ANSI C) environments or to bcopy and bzero for BSD environments. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified. @cindex @code{-lgcc}, use with @code{-nostdlib} @cindex @code{-nostdlib} and unresolved references @cindex unresolved references and @code{-nostdlib} @cindex @code{-lgcc}, use with @code{-nodefaultlibs} @cindex @code{-nodefaultlibs} and unresolved references @cindex unresolved references and @code{-nodefaultlibs} One of the standard libraries bypassed by @samp{-nostdlib} and @samp{-nodefaultlibs} is @file{libgcc.a}, a library of internal subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some languages. @ifset INTERNALS (@xref{Interface,,Interfacing to GCC Output}, for more discussion of @file{libgcc.a}.) @end ifset @ifclear INTERNALS (@xref{Interface,,Interfacing to GCC Output,gcc.info,Porting GCC}, for more discussion of @file{libgcc.a}.) @end ifclear In most cases, you need @file{libgcc.a} even when you want to avoid other standard libraries. In other words, when you specify @samp{-nostdlib} or @samp{-nodefaultlibs} you should usually specify @samp{-lgcc} as well. This ensures that you have no unresolved references to internal GCC library subroutines. (For example, @samp{__main}, used to ensure C++ constructors will be called; @pxref{Collect2,,@code{collect2}}.) @item -s Remove all symbol table and relocation information from the executable. @item -static On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect. @item -shared Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. You must also specify @samp{-fpic} or @samp{-fPIC} on some systems when you specify this option. @item -symbolic Bind references to global symbols when building a shared object. Warn about any unresolved references (unless overridden by the link editor option @samp{-Xlinker -z -Xlinker defs}). Only a few systems support this option. @item -Xlinker @var{option} Pass @var{option} as an option to the linker. You can use this to supply system-specific linker options which GCC does not know how to recognize. If you want to pass an option that takes an argument, you must use @samp{-Xlinker} twice, once for the option and once for the argument. For example, to pass @samp{-assert definitions}, you must write @samp{-Xlinker -assert -Xlinker definitions}. It does not work to write @samp{-Xlinker "-assert definitions"}, because this passes the entire string as a single argument, which is not what the linker expects. @item -Wl,@var{option} Pass @var{option} as an option to the linker. If @var{option} contains commas, it is split into multiple options at the commas. @item -u @var{symbol} Pretend the symbol @var{symbol} is undefined, to force linking of library modules to define it. You can use @samp{-u} multiple times with different symbols to force loading of additional library modules. @end table @node Directory Options @section Options for Directory Search @cindex directory options @cindex options, directory search @cindex search path These options specify directories to search for header files, for libraries and for parts of the compiler: @table @code @item -I@var{dir} Add the directory @var{dir} to the head of the list of directories to be searched for header files. This can be used to override a system header file, substituting your own version, since these directories are searched before the system header file directories. If you use more than one @samp{-I} option, the directories are scanned in left-to-right order; the standard system directories come after. @item -I- Any directories you specify with @samp{-I} options before the @samp{-I-} option are searched only for the case of @samp{#include "@var{file}"}; they are not searched for @samp{#include <@var{file}>}. If additional directories are specified with @samp{-I} options after the @samp{-I-}, these directories are searched for all @samp{#include} directives. (Ordinarily @emph{all} @samp{-I} directories are used this way.) In addition, the @samp{-I-} option inhibits the use of the current directory (where the current input file came from) as the first search directory for @samp{#include "@var{file}"}. There is no way to override this effect of @samp{-I-}. With @samp{-I.} you can specify searching the directory which was current when the compiler was invoked. That is not exactly the same as what the preprocessor does by default, but it is often satisfactory. @samp{-I-} does not inhibit the use of the standard system directories for header files. Thus, @samp{-I-} and @samp{-nostdinc} are independent. @item -L@var{dir} Add directory @var{dir} to the list of directories to be searched for @samp{-l}. @item -B@var{prefix} This option specifies where to find the executables, libraries, include files, and data files of the compiler itself. The compiler driver program runs one or more of the subprograms @file{cpp}, @file{cc1}, @file{as} and @file{ld}. It tries @var{prefix} as a prefix for each program it tries to run, both with and without @samp{@var{machine}/@var{version}/} (@pxref{Target Options}). For each subprogram to be run, the compiler driver first tries the @samp{-B} prefix, if any. If that name is not found, or if @samp{-B} was not specified, the driver tries two standard prefixes, which are @file{/usr/lib/gcc/} and @file{/usr/local/lib/gcc-lib/}. If neither of those results in a file name that is found, the unmodified program name is searched for using the directories specified in your @samp{PATH} environment variable. @samp{-B} prefixes that effectively specify directory names also apply to libraries in the linker, because the compiler translates these options into @samp{-L} options for the linker. They also apply to includes files in the preprocessor, because the compiler translates these options into @samp{-isystem} options for the preprocessor. In this case, the compiler appends @samp{include} to the prefix. The run-time support file @file{libgcc.a} can also be searched for using the @samp{-B} prefix, if needed. If it is not found there, the two standard prefixes above are tried, and that is all. The file is left out of the link if it is not found by those means. Another way to specify a prefix much like the @samp{-B} prefix is to use the environment variable @code{GCC_EXEC_PREFIX}. @xref{Environment Variables}. @item -specs=@var{file} Process @var{file} after the compiler reads in the standard @file{specs} file, in order to override the defaults that the @file{gcc} driver program uses when determining what switches to pass to @file{cc1}, @file{cc1plus}, @file{as}, @file{ld}, etc. More than one @samp{-specs=}@var{file} can be specified on the command line, and they are processed in order, from left to right. @end table @node Target Options @section Specifying Target Machine and Compiler Version @cindex target options @cindex cross compiling @cindex specifying machine version @cindex specifying compiler version and target machine @cindex compiler version, specifying @cindex target machine, specifying By default, GCC compiles code for the same type of machine that you are using. However, it can also be installed as a cross-compiler, to compile for some other type of machine. In fact, several different configurations of GCC, for different target machines, can be installed side by side. Then you specify which one to use with the @samp{-b} option. In addition, older and newer versions of GCC can be installed side by side. One of them (probably the newest) will be the default, but you may sometimes wish to use another. @table @code @item -b @var{machine} The argument @var{machine} specifies the target machine for compilation. This is useful when you have installed GCC as a cross-compiler. The value to use for @var{machine} is the same as was specified as the machine type when configuring GCC as a cross-compiler. For example, if a cross-compiler was configured with @samp{configure i386v}, meaning to compile for an 80386 running System V, then you would specify @samp{-b i386v} to run that cross compiler. When you do not specify @samp{-b}, it normally means to compile for the same type of machine that you are using. @item -V @var{version} The argument @var{version} specifies which version of GCC to run. This is useful when multiple versions are installed. For example, @var{version} might be @samp{2.0}, meaning to run GCC version 2.0. The default version, when you do not specify @samp{-V}, is the last version of GCC that you installed. @end table The @samp{-b} and @samp{-V} options actually work by controlling part of the file name used for the executable files and libraries used for compilation. A given version of GCC, for a given target machine, is normally kept in the directory @file{/usr/local/lib/gcc-lib/@var{machine}/@var{version}}.@refill Thus, sites can customize the effect of @samp{-b} or @samp{-V} either by changing the names of these directories or adding alternate names (or symbolic links). If in directory @file{/usr/local/lib/gcc-lib/} the file @file{80386} is a link to the file @file{i386v}, then @samp{-b 80386} becomes an alias for @samp{-b i386v}. In one respect, the @samp{-b} or @samp{-V} do not completely change to a different compiler: the top-level driver program @code{gcc} that you originally invoked continues to run and invoke the other executables (preprocessor, compiler per se, assembler and linker) that do the real work. However, since no real work is done in the driver program, it usually does not matter that the driver program in use is not the one for the specified target and version. The only way that the driver program depends on the target machine is in the parsing and handling of special machine-specific options. However, this is controlled by a file which is found, along with the other executables, in the directory for the specified version and target machine. As a result, a single installed driver program adapts to any specified target machine and compiler version. The driver program executable does control one significant thing, however: the default version and target machine. Therefore, you can install different instances of the driver program, compiled for different targets or versions, under different names. For example, if the driver for version 2.0 is installed as @code{ogcc} and that for version 2.1 is installed as @code{gcc}, then the command @code{gcc} will use version 2.1 by default, while @code{ogcc} will use 2.0 by default. However, you can choose either version with either command with the @samp{-V} option. @node Submodel Options @section Hardware Models and Configurations @cindex submodel options @cindex specifying hardware config @cindex hardware models and configurations, specifying @cindex machine dependent options Earlier we discussed the standard option @samp{-b} which chooses among different installed compilers for completely different target machines, such as Vax vs. 68000 vs. 80386. In addition, each of these target machine types can have its own special options, starting with @samp{-m}, to choose among various hardware models or configurations---for example, 68010 vs 68020, floating coprocessor or none. A single installed version of the compiler can compile for any model or configuration, according to the options specified. Some configurations of the compiler also support additional special options, usually for compatibility with other compilers on the same platform. @ifset INTERNALS These options are defined by the macro @code{TARGET_SWITCHES} in the machine description. The default for the options is also defined by that macro, which enables you to change the defaults. @end ifset @menu * M680x0 Options:: * VAX Options:: * SPARC Options:: * Convex Options:: * AMD29K Options:: * ARM Options:: * Thumb Options:: * MN10200 Options:: * MN10300 Options:: * M32R/D Options:: * M88K Options:: * RS/6000 and PowerPC Options:: * RT Options:: * MIPS Options:: * i386 Options:: * HPPA Options:: * Intel 960 Options:: * DEC Alpha Options:: * Clipper Options:: * H8/300 Options:: * SH Options:: * System V Options:: * TMS320C3x/C4x Options:: * V850 Options:: * ARC Options:: * NS32K Options:: @end menu @node M680x0 Options @subsection M680x0 Options @cindex M680x0 options These are the @samp{-m} options defined for the 68000 series. The default values for these options depends on which style of 68000 was selected when the compiler was configured; the defaults for the most common choices are given below. @table @code @item -m68000 @itemx -mc68000 Generate output for a 68000. This is the default when the compiler is configured for 68000-based systems. Use this option for microcontrollers with a 68000 or EC000 core, including the 68008, 68302, 68306, 68307, 68322, 68328 and 68356. @item -m68020 @itemx -mc68020 Generate output for a 68020. This is the default when the compiler is configured for 68020-based systems. @item -m68881 Generate output containing 68881 instructions for floating point. This is the default for most 68020 systems unless @samp{-nfp} was specified when the compiler was configured. @item -m68030 Generate output for a 68030. This is the default when the compiler is configured for 68030-based systems. @item -m68040 Generate output for a 68040. This is the default when the compiler is configured for 68040-based systems. This option inhibits the use of 68881/68882 instructions that have to be emulated by software on the 68040. Use this option if your 68040 does not have code to emulate those instructions. @item -m68060 Generate output for a 68060. This is the default when the compiler is configured for 68060-based systems. This option inhibits the use of 68020 and 68881/68882 instructions that have to be emulated by software on the 68060. Use this option if your 68060 does not have code to emulate those instructions. @item -mcpu32 Generate output for a CPU32. This is the default when the compiler is configured for CPU32-based systems. Use this option for microcontrollers with a CPU32 or CPU32+ core, including the 68330, 68331, 68332, 68333, 68334, 68336, 68340, 68341, 68349 and 68360. @item -m5200 Generate output for a 520X "coldfire" family cpu. This is the default when the compiler is configured for 520X-based systems. Use this option for microcontroller with a 5200 core, including the MCF5202, MCF5203, MCF5204 and MCF5202. @item -m68020-40 Generate output for a 68040, without using any of the new instructions. This results in code which can run relatively efficiently on either a 68020/68881 or a 68030 or a 68040. The generated code does use the 68881 instructions that are emulated on the 68040. @item -m68020-60 Generate output for a 68060, without using any of the new instructions. This results in code which can run relatively efficiently on either a 68020/68881 or a 68030 or a 68040. The generated code does use the 68881 instructions that are emulated on the 68060. @item -mfpa Generate output containing Sun FPA instructions for floating point. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not available for all m68k targets. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. The embedded targets @samp{m68k-*-aout} and @samp{m68k-*-coff} do provide software floating point support. @item -mshort Consider type @code{int} to be 16 bits wide, like @code{short int}. @item -mnobitfield Do not use the bit-field instructions. The @samp{-m68000}, @samp{-mcpu32} and @samp{-m5200} options imply @w{@samp{-mnobitfield}}. @item -mbitfield Do use the bit-field instructions. The @samp{-m68020} option implies @samp{-mbitfield}. This is the default if you use a configuration designed for a 68020. @item -mrtd Use a different function-calling convention, in which functions that take a fixed number of arguments return with the @code{rtd} instruction, which pops their arguments while returning. This saves one instruction in the caller since there is no need to pop the arguments there. This calling convention is incompatible with the one normally used on Unix, so you cannot use it if you need to call libraries compiled with the Unix compiler. Also, you must provide function prototypes for all functions that take variable numbers of arguments (including @code{printf}); otherwise incorrect code will be generated for calls to those functions. In addition, seriously incorrect code will result if you call a function with too many arguments. (Normally, extra arguments are harmlessly ignored.) The @code{rtd} instruction is supported by the 68010, 68020, 68030, 68040, 68060 and CPU32 processors, but not by the 68000 or 5200. @item -malign-int @itemx -mno-align-int Control whether GCC aligns @code{int}, @code{long}, @code{long long}, @code{float}, @code{double}, and @code{long double} variables on a 32-bit boundary (@samp{-malign-int}) or a 16-bit boundary (@samp{-mno-align-int}). Aligning variables on 32-bit boundaries produces code that runs somewhat faster on processors with 32-bit busses at the expense of more memory. @strong{Warning:} if you use the @samp{-malign-int} switch, GCC will align structures containing the above types differently than most published application binary interface specifications for the m68k. @end table @node VAX Options @subsection VAX Options @cindex VAX options These @samp{-m} options are defined for the Vax: @table @code @item -munix Do not output certain jump instructions (@code{aobleq} and so on) that the Unix assembler for the Vax cannot handle across long ranges. @item -mgnu Do output those jump instructions, on the assumption that you will assemble with the GNU assembler. @item -mg Output code for g-format floating point numbers instead of d-format. @end table @node SPARC Options @subsection SPARC Options @cindex SPARC options These @samp{-m} switches are supported on the SPARC: @table @code @item -mno-app-regs @itemx -mapp-regs Specify @samp{-mapp-regs} to generate output using the global registers 2 through 4, which the SPARC SVR4 ABI reserves for applications. This is the default. To be fully SVR4 ABI compliant at the cost of some performance loss, specify @samp{-mno-app-regs}. You should compile libraries and system software with this option. @item -mfpu @itemx -mhard-float Generate output containing floating point instructions. This is the default. @item -mno-fpu @itemx -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not available for all SPARC targets. Normally the facilities of the machine's usual C compiler are used, but this cannot be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. The embedded targets @samp{sparc-*-aout} and @samp{sparclite-*-*} do provide software floating point support. @samp{-msoft-float} changes the calling convention in the output file; therefore, it is only useful if you compile @emph{all} of a program with this option. In particular, you need to compile @file{libgcc.a}, the library that comes with GCC, with @samp{-msoft-float} in order for this to work. @item -mhard-quad-float Generate output containing quad-word (long double) floating point instructions. @item -msoft-quad-float Generate output containing library calls for quad-word (long double) floating point instructions. The functions called are those specified in the SPARC ABI. This is the default. As of this writing, there are no sparc implementations that have hardware support for the quad-word floating point instructions. They all invoke a trap handler for one of these instructions, and then the trap handler emulates the effect of the instruction. Because of the trap handler overhead, this is much slower than calling the ABI library routines. Thus the @samp{-msoft-quad-float} option is the default. @item -mno-epilogue @itemx -mepilogue With @samp{-mepilogue} (the default), the compiler always emits code for function exit at the end of each function. Any function exit in the middle of the function (such as a return statement in C) will generate a jump to the exit code at the end of the function. With @samp{-mno-epilogue}, the compiler tries to emit exit code inline at every function exit. @item -mno-flat @itemx -mflat With @samp{-mflat}, the compiler does not generate save/restore instructions and will use a "flat" or single register window calling convention. This model uses %i7 as the frame pointer and is compatible with the normal register window model. Code from either may be intermixed. The local registers and the input registers (0-5) are still treated as "call saved" registers and will be saved on the stack as necessary. With @samp{-mno-flat} (the default), the compiler emits save/restore instructions (except for leaf functions) and is the normal mode of operation. @item -mno-unaligned-doubles @itemx -munaligned-doubles Assume that doubles have 8 byte alignment. This is the default. With @samp{-munaligned-doubles}, GCC assumes that doubles have 8 byte alignment only if they are contained in another type, or if they have an absolute address. Otherwise, it assumes they have 4 byte alignment. Specifying this option avoids some rare compatibility problems with code generated by other compilers. It is not the default because it results in a performance loss, especially for floating point code. @item -mv8 @itemx -msparclite These two options select variations on the SPARC architecture. By default (unless specifically configured for the Fujitsu SPARClite), GCC generates code for the v7 variant of the SPARC architecture. @samp{-mv8} will give you SPARC v8 code. The only difference from v7 code is that the compiler emits the integer multiply and integer divide instructions which exist in SPARC v8 but not in SPARC v7. @samp{-msparclite} will give you SPARClite code. This adds the integer multiply, integer divide step and scan (@code{ffs}) instructions which exist in SPARClite but not in SPARC v7. These options are deprecated and will be deleted in a future GCC release. They have been replaced with @samp{-mcpu=xxx}. @item -mcypress @itemx -msupersparc These two options select the processor for which the code is optimised. With @samp{-mcypress} (the default), the compiler optimizes code for the Cypress CY7C602 chip, as used in the SparcStation/SparcServer 3xx series. This is also appropriate for the older SparcStation 1, 2, IPX etc. With @samp{-msupersparc} the compiler optimizes code for the SuperSparc cpu, as used in the SparcStation 10, 1000 and 2000 series. This flag also enables use of the full SPARC v8 instruction set. These options are deprecated and will be deleted in a future GCC release. They have been replaced with @samp{-mcpu=xxx}. @item -mcpu=@var{cpu_type} Set the instruction set, register set, and instruction scheduling parameters for machine type @var{cpu_type}. Supported values for @var{cpu_type} are @samp{v7}, @samp{cypress}, @samp{v8}, @samp{supersparc}, @samp{sparclite}, @samp{hypersparc}, @samp{sparclite86x}, @samp{f930}, @samp{f934}, @samp{sparclet}, @samp{tsc701}, @samp{v9}, and @samp{ultrasparc}. Default instruction scheduling parameters are used for values that select an architecture and not an implementation. These are @samp{v7}, @samp{v8}, @samp{sparclite}, @samp{sparclet}, @samp{v9}. Here is a list of each supported architecture and their supported implementations. @smallexample v7: cypress v8: supersparc, hypersparc sparclite: f930, f934, sparclite86x sparclet: tsc701 v9: ultrasparc @end smallexample @item -mtune=@var{cpu_type} Set the instruction scheduling parameters for machine type @var{cpu_type}, but do not set the instruction set or register set that the option @samp{-mcpu=}@var{cpu_type} would. The same values for @samp{-mcpu=}@var{cpu_type} are used for @samp{-mtune=}@*@var{cpu_type}, though the only useful values are those that select a particular cpu implementation: @samp{cypress}, @samp{supersparc}, @samp{hypersparc}, @samp{f930}, @samp{f934}, @samp{sparclite86x}, @samp{tsc701}, @samp{ultrasparc}. @item -malign-loops=@var{num} Align loops to a 2 raised to a @var{num} byte boundary. If @samp{-malign-loops} is not specified, the default is 2. @item -malign-jumps=@var{num} Align instructions that are only jumped to to a 2 raised to a @var{num} byte boundary. If @samp{-malign-jumps} is not specified, the default is 2. @item -malign-functions=@var{num} Align the start of functions to a 2 raised to @var{num} byte boundary. If @samp{-malign-functions} is not specified, the default is 2 if compiling for 32 bit sparc, and 5 if compiling for 64 bit sparc. @end table These @samp{-m} switches are supported in addition to the above on the SPARCLET processor. @table @code @item -mlittle-endian Generate code for a processor running in little-endian mode. @item -mlive-g0 Treat register @code{%g0} as a normal register. GCC will continue to clobber it as necessary but will not assume it always reads as 0. @item -mbroken-saverestore Generate code that does not use non-trivial forms of the @code{save} and @code{restore} instructions. Early versions of the SPARCLET processor do not correctly handle @code{save} and @code{restore} instructions used with arguments. They correctly handle them used without arguments. A @code{save} instruction used without arguments increments the current window pointer but does not allocate a new stack frame. It is assumed that the window overflow trap handler will properly handle this case as will interrupt handlers. @end table These @samp{-m} switches are supported in addition to the above on SPARC V9 processors in 64 bit environments. @table @code @item -mlittle-endian Generate code for a processor running in little-endian mode. @item -m32 @itemx -m64 Generate code for a 32 bit or 64 bit environment. The 32 bit environment sets int, long and pointer to 32 bits. The 64 bit environment sets int to 32 bits and long and pointer to 64 bits. @item -mcmodel=medlow Generate code for the Medium/Low code model: the program must be linked in the low 32 bits of the address space. Pointers are 64 bits. Programs can be statically or dynamically linked. @item -mcmodel=medmid Generate code for the Medium/Middle code model: the program must be linked in the low 44 bits of the address space, the text segment must be less than 2G bytes, and data segment must be within 2G of the text segment. Pointers are 64 bits. @item -mcmodel=medany Generate code for the Medium/Anywhere code model: the program may be linked anywhere in the address space, the text segment must be less than 2G bytes, and data segment must be within 2G of the text segment. Pointers are 64 bits. @item -mcmodel=embmedany Generate code for the Medium/Anywhere code model for embedded systems: assume a 32 bit text and a 32 bit data segment, both starting anywhere (determined at link time). Register %g4 points to the base of the data segment. Pointers still 64 bits. Programs are statically linked, PIC is not supported. @item -mstack-bias @itemx -mno-stack-bias With @samp{-mstack-bias}, GCC assumes that the stack pointer, and frame pointer if present, are offset by -2047 which must be added back when making stack frame references. Otherwise, assume no such offset is present. @end table @node Convex Options @subsection Convex Options @cindex Convex options These @samp{-m} options are defined for Convex: @table @code @item -mc1 Generate output for C1. The code will run on any Convex machine. The preprocessor symbol @code{__convex__c1__} is defined. @item -mc2 Generate output for C2. Uses instructions not available on C1. Scheduling and other optimizations are chosen for max performance on C2. The preprocessor symbol @code{__convex_c2__} is defined. @item -mc32 Generate output for C32xx. Uses instructions not available on C1. Scheduling and other optimizations are chosen for max performance on C32. The preprocessor symbol @code{__convex_c32__} is defined. @item -mc34 Generate output for C34xx. Uses instructions not available on C1. Scheduling and other optimizations are chosen for max performance on C34. The preprocessor symbol @code{__convex_c34__} is defined. @item -mc38 Generate output for C38xx. Uses instructions not available on C1. Scheduling and other optimizations are chosen for max performance on C38. The preprocessor symbol @code{__convex_c38__} is defined. @item -margcount Generate code which puts an argument count in the word preceding each argument list. This is compatible with regular CC, and a few programs may need the argument count word. GDB and other source-level debuggers do not need it; this info is in the symbol table. @item -mnoargcount Omit the argument count word. This is the default. @item -mvolatile-cache Allow volatile references to be cached. This is the default. @item -mvolatile-nocache Volatile references bypass the data cache, going all the way to memory. This is only needed for multi-processor code that does not use standard synchronization instructions. Making non-volatile references to volatile locations will not necessarily work. @item -mlong32 Type long is 32 bits, the same as type int. This is the default. @item -mlong64 Type long is 64 bits, the same as type long long. This option is useless, because no library support exists for it. @end table @node AMD29K Options @subsection AMD29K Options @cindex AMD29K options These @samp{-m} options are defined for the AMD Am29000: @table @code @item -mdw @kindex -mdw @cindex DW bit (29k) Generate code that assumes the @code{DW} bit is set, i.e., that byte and halfword operations are directly supported by the hardware. This is the default. @item -mndw @kindex -mndw Generate code that assumes the @code{DW} bit is not set. @item -mbw @kindex -mbw @cindex byte writes (29k) Generate code that assumes the system supports byte and halfword write operations. This is the default. @item -mnbw @kindex -mnbw Generate code that assumes the systems does not support byte and halfword write operations. @samp{-mnbw} implies @samp{-mndw}. @item -msmall @kindex -msmall @cindex memory model (29k) Use a small memory model that assumes that all function addresses are either within a single 256 KB segment or at an absolute address of less than 256k. This allows the @code{call} instruction to be used instead of a @code{const}, @code{consth}, @code{calli} sequence. @item -mnormal @kindex -mnormal Use the normal memory model: Generate @code{call} instructions only when calling functions in the same file and @code{calli} instructions otherwise. This works if each file occupies less than 256 KB but allows the entire executable to be larger than 256 KB. This is the default. @item -mlarge Always use @code{calli} instructions. Specify this option if you expect a single file to compile into more than 256 KB of code. @item -m29050 @kindex -m29050 @cindex processor selection (29k) Generate code for the Am29050. @item -m29000 @kindex -m29000 Generate code for the Am29000. This is the default. @item -mkernel-registers @kindex -mkernel-registers @cindex kernel and user registers (29k) Generate references to registers @code{gr64-gr95} instead of to registers @code{gr96-gr127}. This option can be used when compiling kernel code that wants a set of global registers disjoint from that used by user-mode code. Note that when this option is used, register names in @samp{-f} flags must use the normal, user-mode, names. @item -muser-registers @kindex -muser-registers Use the normal set of global registers, @code{gr96-gr127}. This is the default. @item -mstack-check @itemx -mno-stack-check @kindex -mstack-check @cindex stack checks (29k) Insert (or do not insert) a call to @code{__msp_check} after each stack adjustment. This is often used for kernel code. @item -mstorem-bug @itemx -mno-storem-bug @kindex -mstorem-bug @cindex storem bug (29k) @samp{-mstorem-bug} handles 29k processors which cannot handle the separation of a mtsrim insn and a storem instruction (most 29000 chips to date, but not the 29050). @item -mno-reuse-arg-regs @itemx -mreuse-arg-regs @kindex -mreuse-arg-regs @samp{-mno-reuse-arg-regs} tells the compiler to only use incoming argument registers for copying out arguments. This helps detect calling a function with fewer arguments than it was declared with. @item -mno-impure-text @itemx -mimpure-text @kindex -mimpure-text @samp{-mimpure-text}, used in addition to @samp{-shared}, tells the compiler to not pass @samp{-assert pure-text} to the linker when linking a shared object. @item -msoft-float @kindex -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not part of GCC. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. @item -mno-multm @kindex -mno-multm Do not generate multm or multmu instructions. This is useful for some embedded systems which do not have trap handlers for these instructions. @end table @node ARM Options @subsection ARM Options @cindex ARM options These @samp{-m} options are defined for Advanced RISC Machines (ARM) architectures: @table @code @item -mapcs-frame @kindex -mapcs-frame Generate a stack frame that is compliant with the ARM Procedure Call Standard for all functions, even if this is not strictly necessary for correct execution of the code. Specifying @samp{-fomit-frame-pointer} with this option will cause the stack frames not to be generated for leaf functions. The default is @samp{-mno-apcs-frame}. @item -mapcs @kindex -mapcs This is a synonym for @samp{-mapcs-frame}. @item -mapcs-26 @kindex -mapcs-26 Generate code for a processor running with a 26-bit program counter, and conforming to the function calling standards for the APCS 26-bit option. This option replaces the @samp{-m2} and @samp{-m3} options of previous releases of the compiler. @item -mapcs-32 @kindex -mapcs-32 Generate code for a processor running with a 32-bit program counter, and conforming to the function calling standards for the APCS 32-bit option. This option replaces the @samp{-m6} option of previous releases of the compiler. @item -mapcs-stack-check @kindex -mapcs-stack-check @kindex -mno-apcs-stack-check Generate code to check the amount of stack space available upon entry to every function (that actually uses some stack space). If there is insufficient space available then either the function @samp{__rt_stkovf_split_small} or @samp{__rt_stkovf_split_big} will be called, depending upon the amount of stack space required. The run time system is required to provide these functions. The default is @samp{-mno-apcs-stack-check}, since this produces smaller code. @item -mapcs-float @kindex -mapcs-float @kindex -mno-apcs-float Pass floating point arguments using the float point registers. This is one of the variants of the APCS. This option is reccommended if the target hardware has a floating point unit or if a lot of floating point arithmetic is going to be performed by the code. The default is @samp{-mno-apcs-float}, since integer only code is slightly increased in size if @samp{-mapcs-float} is used. @item -mapcs-reentrant @kindex -mapcs-reentrant @kindex -mno-apcs-reentrant Generate reentrant, position independent code. This is the equivalent to specifying the @samp{-fpic} option. The default is @samp{-mno-apcs-reentrant}. @item -mthumb-interwork @kindex -mthumb-interwork @kindex -mno-thumb-interwork Generate code which supports calling between the ARM and THUMB instruction sets. Without this option the two instruction sets cannot be reliably used inside one program. The default is @samp{-mno-thumb-interwork}, since slightly larger code is generated when @samp{-mthumb-interwork} is specified. @item -mno-sched-prolog @kindex -mno-sched-prolog @kindex -msched-prolog Prevent the reordering of instructions in the function prolog, or the merging of those instruction with the instructions in the function's body. This means that all functions will start with a recognisable set of instructions (or in fact one of a chioce from a small set of different function prologues), and this information can be used to locate the start if functions inside an executable piece of code. The default is @samp{-msched-prolog}. @item -mhard-float Generate output containing floating point instructions. This is the default. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not available for all ARM targets. Normally the facilities of the machine's usual C compiler are used, but this cannot be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. @samp{-msoft-float} changes the calling convention in the output file; therefore, it is only useful if you compile @emph{all} of a program with this option. In particular, you need to compile @file{libgcc.a}, the library that comes with GCC, with @samp{-msoft-float} in order for this to work. @item -mlittle-endian Generate code for a processor running in little-endian mode. This is the default for all standard configurations. @item -mbig-endian Generate code for a processor running in big-endian mode; the default is to compile code for a little-endian processor. @item -mwords-little-endian This option only applies when generating code for big-endian processors. Generate code for a little-endian word order but a big-endian byte order. That is, a byte order of the form @samp{32107654}. Note: this option should only be used if you require compatibility with code for big-endian ARM processors generated by versions of the compiler prior to 2.8. @item -mshort-load-bytes @kindex -mshort-load-bytes Do not try to load half-words (eg @samp{short}s) by loading a word from an unaligned address. For some targets the MMU is configured to trap unaligned loads; use this option to generate code that is safe in these environments. @item -mno-short-load-bytes @kindex -mno-short-load-bytes Use unaligned word loads to load half-words (eg @samp{short}s). This option produces more efficient code, but the MMU is sometimes configured to trap these instructions. @item -mshort-load-words @kindex -mshort-load-words This is a synonym for the @samp{-mno-short-load-bytes}. @item -mno-short-load-words @kindex -mno-short-load-words This is a synonym for the @samp{-mshort-load-bytes}. @item -mbsd @kindex -mbsd This option only applies to RISC iX. Emulate the native BSD-mode compiler. This is the default if @samp{-ansi} is not specified. @item -mxopen @kindex -mxopen This option only applies to RISC iX. Emulate the native X/Open-mode compiler. @item -mno-symrename @kindex -mno-symrename This option only applies to RISC iX. Do not run the assembler post-processor, @samp{symrename}, after code has been assembled. Normally it is necessary to modify some of the standard symbols in preparation for linking with the RISC iX C library; this option suppresses this pass. The post-processor is never run when the compiler is built for cross-compilation. @item -mcpu= @itemx -mtune= @kindex -mcpu= @kindex -mtune= This specifies the name of the target ARM processor. GCC uses this name to determine what kind of instructions it can use when generating assembly code. Permissable names are: arm2, arm250, arm3, arm6, arm60, arm600, arm610, arm620, arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, arm700i, arm710, arm710c, arm7100, arm7500, arm7500fe, arm7tdmi, arm8, strongarm, strongarm110, strongarm1100, arm8, arm810, arm9, arm9tdmi. @samp{-mtune=} is a synonym for @samp{-mcpue=} to support older versions of GCC. @item -march= @kindex -march= This specifies the name of the target ARM architecture. GCC uses this name to determine what kind of instructions it can use when generating assembly code. This option can be used in conjunction with or instead of the @samp{-mcpu=} option. Permissable names are: armv2, armv2a, armv3, armv3m, armv4, armv4t @item -mfpe= @itemx -mfp= @kindex -mfpe= @kindex -mfp= This specifes the version of the floating point emulation available on the target. Permissable values are 2 and 3. @samp{-mfp=} is a synonym for @samp{-mfpe=} to support older versions of GCC. @item -mstructure-size-boundary= @kindex -mstructure-size-boundary The size of all structures and unions will be rounded up to a multiple of the number of bits set by this option. Permissable values are 8 and 32. The default value varies for different toolchains. For the COFF targeted toolchain the default value is 8. Specifying the larger number can produced faster, more efficient code, but can also increase the size of the program. The two values are potentially incompatible. Code compiled with one value cannot necessarily expect to work with code or libraries compiled with the other value, if they exchange information using structures or unions. Programmers are encouraged to use the 32 value as future versions of the toolchain may default to this value. @item -mabort-on-noreturn @kindex -mabort-on-noreturn @kindex -mnoabort-on-noreturn Generate a call to the function abort at the end of a noreturn function. It will be executed if the function tries to return. @end table @node Thumb Options @subsection Thumb Options @cindex Thumb Options @table @code @item -mthumb-interwork @kindex -mthumb-interwork @kindex -mno-thumb-interwork Generate code which supports calling between the THUMB and ARM instruction sets. Without this option the two instruction sets cannot be reliably used inside one program. The default is @samp{-mno-thumb-interwork}, since slightly smaller code is generated with this option. @item -mtpcs-frame @kindex -mtpcs-frame @kindex -mno-tpcs-frame Generate a stack frame that is compliant with the Thumb Procedure Call Standard for all non-leaf functions. (A leaf function is one that does not call any other functions). The default is @samp{-mno-apcs-frame}. @item -mtpcs-leaf-frame @kindex -mtpcs-leaf-frame @kindex -mno-tpcs-leaf-frame Generate a stack frame that is compliant with the Thumb Procedure Call Standard for all leaf functions. (A leaf function is one that does not call any other functions). The default is @samp{-mno-apcs-leaf-frame}. @item -mlittle-endian @kindex -mlittle-endian Generate code for a processor running in little-endian mode. This is the default for all standard configurations. @item -mbig-endian @kindex -mbig-endian Generate code for a processor running in big-endian mode. @item -mstructure-size-boundary= @kindex -mstructure-size-boundary The size of all structures and unions will be rounded up to a multiple of the number of bits set by this option. Permissable values are 8 and 32. The default value varies for different toolchains. For the COFF targeted toolchain the default value is 8. Specifying the larger number can produced faster, more efficient code, but can also increase the size of the program. The two values are potentially incompatible. Code compiled with one value cannot necessarily expect to work with code or libraries compiled with the other value, if they exchange information using structures or unions. Programmers are encouraged to use the 32 value as future versions of the toolchain may default to this value. @end table @node MN10200 Options @subsection MN10200 Options @cindex MN10200 options These @samp{-m} options are defined for Matsushita MN10200 architectures: @table @code @item -mrelax Indicate to the linker that it should perform a relaxation optimization pass to shorten branches, calls and absolute memory addresses. This option only has an effect when used on the command line for the final link step. This option makes symbolic debugging impossible. @end table @node MN10300 Options @subsection MN10300 Options @cindex MN10300 options These @samp{-m} options are defined for Matsushita MN10300 architectures: @table @code @item -mmult-bug Generate code to avoid bugs in the multiply instructions for the MN10300 processors. This is the default. @item -mno-mult-bug Do not generate code to avoid bugs in the multiply instructions for the MN10300 processors. @item -mrelax Indicate to the linker that it should perform a relaxation optimization pass to shorten branches, calls and absolute memory addresses. This option only has an effect when used on the command line for the final link step. This option makes symbolic debugging impossible. @end table @node M32R/D Options @subsection M32R/D Options @cindex M32R/D options These @samp{-m} options are defined for Mitsubishi M32R/D architectures: @table @code @item -mcode-model=small Assume all objects live in the lower 16MB of memory (so that their addresses can be loaded with the @code{ld24} instruction), and assume all subroutines are reachable with the @code{bl} instruction. This is the default. The addressability of a particular object can be set with the @code{model} attribute. @item -mcode-model=medium Assume objects may be anywhere in the 32 bit address space (the compiler will generate @code{seth/add3} instructions to load their addresses), and assume all subroutines are reachable with the @code{bl} instruction. @item -mcode-model=large Assume objects may be anywhere in the 32 bit address space (the compiler will generate @code{seth/add3} instructions to load their addresses), and assume subroutines may not be reachable with the @code{bl} instruction (the compiler will generate the much slower @code{seth/add3/jl} instruction sequence). @item -msdata=none Disable use of the small data area. Variables will be put into one of @samp{.data}, @samp{bss}, or @samp{.rodata} (unless the @code{section} attribute has been specified). This is the default. The small data area consists of sections @samp{.sdata} and @samp{.sbss}. Objects may be explicitly put in the small data area with the @code{section} attribute using one of these sections. @item -msdata=sdata Put small global and static data in the small data area, but do not generate special code to reference them. @item -msdata=use Put small global and static data in the small data area, and generate special instructions to reference them. @item -G @var{num} @cindex smaller data references Put global and static objects less than or equal to @var{num} bytes into the small data or bss sections instead of the normal data or bss sections. The default value of @var{num} is 8. The @samp{-msdata} option must be set to one of @samp{sdata} or @samp{use} for this option to have any effect. All modules should be compiled with the same @samp{-G @var{num}} value. Compiling with different values of @var{num} may or may not work; if it doesn't the linker will give an error message - incorrect code will not be generated. @end table @node M88K Options @subsection M88K Options @cindex M88k options These @samp{-m} options are defined for Motorola 88k architectures: @table @code @item -m88000 @kindex -m88000 Generate code that works well on both the m88100 and the m88110. @item -m88100 @kindex -m88100 Generate code that works best for the m88100, but that also runs on the m88110. @item -m88110 @kindex -m88110 Generate code that works best for the m88110, and may not run on the m88100. @item -mbig-pic @kindex -mbig-pic Obsolete option to be removed from the next revision. Use @samp{-fPIC}. @item -midentify-revision @kindex -midentify-revision @kindex ident @cindex identifying source, compiler (88k) Include an @code{ident} directive in the assembler output recording the source file name, compiler name and version, timestamp, and compilation flags used. @item -mno-underscores @kindex -mno-underscores @cindex underscores, avoiding (88k) In assembler output, emit symbol names without adding an underscore character at the beginning of each name. The default is to use an underscore as prefix on each name. @item -mocs-debug-info @itemx -mno-ocs-debug-info @kindex -mocs-debug-info @kindex -mno-ocs-debug-info @cindex OCS (88k) @cindex debugging, 88k OCS Include (or omit) additional debugging information (about registers used in each stack frame) as specified in the 88open Object Compatibility Standard, ``OCS''. This extra information allows debugging of code that has had the frame pointer eliminated. The default for DG/UX, SVr4, and Delta 88 SVr3.2 is to include this information; other 88k configurations omit this information by default. @item -mocs-frame-position @kindex -mocs-frame-position @cindex register positions in frame (88k) When emitting COFF debugging information for automatic variables and parameters stored on the stack, use the offset from the canonical frame address, which is the stack pointer (register 31) on entry to the function. The DG/UX, SVr4, Delta88 SVr3.2, and BCS configurations use @samp{-mocs-frame-position}; other 88k configurations have the default @samp{-mno-ocs-frame-position}. @item -mno-ocs-frame-position @kindex -mno-ocs-frame-position @cindex register positions in frame (88k) When emitting COFF debugging information for automatic variables and parameters stored on the stack, use the offset from the frame pointer register (register 30). When this option is in effect, the frame pointer is not eliminated when debugging information is selected by the -g switch. @item -moptimize-arg-area @itemx -mno-optimize-arg-area @kindex -moptimize-arg-area @kindex -mno-optimize-arg-area @cindex arguments in frame (88k) Control how function arguments are stored in stack frames. @samp{-moptimize-arg-area} saves space by optimizing them, but this conflicts with the 88open specifications. The opposite alternative, @samp{-mno-optimize-arg-area}, agrees with 88open standards. By default GCC does not optimize the argument area. @item -mshort-data-@var{num} @kindex -mshort-data-@var{num} @cindex smaller data references (88k) @cindex r0-relative references (88k) Generate smaller data references by making them relative to @code{r0}, which allows loading a value using a single instruction (rather than the usual two). You control which data references are affected by specifying @var{num} with this option. For example, if you specify @samp{-mshort-data-512}, then the data references affected are those involving displacements of less than 512 bytes. @samp{-mshort-data-@var{num}} is not effective for @var{num} greater than 64k. @item -mserialize-volatile @kindex -mserialize-volatile @itemx -mno-serialize-volatile @kindex -mno-serialize-volatile @cindex sequential consistency on 88k Do, or don't, generate code to guarantee sequential consistency of volatile memory references. By default, consistency is guaranteed. The order of memory references made by the MC88110 processor does not always match the order of the instructions requesting those references. In particular, a load instruction may execute before a preceding store instruction. Such reordering violates sequential consistency of volatile memory references, when there are multiple processors. When consistency must be guaranteed, GNU C generates special instructions, as needed, to force execution in the proper order. The MC88100 processor does not reorder memory references and so always provides sequential consistency. However, by default, GNU C generates the special instructions to guarantee consistency even when you use @samp{-m88100}, so that the code may be run on an MC88110 processor. If you intend to run your code only on the MC88100 processor, you may use @samp{-mno-serialize-volatile}. The extra code generated to guarantee consistency may affect the performance of your application. If you know that you can safely forgo this guarantee, you may use @samp{-mno-serialize-volatile}. @item -msvr4 @itemx -msvr3 @kindex -msvr4 @kindex -msvr3 @cindex assembler syntax, 88k @cindex SVr4 Turn on (@samp{-msvr4}) or off (@samp{-msvr3}) compiler extensions related to System V release 4 (SVr4). This controls the following: @enumerate @item Which variant of the assembler syntax to emit. @item @samp{-msvr4} makes the C preprocessor recognize @samp{#pragma weak} that is used on System V release 4. @item @samp{-msvr4} makes GCC issue additional declaration directives used in SVr4. @end enumerate @samp{-msvr4} is the default for the m88k-motorola-sysv4 and m88k-dg-dgux m88k configurations. @samp{-msvr3} is the default for all other m88k configurations. @item -mversion-03.00 @kindex -mversion-03.00 This option is obsolete, and is ignored. @c ??? which asm syntax better for GAS? option there too? @item -mno-check-zero-division @itemx -mcheck-zero-division @kindex -mno-check-zero-division @kindex -mcheck-zero-division @cindex zero division on 88k Do, or don't, generate code to guarantee that integer division by zero will be detected. By default, detection is guaranteed. Some models of the MC88100 processor fail to trap upon integer division by zero under certain conditions. By default, when compiling code that might be run on such a processor, GNU C generates code that explicitly checks for zero-valued divisors and traps with exception number 503 when one is detected. Use of mno-check-zero-division suppresses such checking for code generated to run on an MC88100 processor. GNU C assumes that the MC88110 processor correctly detects all instances of integer division by zero. When @samp{-m88110} is specified, both @samp{-mcheck-zero-division} and @samp{-mno-check-zero-division} are ignored, and no explicit checks for zero-valued divisors are generated. @item -muse-div-instruction @kindex -muse-div-instruction @cindex divide instruction, 88k Use the div instruction for signed integer division on the MC88100 processor. By default, the div instruction is not used. On the MC88100 processor the signed integer division instruction div) traps to the operating system on a negative operand. The operating system transparently completes the operation, but at a large cost in execution time. By default, when compiling code that might be run on an MC88100 processor, GNU C emulates signed integer division using the unsigned integer division instruction divu), thereby avoiding the large penalty of a trap to the operating system. Such emulation has its own, smaller, execution cost in both time and space. To the extent that your code's important signed integer division operations are performed on two nonnegative operands, it may be desirable to use the div instruction directly. On the MC88110 processor the div instruction (also known as the divs instruction) processes negative operands without trapping to the operating system. When @samp{-m88110} is specified, @samp{-muse-div-instruction} is ignored, and the div instruction is used for signed integer division. Note that the result of dividing INT_MIN by -1 is undefined. In particular, the behavior of such a division with and without @samp{-muse-div-instruction} may differ. @item -mtrap-large-shift @itemx -mhandle-large-shift @kindex -mtrap-large-shift @kindex -mhandle-large-shift @cindex bit shift overflow (88k) @cindex large bit shifts (88k) Include code to detect bit-shifts of more than 31 bits; respectively, trap such shifts or emit code to handle them properly. By default GCC makes no special provision for large bit shifts. @item -mwarn-passed-structs @kindex -mwarn-passed-structs @cindex structure passing (88k) Warn when a function passes a struct as an argument or result. Structure-passing conventions have changed during the evolution of the C language, and are often the source of portability problems. By default, GCC issues no such warning. @end table @node RS/6000 and PowerPC Options @subsection IBM RS/6000 and PowerPC Options @cindex RS/6000 and PowerPC Options @cindex IBM RS/6000 and PowerPC Options These @samp{-m} options are defined for the IBM RS/6000 and PowerPC: @table @code @item -mpower @itemx -mno-power @itemx -mpower2 @itemx -mno-power2 @itemx -mpowerpc @itemx -mno-powerpc @itemx -mpowerpc-gpopt @itemx -mno-powerpc-gpopt @itemx -mpowerpc-gfxopt @itemx -mno-powerpc-gfxopt @itemx -mpowerpc64 @itemx -mno-powerpc64 @kindex -mpower @kindex -mpower2 @kindex -mpowerpc @kindex -mpowerpc-gpopt @kindex -mpowerpc-gfxopt @kindex -mpowerpc64 GCC supports two related instruction set architectures for the RS/6000 and PowerPC. The @dfn{POWER} instruction set are those instructions supported by the @samp{rios} chip set used in the original RS/6000 systems and the @dfn{PowerPC} instruction set is the architecture of the Motorola MPC5xx, MPC6xx, MPC8xx microprocessors, and the IBM 4xx microprocessors. Neither architecture is a subset of the other. However there is a large common subset of instructions supported by both. An MQ register is included in processors supporting the POWER architecture. You use these options to specify which instructions are available on the processor you are using. The default value of these options is determined when configuring GCC. Specifying the @samp{-mcpu=@var{cpu_type}} overrides the specification of these options. We recommend you use the @samp{-mcpu=@var{cpu_type}} option rather than the options listed above. The @samp{-mpower} option allows GCC to generate instructions that are found only in the POWER architecture and to use the MQ register. Specifying @samp{-mpower2} implies @samp{-power} and also allows GCC to generate instructions that are present in the POWER2 architecture but not the original POWER architecture. The @samp{-mpowerpc} option allows GCC to generate instructions that are found only in the 32-bit subset of the PowerPC architecture. Specifying @samp{-mpowerpc-gpopt} implies @samp{-mpowerpc} and also allows GCC to use the optional PowerPC architecture instructions in the General Purpose group, including floating-point square root. Specifying @samp{-mpowerpc-gfxopt} implies @samp{-mpowerpc} and also allows GCC to use the optional PowerPC architecture instructions in the Graphics group, including floating-point select. The @samp{-mpowerpc64} option allows GCC to generate the additional 64-bit instructions that are found in the full PowerPC64 architecture and to treat GPRs as 64-bit, doubleword quantities. GCC defaults to @samp{-mno-powerpc64}. If you specify both @samp{-mno-power} and @samp{-mno-powerpc}, GCC will use only the instructions in the common subset of both architectures plus some special AIX common-mode calls, and will not use the MQ register. Specifying both @samp{-mpower} and @samp{-mpowerpc} permits GCC to use any instruction from either architecture and to allow use of the MQ register; specify this for the Motorola MPC601. @item -mnew-mnemonics @itemx -mold-mnemonics @kindex -mnew-mnemonics @kindex -mold-mnemonics Select which mnemonics to use in the generated assembler code. @samp{-mnew-mnemonics} requests output that uses the assembler mnemonics defined for the PowerPC architecture, while @samp{-mold-mnemonics} requests the assembler mnemonics defined for the POWER architecture. Instructions defined in only one architecture have only one mnemonic; GCC uses that mnemonic irrespective of which of these options is specified. GCC defaults to the mnemonics appropriate for the architecture in use. Specifying @samp{-mcpu=@var{cpu_type}} sometimes overrides the value of these option. Unless you are building a cross-compiler, you should normally not specify either @samp{-mnew-mnemonics} or @samp{-mold-mnemonics}, but should instead accept the default. @item -mcpu=@var{cpu_type} @kindex -mcpu Set architecture type, register usage, choice of mnemonics, and instruction scheduling parameters for machine type @var{cpu_type}. Supported values for @var{cpu_type} are @samp{rs6000}, @samp{rios1}, @samp{rios2}, @samp{rsc}, @samp{601}, @samp{602}, @samp{603}, @samp{603e}, @samp{604}, @samp{604e}, @samp{620}, @samp{740}, @samp{750}, @samp{power}, @samp{power2}, @samp{powerpc}, @samp{403}, @samp{505}, @samp{801}, @samp{821}, @samp{823}, and @samp{860} and @samp{common}. @samp{-mcpu=power}, @samp{-mcpu=power2}, and @samp{-mcpu=powerpc} specify generic POWER, POWER2 and pure PowerPC (i.e., not MPC601) architecture machine types, with an appropriate, generic processor model assumed for scheduling purposes.@refill @c overfull hbox here --bob 22 jul96 @c original text between ignore ... end ignore @ignore Specifying any of the @samp{-mcpu=rios1}, @samp{-mcpu=rios2}, @samp{-mcpu=rsc}, @samp{-mcpu=power}, or @samp{-mcpu=power2} options enables the @samp{-mpower} option and disables the @samp{-mpowerpc} option; @samp{-mcpu=601} enables both the @samp{-mpower} and @samp{-mpowerpc} options; all of @samp{-mcpu=602}, @samp{-mcpu=603}, @samp{-mcpu=603e}, @samp{-mcpu=604}, @samp{-mcpu=604e}, @samp{-mcpu=620}, @samp{-mcpu=403}, @samp{-mcpu=505}, @samp{-mcpu=801}, @samp{-mcpu=821}, @samp{-mcpu=823}, @samp{-mcpu=860} and @samp{-mcpu=powerpc} enable the @samp{-mpowerpc} option and disable the @samp{-mpower} option; @samp{-mcpu=common} disables both the @samp{-mpower} and @samp{-mpowerpc} options.@refill @end ignore @c changed paragraph Specifying any of the following options: @samp{-mcpu=rios1}, @samp{-mcpu=rios2}, @samp{-mcpu=rsc}, @samp{-mcpu=power}, or @samp{-mcpu=power2} enables the @samp{-mpower} option and disables the @samp{-mpowerpc} option; @samp{-mcpu=601} enables both the @samp{-mpower} and @samp{-mpowerpc} options. All of @samp{-mcpu=602}, @samp{-mcpu=603}, @samp{-mcpu=603e}, @samp{-mcpu=604}, @samp{-mcpu=620}, enable the @samp{-mpowerpc} option and disable the @samp{-mpower} option. Exactly similarly, all of @samp{-mcpu=403}, @samp{-mcpu=505}, @samp{-mcpu=821}, @samp{-mcpu=860} and @samp{-mcpu=powerpc} enable the @samp{-mpowerpc} option and disable the @samp{-mpower} option. @samp{-mcpu=common} disables both the @samp{-mpower} and @samp{-mpowerpc} options.@refill @c end changes to prevent overfull hboxes AIX versions 4 or greater selects @samp{-mcpu=common} by default, so that code will operate on all members of the RS/6000 and PowerPC families. In that case, GCC will use only the instructions in the common subset of both architectures plus some special AIX common-mode calls, and will not use the MQ register. GCC assumes a generic processor model for scheduling purposes. Specifying any of the options @samp{-mcpu=rios1}, @samp{-mcpu=rios2}, @samp{-mcpu=rsc}, @samp{-mcpu=power}, or @samp{-mcpu=power2} also disables the @samp{new-mnemonics} option. Specifying @samp{-mcpu=601}, @samp{-mcpu=602}, @samp{-mcpu=603}, @samp{-mcpu=603e}, @samp{-mcpu=604}, @samp{620}, @samp{403}, or @samp{-mcpu=powerpc} also enables the @samp{new-mnemonics} option.@refill Specifying @samp{-mcpu=403}, @samp{-mcpu=821}, or @samp{-mcpu=860} also enables the @samp{-msoft-float} option. @item -mtune=@var{cpu_type} Set the instruction scheduling parameters for machine type @var{cpu_type}, but do not set the architecture type, register usage, choice of mnemonics like @samp{-mcpu=}@var{cpu_type} would. The same values for @var{cpu_type} are used for @samp{-mtune=}@var{cpu_type} as for @samp{-mcpu=}@var{cpu_type}. The @samp{-mtune=}@var{cpu_type} option overrides the @samp{-mcpu=}@var{cpu_type} option in terms of instruction scheduling parameters. @item -mfull-toc @itemx -mno-fp-in-toc @itemx -mno-sum-in-toc @itemx -mminimal-toc @kindex -mminimal-toc Modify generation of the TOC (Table Of Contents), which is created for every executable file. The @samp{-mfull-toc} option is selected by default. In that case, GCC will allocate at least one TOC entry for each unique non-automatic variable reference in your program. GCC will also place floating-point constants in the TOC. However, only 16,384 entries are available in the TOC. If you receive a linker error message that saying you have overflowed the available TOC space, you can reduce the amount of TOC space used with the @samp{-mno-fp-in-toc} and @samp{-mno-sum-in-toc} options. @samp{-mno-fp-in-toc} prevents GCC from putting floating-point constants in the TOC and @samp{-mno-sum-in-toc} forces GCC to generate code to calculate the sum of an address and a constant at run-time instead of putting that sum into the TOC. You may specify one or both of these options. Each causes GCC to produce very slightly slower and larger code at the expense of conserving TOC space. If you still run out of space in the TOC even when you specify both of these options, specify @samp{-mminimal-toc} instead. This option causes GCC to make only one TOC entry for every file. When you specify this option, GCC will produce code that is slower and larger but which uses extremely little TOC space. You may wish to use this option only on files that contain less frequently executed code. @refill @item -maix64 @itemx -maix32 @kindex -maix64 @kindex -maix32 Enable AIX 64-bit ABI and calling convention: 64-bit pointers, 64-bit @code{long} type, and the infrastructure needed to support them. Specifying @samp{-maix64} implies @samp{-mpowerpc64} and @samp{-mpowerpc}, while @samp{-maix32} disables the 64-bit ABI and implies @samp{-mno-powerpc64}. GCC defaults to @samp{-maix32}. @item -mxl-call @itemx -mno-xl-call @kindex -mxl-call On AIX, pass floating-point arguments to prototyped functions beyond the register save area (RSA) on the stack in addition to argument FPRs. The AIX calling convention was extended but not initially documented to handle an obscure K&R C case of calling a function that takes the address of its arguments with fewer arguments than declared. AIX XL compilers access floating point arguments which do not fit in the RSA from the stack when a subroutine is compiled without optimization. Because always storing floating-point arguments on the stack is inefficient and rarely needed, this option is not enabled by default and only is necessary when calling subroutines compiled by AIX XL compilers without optimization. @item -mthreads @kindex -mthreads Support @dfn{AIX Threads}. Link an application written to use @dfn{pthreads} with special libraries and startup code to enable the application to run. @item -mpe @kindex -mpe Support @dfn{IBM RS/6000 SP} @dfn{Parallel Environment} (PE). Link an application written to use message passing with special startup code to enable the application to run. The system must have PE installed in the standard location (@file{/usr/lpp/ppe.poe/}), or the @file{specs} file must be overridden with the @samp{-specs=} option to specify the appropriate directory location. The Parallel Environment does not support threads, so the @samp{-mpe} option and the @samp{-mthreads} option are incompatible. @item -msoft-float @itemx -mhard-float @kindex -msoft-float Generate code that does not use (uses) the floating-point register set. Software floating point emulation is provided if you use the @samp{-msoft-float} option, and pass the option to GCC when linking. @item -mmultiple @itemx -mno-multiple Generate code that uses (does not use) the load multiple word instructions and the store multiple word instructions. These instructions are generated by default on POWER systems, and not generated on PowerPC systems. Do not use @samp{-mmultiple} on little endian PowerPC systems, since those instructions do not work when the processor is in little endian mode. The exceptions are PPC740 and PPC750 which permit the instructions usage in little endian mode. @item -mstring @itemx -mno-string @kindex -mstring Generate code that uses (does not use) the load string instructions and the store string word instructions to save multiple registers and do small block moves. These instructions are generated by default on POWER systems, and not generated on PowerPC systems. Do not use @samp{-mstring} on little endian PowerPC systems, since those instructions do not work when the processor is in little endian mode. The exceptions are PPC740 and PPC750 which permit the instructions usage in little endian mode. @item -mupdate @itemx -mno-update @kindex -mupdate Generate code that uses (does not use) the load or store instructions that update the base register to the address of the calculated memory location. These instructions are generated by default. If you use @samp{-mno-update}, there is a small window between the time that the stack pointer is updated and the address of the previous frame is stored, which means code that walks the stack frame across interrupts or signals may get corrupted data. @item -mfused-madd @itemx -mno-fused-madd @kindex -mfused-madd Generate code that uses (does not use) the floating point multiply and accumulate instructions. These instructions are generated by default if hardware floating is used. @item -mno-bit-align @itemx -mbit-align @kindex -mbit-align On System V.4 and embedded PowerPC systems do not (do) force structures and unions that contain bit fields to be aligned to the base type of the bit field. For example, by default a structure containing nothing but 8 @code{unsigned} bitfields of length 1 would be aligned to a 4 byte boundary and have a size of 4 bytes. By using @samp{-mno-bit-align}, the structure would be aligned to a 1 byte boundary and be one byte in size. @item -mno-strict-align @itemx -mstrict-align @kindex -mstrict-align On System V.4 and embedded PowerPC systems do not (do) assume that unaligned memory references will be handled by the system. @item -mrelocatable @itemx -mno-relocatable @kindex -mrelocatable On embedded PowerPC systems generate code that allows (does not allow) the program to be relocated to a different address at runtime. If you use @samp{-mrelocatable} on any module, all objects linked together must be compiled with @samp{-mrelocatable} or @samp{-mrelocatable-lib}. @item -mrelocatable-lib @itemx -mno-relocatable-lib On embedded PowerPC systems generate code that allows (does not allow) the program to be relocated to a different address at runtime. Modules compiled with @samp{-mrelocatable-lib} can be linked with either modules compiled without @samp{-mrelocatable} and @samp{-mrelocatable-lib} or with modules compiled with the @samp{-mrelocatable} options. @item -mno-toc @itemx -mtoc On System V.4 and embedded PowerPC systems do not (do) assume that register 2 contains a pointer to a global area pointing to the addresses used in the program. @item -mlittle @itemx -mlittle-endian On System V.4 and embedded PowerPC systems compile code for the processor in little endian mode. The @samp{-mlittle-endian} option is the same as @samp{-mlittle}. @item -mbig @itemx -mbig-endian On System V.4 and embedded PowerPC systems compile code for the processor in big endian mode. The @samp{-mbig-endian} option is the same as @samp{-mbig}. @item -mcall-sysv On System V.4 and embedded PowerPC systems compile code using calling conventions that adheres to the March 1995 draft of the System V Application Binary Interface, PowerPC processor supplement. This is the default unless you configured GCC using @samp{powerpc-*-eabiaix}. @item -mcall-sysv-eabi Specify both @samp{-mcall-sysv} and @samp{-meabi} options. @item -mcall-sysv-noeabi Specify both @samp{-mcall-sysv} and @samp{-mno-eabi} options. @item -mcall-aix On System V.4 and embedded PowerPC systems compile code using calling conventions that are similar to those used on AIX. This is the default if you configured GCC using @samp{powerpc-*-eabiaix}. @item -mcall-solaris On System V.4 and embedded PowerPC systems compile code for the Solaris operating system. @item -mcall-linux On System V.4 and embedded PowerPC systems compile code for the Linux-based GNU system. @item -mprototype @itemx -mno-prototype On System V.4 and embedded PowerPC systems assume that all calls to variable argument functions are properly prototyped. Otherwise, the compiler must insert an instruction before every non prototyped call to set or clear bit 6 of the condition code register (@var{CR}) to indicate whether floating point values were passed in the floating point registers in case the function takes a variable arguments. With @samp{-mprototype}, only calls to prototyped variable argument functions will set or clear the bit. @item -msim On embedded PowerPC systems, assume that the startup module is called @file{sim-crt0.o} and that the standard C libraries are @file{libsim.a} and @file{libc.a}. This is the default for @samp{powerpc-*-eabisim}. configurations. @item -mmvme On embedded PowerPC systems, assume that the startup module is called @file{crt0.o} and the standard C libraries are @file{libmvme.a} and @file{libc.a}. @item -mads On embedded PowerPC systems, assume that the startup module is called @file{crt0.o} and the standard C libraries are @file{libads.a} and @file{libc.a}. @item -myellowknife On embedded PowerPC systems, assume that the startup module is called @file{crt0.o} and the standard C libraries are @file{libyk.a} and @file{libc.a}. @item -memb On embedded PowerPC systems, set the @var{PPC_EMB} bit in the ELF flags header to indicate that @samp{eabi} extended relocations are used. @item -meabi @itemx -mno-eabi On System V.4 and embedded PowerPC systems do (do not) adhere to the Embedded Applications Binary Interface (eabi) which is a set of modifications to the System V.4 specifications. Selecting @code{-meabi} means that the stack is aligned to an 8 byte boundary, a function @code{__eabi} is called to from @code{main} to set up the eabi environment, and the @samp{-msdata} option can use both @code{r2} and @code{r13} to point to two separate small data areas. Selecting @code{-mno-eabi} means that the stack is aligned to a 16 byte boundary, do not call an initialization function from @code{main}, and the @samp{-msdata} option will only use @code{r13} to point to a single small data area. The @samp{-meabi} option is on by default if you configured GCC using one of the @samp{powerpc*-*-eabi*} options. @item -msdata=eabi On System V.4 and embedded PowerPC systems, put small initialized @code{const} global and static data in the @samp{.sdata2} section, which is pointed to by register @code{r2}. Put small initialized non-@code{const} global and static data in the @samp{.sdata} section, which is pointed to by register @code{r13}. Put small uninitialized global and static data in the @samp{.sbss} section, which is adjacent to the @samp{.sdata} section. The @samp{-msdata=eabi} option is incompatible with the @samp{-mrelocatable} option. The @samp{-msdata=eabi} option also sets the @samp{-memb} option. @item -msdata=sysv On System V.4 and embedded PowerPC systems, put small global and static data in the @samp{.sdata} section, which is pointed to by register @code{r13}. Put small uninitialized global and static data in the @samp{.sbss} section, which is adjacent to the @samp{.sdata} section. The @samp{-msdata=sysv} option is incompatible with the @samp{-mrelocatable} option. @item -msdata=default @itemx -msdata On System V.4 and embedded PowerPC systems, if @samp{-meabi} is used, compile code the same as @samp{-msdata=eabi}, otherwise compile code the same as @samp{-msdata=sysv}. @item -msdata-data On System V.4 and embedded PowerPC systems, put small global and static data in the @samp{.sdata} section. Put small uninitialized global and static data in the @samp{.sbss} section. Do not use register @code{r13} to address small data however. This is the default behavior unless other @samp{-msdata} options are used. @item -msdata=none @itemx -mno-sdata On embedded PowerPC systems, put all initialized global and static data in the @samp{.data} section, and all uninitialized data in the @samp{.bss} section. @item -G @var{num} @cindex smaller data references (PowerPC) @cindex .sdata/.sdata2 references (PowerPC) On embedded PowerPC systems, put global and static items less than or equal to @var{num} bytes into the small data or bss sections instead of the normal data or bss section. By default, @var{num} is 8. The @samp{-G @var{num}} switch is also passed to the linker. All modules should be compiled with the same @samp{-G @var{num}} value. @item -mregnames @itemx -mno-regnames On System V.4 and embedded PowerPC systems do (do not) emit register names in the assembly language output using symbolic forms. @end table @node RT Options @subsection IBM RT Options @cindex RT options @cindex IBM RT options These @samp{-m} options are defined for the IBM RT PC: @table @code @item -min-line-mul Use an in-line code sequence for integer multiplies. This is the default. @item -mcall-lib-mul Call @code{lmul$$} for integer multiples. @item -mfull-fp-blocks Generate full-size floating point data blocks, including the minimum amount of scratch space recommended by IBM. This is the default. @item -mminimum-fp-blocks Do not include extra scratch space in floating point data blocks. This results in smaller code, but slower execution, since scratch space must be allocated dynamically. @cindex @file{varargs.h} and RT PC @cindex @file{stdarg.h} and RT PC @item -mfp-arg-in-fpregs Use a calling sequence incompatible with the IBM calling convention in which floating point arguments are passed in floating point registers. Note that @code{varargs.h} and @code{stdargs.h} will not work with floating point operands if this option is specified. @item -mfp-arg-in-gregs Use the normal calling convention for floating point arguments. This is the default. @item -mhc-struct-return Return structures of more than one word in memory, rather than in a register. This provides compatibility with the MetaWare HighC (hc) compiler. Use the option @samp{-fpcc-struct-return} for compatibility with the Portable C Compiler (pcc). @item -mnohc-struct-return Return some structures of more than one word in registers, when convenient. This is the default. For compatibility with the IBM-supplied compilers, use the option @samp{-fpcc-struct-return} or the option @samp{-mhc-struct-return}. @end table @node MIPS Options @subsection MIPS Options @cindex MIPS options These @samp{-m} options are defined for the MIPS family of computers: @table @code @item -mcpu=@var{cpu type} Assume the defaults for the machine type @var{cpu type} when scheduling instructions. The choices for @var{cpu type} are @samp{r2000}, @samp{r3000}, @samp{r3900}, @samp{r4000}, @samp{r4100}, @samp{r4300}, @samp{r4400}, @samp{r4600}, @samp{r4650}, @samp{r5000}, @samp{r6000}, @samp{r8000}, and @samp{orion}. Additionally, the @samp{r2000}, @samp{r3000}, @samp{r4000}, @samp{r5000}, and @samp{r6000} can be abbreviated as @samp{r2k} (or @samp{r2K}), @samp{r3k}, etc. While picking a specific @var{cpu type} will schedule things appropriately for that particular chip, the compiler will not generate any code that does not meet level 1 of the MIPS ISA (instruction set architecture) without a @samp{-mipsX} or @samp{-mabi} switch being used. @item -mips1 Issue instructions from level 1 of the MIPS ISA. This is the default. @samp{r3000} is the default @var{cpu type} at this ISA level. @item -mips2 Issue instructions from level 2 of the MIPS ISA (branch likely, square root instructions). @samp{r6000} is the default @var{cpu type} at this ISA level. @item -mips3 Issue instructions from level 3 of the MIPS ISA (64 bit instructions). @samp{r4000} is the default @var{cpu type} at this ISA level. @item -mips4 Issue instructions from level 4 of the MIPS ISA (conditional move, prefetch, enhanced FPU instructions). @samp{r8000} is the default @var{cpu type} at this ISA level. @item -mfp32 Assume that 32 32-bit floating point registers are available. This is the default. @item -mfp64 Assume that 32 64-bit floating point registers are available. This is the default when the @samp{-mips3} option is used. @item -mgp32 Assume that 32 32-bit general purpose registers are available. This is the default. @item -mgp64 Assume that 32 64-bit general purpose registers are available. This is the default when the @samp{-mips3} option is used. @item -mint64 Force int and long types to be 64 bits wide. See @samp{-mlong32} for an explanation of the default, and the width of pointers. @item -mlong64 Force long types to be 64 bits wide. See @samp{-mlong32} for an explanation of the default, and the width of pointers. @item -mlong32 Force long, int, and pointer types to be 32 bits wide. If none of @samp{-mlong32}, @samp{-mlong64}, or @samp{-mint64} are set, the size of ints, longs, and pointers depends on the ABI and ISA choosen. For @samp{-mabi=32}, and @samp{-mabi=n32}, ints and longs are 32 bits wide. For @samp{-mabi=64}, ints are 32 bits, and longs are 64 bits wide. For @samp{-mabi=eabi} and either @samp{-mips1} or @samp{-mips2}, ints and longs are 32 bits wide. For @samp{-mabi=eabi} and higher ISAs, ints are 32 bits, and longs are 64 bits wide. The width of pointer types is the smaller of the width of longs or the width of general purpose registers (which in turn depends on the ISA). @item -mabi=32 @itemx -mabi=o64 @itemx -mabi=n32 @itemx -mabi=64 @itemx -mabi=eabi Generate code for the indicated ABI. The default instruction level is @samp{-mips1} for @samp{32}, @samp{-mips3} for @samp{n32}, and @samp{-mips4} otherwise. Conversely, with @samp{-mips1} or @samp{-mips2}, the default ABI is @samp{32}; otherwise, the default ABI is @samp{64}. @item -mmips-as Generate code for the MIPS assembler, and invoke @file{mips-tfile} to add normal debug information. This is the default for all platforms except for the OSF/1 reference platform, using the OSF/rose object format. If the either of the @samp{-gstabs} or @samp{-gstabs+} switches are used, the @file{mips-tfile} program will encapsulate the stabs within MIPS ECOFF. @item -mgas Generate code for the GNU assembler. This is the default on the OSF/1 reference platform, using the OSF/rose object format. Also, this is the default if the configure option @samp{--with-gnu-as} is used. @item -msplit-addresses @itemx -mno-split-addresses Generate code to load the high and low parts of address constants separately. This allows @code{gcc} to optimize away redundant loads of the high order bits of addresses. This optimization requires GNU as and GNU ld. This optimization is enabled by default for some embedded targets where GNU as and GNU ld are standard. @item -mrnames @itemx -mno-rnames The @samp{-mrnames} switch says to output code using the MIPS software names for the registers, instead of the hardware names (ie, @var{a0} instead of @var{$4}). The only known assembler that supports this option is the Algorithmics assembler. @item -mgpopt @itemx -mno-gpopt The @samp{-mgpopt} switch says to write all of the data declarations before the instructions in the text section, this allows the MIPS assembler to generate one word memory references instead of using two words for short global or static data items. This is on by default if optimization is selected. @item -mstats @itemx -mno-stats For each non-inline function processed, the @samp{-mstats} switch causes the compiler to emit one line to the standard error file to print statistics about the program (number of registers saved, stack size, etc.). @item -mmemcpy @itemx -mno-memcpy The @samp{-mmemcpy} switch makes all block moves call the appropriate string function (@samp{memcpy} or @samp{bcopy}) instead of possibly generating inline code. @item -mmips-tfile @itemx -mno-mips-tfile The @samp{-mno-mips-tfile} switch causes the compiler not postprocess the object file with the @file{mips-tfile} program, after the MIPS assembler has generated it to add debug support. If @file{mips-tfile} is not run, then no local variables will be available to the debugger. In addition, @file{stage2} and @file{stage3} objects will have the temporary file names passed to the assembler embedded in the object file, which means the objects will not compare the same. The @samp{-mno-mips-tfile} switch should only be used when there are bugs in the @file{mips-tfile} program that prevents compilation. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not part of GCC. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. @item -mhard-float Generate output containing floating point instructions. This is the default if you use the unmodified sources. @item -mabicalls @itemx -mno-abicalls Emit (or do not emit) the pseudo operations @samp{.abicalls}, @samp{.cpload}, and @samp{.cprestore} that some System V.4 ports use for position independent code. @item -mlong-calls @itemx -mno-long-calls Do all calls with the @samp{JALR} instruction, which requires loading up a function's address into a register before the call. You need to use this switch, if you call outside of the current 512 megabyte segment to functions that are not through pointers. @item -mhalf-pic @itemx -mno-half-pic Put pointers to extern references into the data section and load them up, rather than put the references in the text section. @item -membedded-pic @itemx -mno-embedded-pic Generate PIC code suitable for some embedded systems. All calls are made using PC relative address, and all data is addressed using the $gp register. No more than 65536 bytes of global data may be used. This requires GNU as and GNU ld which do most of the work. This currently only works on targets which use ECOFF; it does not work with ELF. @item -membedded-data @itemx -mno-embedded-data Allocate variables to the read-only data section first if possible, then next in the small data section if possible, otherwise in data. This gives slightly slower code than the default, but reduces the amount of RAM required when executing, and thus may be preferred for some embedded systems. @item -msingle-float @itemx -mdouble-float The @samp{-msingle-float} switch tells gcc to assume that the floating point coprocessor only supports single precision operations, as on the @samp{r4650} chip. The @samp{-mdouble-float} switch permits gcc to use double precision operations. This is the default. @item -mmad @itemx -mno-mad Permit use of the @samp{mad}, @samp{madu} and @samp{mul} instructions, as on the @samp{r4650} chip. @item -m4650 Turns on @samp{-msingle-float}, @samp{-mmad}, and, at least for now, @samp{-mcpu=r4650}. @item -mips16 @itemx -mno-mips16 Enable 16-bit instructions. @item -mentry Use the entry and exit pseudo ops. This option can only be used with @samp{-mips16}. @item -EL Compile code for the processor in little endian mode. The requisite libraries are assumed to exist. @item -EB Compile code for the processor in big endian mode. The requisite libraries are assumed to exist. @item -G @var{num} @cindex smaller data references (MIPS) @cindex gp-relative references (MIPS) Put global and static items less than or equal to @var{num} bytes into the small data or bss sections instead of the normal data or bss section. This allows the assembler to emit one word memory reference instructions based on the global pointer (@var{gp} or @var{$28}), instead of the normal two words used. By default, @var{num} is 8 when the MIPS assembler is used, and 0 when the GNU assembler is used. The @samp{-G @var{num}} switch is also passed to the assembler and linker. All modules should be compiled with the same @samp{-G @var{num}} value. @item -nocpp Tell the MIPS assembler to not run its preprocessor over user assembler files (with a @samp{.s} suffix) when assembling them. @end table @ifset INTERNALS These options are defined by the macro @code{TARGET_SWITCHES} in the machine description. The default for the options is also defined by that macro, which enables you to change the defaults. @end ifset @node i386 Options @subsection Intel 386 Options @cindex i386 Options @cindex Intel 386 Options These @samp{-m} options are defined for the i386 family of computers: @table @code @item -mcpu=@var{cpu type} Assume the defaults for the machine type @var{cpu type} when scheduling instructions. The choices for @var{cpu type} are: @multitable @columnfractions .20 .20 .20 .20 @item @samp{i386} @tab @samp{i486} @tab @samp{i586} @tab @samp{i686} @item @samp{pentium} @tab @samp{pentiumpro} @tab @samp{k6} @end multitable While picking a specific @var{cpu type} will schedule things appropriately for that particular chip, the compiler will not generate any code that does not run on the i386 without the @samp{-march=@var{cpu type}} option being used. @samp{i586} is equivalent to @samp{pentium} and @samp{i686} is equivalent to @samp{pentiumpro}. @samp{k6} is the AMD chip as opposed to the Intel ones. @item -march=@var{cpu type} Generate instructions for the machine type @var{cpu type}. The choices for @var{cpu type} are the same as for @samp{-mcpu}. Moreover, specifying @samp{-march=@var{cpu type}} implies @samp{-mcpu=@var{cpu type}}. @item -m386 @itemx -m486 @itemx -mpentium @itemx -mpentiumpro Synonyms for -mcpu=i386, -mcpu=i486, -mcpu=pentium, and -mcpu=pentiumpro respectively. These synonyms are deprecated. @item -mno-ieee-fp @itemx -mieee-fp Control whether or not the compiler uses IEEE floating point comparisons. These handle correctly the case where the result of a comparison is unordered. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not part of GCC. Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. On machines where a function returns floating point results in the 80387 register stack, some floating point opcodes may be emitted even if @samp{-msoft-float} is used. @item -mno-fp-ret-in-387 Do not use the FPU registers for return values of functions. The usual calling convention has functions return values of types @code{float} and @code{double} in an FPU register, even if there is no FPU. The idea is that the operating system should emulate an FPU. The option @samp{-mno-fp-ret-in-387} causes such values to be returned in ordinary CPU registers instead. @item -mno-fancy-math-387 Some 387 emulators do not support the @code{sin}, @code{cos} and @code{sqrt} instructions for the 387. Specify this option to avoid generating those instructions. This option is the default on FreeBSD. As of revision 2.6.1, these instructions are not generated unless you also use the @samp{-ffast-math} switch. @item -malign-double @itemx -mno-align-double Control whether GCC aligns @code{double}, @code{long double}, and @code{long long} variables on a two word boundary or a one word boundary. Aligning @code{double} variables on a two word boundary will produce code that runs somewhat faster on a @samp{Pentium} at the expense of more memory. @strong{Warning:} if you use the @samp{-malign-double} switch, structures containing the above types will be aligned differently than the published application binary interface specifications for the 386. @item -msvr3-shlib @itemx -mno-svr3-shlib Control whether GCC places uninitialized locals into @code{bss} or @code{data}. @samp{-msvr3-shlib} places these locals into @code{bss}. These options are meaningful only on System V Release 3. @item -mno-wide-multiply @itemx -mwide-multiply Control whether GCC uses the @code{mul} and @code{imul} that produce 64 bit results in @code{eax:edx} from 32 bit operands to do @code{long long} multiplies and 32-bit division by constants. @item -mprofiler-epilogue @itemx -mno-profiler-epilogue Generate extra code to write profile information for function exits. This option has no effect except in combination with @samp{-g} or @samp{-pg}. @item -mrtd Use a different function-calling convention, in which functions that take a fixed number of arguments return with the @code{ret} @var{num} instruction, which pops their arguments while returning. This saves one instruction in the caller since there is no need to pop the arguments there. You can specify that an individual function is called with this calling sequence with the function attribute @samp{stdcall}. You can also override the @samp{-mrtd} option by using the function attribute @samp{cdecl}. @xref{Function Attributes}. @strong{Warning:} this calling convention is incompatible with the one normally used on Unix, so you cannot use it if you need to call libraries compiled with the Unix compiler. Also, you must provide function prototypes for all functions that take variable numbers of arguments (including @code{printf}); otherwise incorrect code will be generated for calls to those functions. In addition, seriously incorrect code will result if you call a function with too many arguments. (Normally, extra arguments are harmlessly ignored.) @item -mreg-alloc=@var{regs} Control the default allocation order of integer registers. The string @var{regs} is a series of letters specifying a register. The supported letters are: @code{a} allocate EAX; @code{b} allocate EBX; @code{c} allocate ECX; @code{d} allocate EDX; @code{S} allocate ESI; @code{D} allocate EDI; @code{B} allocate EBP. @item -mregparm=@var{num} Control how many registers are used to pass integer arguments. By default, no registers are used to pass arguments, and at most 3 registers can be used. You can control this behavior for a specific function by using the function attribute @samp{regparm}. @xref{Function Attributes}. @strong{Warning:} if you use this switch, and @var{num} is nonzero, then you must build all modules with the same value, including any libraries. This includes the system libraries and startup modules. @item -malign-loops=@var{num} Align loops to a 2 raised to a @var{num} byte boundary. If @samp{-malign-loops} is not specified, the default is 2 unless gas 2.8 (or later) is being used in which case the default is to align the loop on a 16 byte boundary if it is less than 8 bytes away. @item -malign-jumps=@var{num} Align instructions that are only jumped to to a 2 raised to a @var{num} byte boundary. If @samp{-malign-jumps} is not specified, the default is 2 if optimizing for a 386, and 4 if optimizing for a 486 unless gas 2.8 (or later) is being used in which case the default is to align the instruction on a 16 byte boundary if it is less than 8 bytes away. @item -malign-functions=@var{num} Align the start of functions to a 2 raised to @var{num} byte boundary. If @samp{-malign-functions} is not specified, the default is 2 if optimizing for a 386, and 4 if optimizing for a 486. @item -mpreferred-stack-boundary=@var{num} Attempt to keep the stack boundary aligned to a 2 raised to @var{num} byte boundary. If @samp{-mpreferred-stack-boundary} is not specified, the default is 4 (16 bytes or 128 bits). The stack is required to be aligned on a 4 byte boundary. On Pentium and PentiumPro, @code{double} and @code{long double} values should be aligned to an 8 byte boundary (see @samp{-malign-double}) or suffer significant run time performance penalties. On Pentium III, the Streaming SIMD Extention (SSE) data type @code{__m128} suffers similar penalties if it is not 16 byte aligned. To ensure proper alignment of this values on the stack, the stack boundary must be as aligned as that required by any value stored on the stack. Further, every function must be generated such that it keeps the stack aligned. Thus calling a function compiled with a higher preferred stack boundary from a function compiled with a lower preferred stack boundary will most likely misalign the stack. It is recommended that libraries that use callbacks always use the default setting. This extra alignment does consume extra stack space. Code that is sensitive to stack space usage, such as embedded systems and operating system kernels, may want to reduce the preferred alignment to @samp{-mpreferred-stack-boundary=2}. @end table @node HPPA Options @subsection HPPA Options @cindex HPPA Options These @samp{-m} options are defined for the HPPA family of computers: @table @code @item -march=@var{architecture type} Generate code for the specified architecture. The choices for @var{architecture type} are @samp{1.0} for PA 1.0, @samp{1.1} for PA 1.1, and @samp{2.0} for PA 2.0 processors. Refer to @file{/usr/lib/sched.models} on an HP-UX system to determine the proper architecture option for your machine. Code compiled for lower numbered architectures will run on higher numbered architectures, but not the other way around. PA 2.0 support currently requires gas snapshot 19990413 or later. The next release of binutils (current is 2.9.1) will probably contain PA 2.0 support. @item -mpa-risc-1-0 @itemx -mpa-risc-1-1 @itemx -mpa-risc-2-0 Synonyms for -march=1.0, -march=1.1, and -march=2.0 respectively. @item -mbig-switch Generate code suitable for big switch tables. Use this option only if the assembler/linker complain about out of range branches within a switch table. @item -mjump-in-delay Fill delay slots of function calls with unconditional jump instructions by modifying the return pointer for the function call to be the target of the conditional jump. @item -mdisable-fpregs Prevent floating point registers from being used in any manner. This is necessary for compiling kernels which perform lazy context switching of floating point registers. If you use this option and attempt to perform floating point operations, the compiler will abort. @item -mdisable-indexing Prevent the compiler from using indexing address modes. This avoids some rather obscure problems when compiling MIG generated code under MACH. @item -mno-space-regs Generate code that assumes the target has no space registers. This allows GCC to generate faster indirect calls and use unscaled index address modes. Such code is suitable for level 0 PA systems and kernels. @item -mfast-indirect-calls Generate code that assumes calls never cross space boundaries. This allows GCC to emit code which performs faster indirect calls. This option will not work in the presense of shared libraries or nested functions. @item -mspace Optimize for space rather than execution time. Currently this only enables out of line function prologues and epilogues. This option is incompatible with PIC code generation and profiling. @item -mlong-load-store Generate 3-instruction load and store sequences as sometimes required by the HP-UX 10 linker. This is equivalent to the @samp{+k} option to the HP compilers. @item -mportable-runtime Use the portable calling conventions proposed by HP for ELF systems. @item -mgas Enable the use of assembler directives only GAS understands. @item -mschedule=@var{cpu type} Schedule code according to the constraints for the machine type @var{cpu type}. The choices for @var{cpu type} are @samp{700} @samp{7100}, @samp{7100LC}, @samp{7200}, and @samp{8000}. Refer to @file{/usr/lib/sched.models} on an HP-UX system to determine the proper scheduling option for your machine. @item -mlinker-opt Enable the optimization pass in the HPUX linker. Note this makes symbolic debugging impossible. It also triggers a bug in the HPUX 8 and HPUX 9 linkers in which they give bogus error messages when linking some programs. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries are not available for all HPPA targets. Normally the facilities of the machine's usual C compiler are used, but this cannot be done directly in cross-compilation. You must make your own arrangements to provide suitable library functions for cross-compilation. The embedded target @samp{hppa1.1-*-pro} does provide software floating point support. @samp{-msoft-float} changes the calling convention in the output file; therefore, it is only useful if you compile @emph{all} of a program with this option. In particular, you need to compile @file{libgcc.a}, the library that comes with GCC, with @samp{-msoft-float} in order for this to work. @end table @node Intel 960 Options @subsection Intel 960 Options These @samp{-m} options are defined for the Intel 960 implementations: @table @code @item -m@var{cpu type} Assume the defaults for the machine type @var{cpu type} for some of the other options, including instruction scheduling, floating point support, and addressing modes. The choices for @var{cpu type} are @samp{ka}, @samp{kb}, @samp{mc}, @samp{ca}, @samp{cf}, @samp{sa}, and @samp{sb}. The default is @samp{kb}. @item -mnumerics @itemx -msoft-float The @samp{-mnumerics} option indicates that the processor does support floating-point instructions. The @samp{-msoft-float} option indicates that floating-point support should not be assumed. @item -mleaf-procedures @itemx -mno-leaf-procedures Do (or do not) attempt to alter leaf procedures to be callable with the @code{bal} instruction as well as @code{call}. This will result in more efficient code for explicit calls when the @code{bal} instruction can be substituted by the assembler or linker, but less efficient code in other cases, such as calls via function pointers, or using a linker that doesn't support this optimization. @item -mtail-call @itemx -mno-tail-call Do (or do not) make additional attempts (beyond those of the machine-independent portions of the compiler) to optimize tail-recursive calls into branches. You may not want to do this because the detection of cases where this is not valid is not totally complete. The default is @samp{-mno-tail-call}. @item -mcomplex-addr @itemx -mno-complex-addr Assume (or do not assume) that the use of a complex addressing mode is a win on this implementation of the i960. Complex addressing modes may not be worthwhile on the K-series, but they definitely are on the C-series. The default is currently @samp{-mcomplex-addr} for all processors except the CB and CC. @item -mcode-align @itemx -mno-code-align Align code to 8-byte boundaries for faster fetching (or don't bother). Currently turned on by default for C-series implementations only. @ignore @item -mclean-linkage @itemx -mno-clean-linkage These options are not fully implemented. @end ignore @item -mic-compat @itemx -mic2.0-compat @itemx -mic3.0-compat Enable compatibility with iC960 v2.0 or v3.0. @item -masm-compat @itemx -mintel-asm Enable compatibility with the iC960 assembler. @item -mstrict-align @itemx -mno-strict-align Do not permit (do permit) unaligned accesses. @item -mold-align Enable structure-alignment compatibility with Intel's gcc release version 1.3 (based on gcc 1.37). This option implies @samp{-mstrict-align}. @item -mlong-double-64 Implement type @samp{long double} as 64-bit floating point numbers. Without the option @samp{long double} is implemented by 80-bit floating point numbers. The only reason we have it because there is no 128-bit @samp{long double} support in @samp{fp-bit.c} yet. So it is only useful for people using soft-float targets. Otherwise, we should recommend against use of it. @end table @node DEC Alpha Options @subsection DEC Alpha Options These @samp{-m} options are defined for the DEC Alpha implementations: @table @code @item -mno-soft-float @itemx -msoft-float Use (do not use) the hardware floating-point instructions for floating-point operations. When @code{-msoft-float} is specified, functions in @file{libgcc1.c} will be used to perform floating-point operations. Unless they are replaced by routines that emulate the floating-point operations, or compiled in such a way as to call such emulations routines, these routines will issue floating-point operations. If you are compiling for an Alpha without floating-point operations, you must ensure that the library is built so as not to call them. Note that Alpha implementations without floating-point operations are required to have floating-point registers. @item -mfp-reg @itemx -mno-fp-regs Generate code that uses (does not use) the floating-point register set. @code{-mno-fp-regs} implies @code{-msoft-float}. If the floating-point register set is not used, floating point operands are passed in integer registers as if they were integers and floating-point results are passed in $0 instead of $f0. This is a non-standard calling sequence, so any function with a floating-point argument or return value called by code compiled with @code{-mno-fp-regs} must also be compiled with that option. A typical use of this option is building a kernel that does not use, and hence need not save and restore, any floating-point registers. @item -mieee The Alpha architecture implements floating-point hardware optimized for maximum performance. It is mostly compliant with the IEEE floating point standard. However, for full compliance, software assistance is required. This option generates code fully IEEE compliant code @emph{except} that the @var{inexact flag} is not maintained (see below). If this option is turned on, the CPP macro @code{_IEEE_FP} is defined during compilation. The option is a shorthand for: @samp{-D_IEEE_FP -mfp-trap-mode=su -mtrap-precision=i -mieee-conformant}. The resulting code is less efficient but is able to correctly support denormalized numbers and exceptional IEEE values such as not-a-number and plus/minus infinity. Other Alpha compilers call this option @code{-ieee_with_no_inexact}. @item -mieee-with-inexact @c overfull hbox here --bob 22 jul96 @c original text between ignore ... end ignore @ignore This is like @samp{-mieee} except the generated code also maintains the IEEE @var{inexact flag}. Turning on this option causes the generated code to implement fully-compliant IEEE math. The option is a shorthand for @samp{-D_IEEE_FP -D_IEEE_FP_INEXACT} plus @samp{-mieee-conformant}, @samp{-mfp-trap-mode=sui}, and @samp{-mtrap-precision=i}. On some Alpha implementations the resulting code may execute significantly slower than the code generated by default. Since there is very little code that depends on the @var{inexact flag}, you should normally not specify this option. Other Alpha compilers call this option @samp{-ieee_with_inexact}. @end ignore @c changed paragraph This is like @samp{-mieee} except the generated code also maintains the IEEE @var{inexact flag}. Turning on this option causes the generated code to implement fully-compliant IEEE math. The option is a shorthand for @samp{-D_IEEE_FP -D_IEEE_FP_INEXACT} plus the three following: @samp{-mieee-conformant}, @samp{-mfp-trap-mode=sui}, and @samp{-mtrap-precision=i}. On some Alpha implementations the resulting code may execute significantly slower than the code generated by default. Since there is very little code that depends on the @var{inexact flag}, you should normally not specify this option. Other Alpha compilers call this option @samp{-ieee_with_inexact}. @c end changes to prevent overfull hboxes @item -mfp-trap-mode=@var{trap mode} This option controls what floating-point related traps are enabled. Other Alpha compilers call this option @samp{-fptm }@var{trap mode}. The trap mode can be set to one of four values: @table @samp @item n This is the default (normal) setting. The only traps that are enabled are the ones that cannot be disabled in software (e.g., division by zero trap). @item u In addition to the traps enabled by @samp{n}, underflow traps are enabled as well. @item su Like @samp{su}, but the instructions are marked to be safe for software completion (see Alpha architecture manual for details). @item sui Like @samp{su}, but inexact traps are enabled as well. @end table @item -mfp-rounding-mode=@var{rounding mode} Selects the IEEE rounding mode. Other Alpha compilers call this option @samp{-fprm }@var{rounding mode}. The @var{rounding mode} can be one of: @table @samp @item n Normal IEEE rounding mode. Floating point numbers are rounded towards the nearest machine number or towards the even machine number in case of a tie. @item m Round towards minus infinity. @item c Chopped rounding mode. Floating point numbers are rounded towards zero. @item d Dynamic rounding mode. A field in the floating point control register (@var{fpcr}, see Alpha architecture reference manual) controls the rounding mode in effect. The C library initializes this register for rounding towards plus infinity. Thus, unless your program modifies the @var{fpcr}, @samp{d} corresponds to round towards plus infinity. @end table @item -mtrap-precision=@var{trap precision} In the Alpha architecture, floating point traps are imprecise. This means without software assistance it is impossible to recover from a floating trap and program execution normally needs to be terminated. GCC can generate code that can assist operating system trap handlers in determining the exact location that caused a floating point trap. Depending on the requirements of an application, different levels of precisions can be selected: @table @samp @item p Program precision. This option is the default and means a trap handler can only identify which program caused a floating point exception. @item f Function precision. The trap handler can determine the function that caused a floating point exception. @item i Instruction precision. The trap handler can determine the exact instruction that caused a floating point exception. @end table Other Alpha compilers provide the equivalent options called @samp{-scope_safe} and @samp{-resumption_safe}. @item -mieee-conformant This option marks the generated code as IEEE conformant. You must not use this option unless you also specify @samp{-mtrap-precision=i} and either @samp{-mfp-trap-mode=su} or @samp{-mfp-trap-mode=sui}. Its only effect is to emit the line @samp{.eflag 48} in the function prologue of the generated assembly file. Under DEC Unix, this has the effect that IEEE-conformant math library routines will be linked in. @item -mbuild-constants Normally GCC examines a 32- or 64-bit integer constant to see if it can construct it from smaller constants in two or three instructions. If it cannot, it will output the constant as a literal and generate code to load it from the data segment at runtime. Use this option to require GCC to construct @emph{all} integer constants using code, even if it takes more instructions (the maximum is six). You would typically use this option to build a shared library dynamic loader. Itself a shared library, it must relocate itself in memory before it can find the variables and constants in its own data segment. @item -malpha-as @itemx -mgas Select whether to generate code to be assembled by the vendor-supplied assembler (@samp{-malpha-as}) or by the GNU assembler @samp{-mgas}. @item -mbwx @itemx -mno-bwx @itemx -mcix @itemx -mno-cix @itemx -mmax @itemx -mno-max Indicate whether GCC should generate code to use the optional BWX, CIX, and MAX instruction sets. The default is to use the instruction sets supported by the CPU type specified via @samp{-mcpu=} option or that of the CPU on which GCC was built if none was specified. @item -mcpu=@var{cpu_type} Set the instruction set, register set, and instruction scheduling parameters for machine type @var{cpu_type}. You can specify either the @samp{EV} style name or the corresponding chip number. GCC supports scheduling parameters for the EV4 and EV5 family of processors and will choose the default values for the instruction set from the processor you specify. If you do not specify a processor type, GCC will default to the processor on which the compiler was built. Supported values for @var{cpu_type} are @table @samp @item ev4 @itemx 21064 Schedules as an EV4 and has no instruction set extensions. @item ev5 @itemx 21164 Schedules as an EV5 and has no instruction set extensions. @item ev56 @itemx 21164a Schedules as an EV5 and supports the BWX extension. @item pca56 @itemx 21164pc @itemx 21164PC Schedules as an EV5 and supports the BWX and MAX extensions. @item ev6 @itemx 21264 Schedules as an EV5 (until Digital releases the scheduling parameters for the EV6) and supports the BWX, CIX, and MAX extensions. @end table @item -mmemory-latency=@var{time} Sets the latency the scheduler should assume for typical memory references as seen by the application. This number is highly dependant on the memory access patterns used by the application and the size of the external cache on the machine. Valid options for @var{time} are @table @samp @item @var{number} A decimal number representing clock cycles. @item L1 @itemx L2 @itemx L3 @itemx main The compiler contains estimates of the number of clock cycles for ``typical'' EV4 & EV5 hardware for the Level 1, 2 & 3 caches (also called Dcache, Scache, and Bcache), as well as to main memory. Note that L3 is only valid for EV5. @end table @end table @node Clipper Options @subsection Clipper Options These @samp{-m} options are defined for the Clipper implementations: @table @code @item -mc300 Produce code for a C300 Clipper processor. This is the default. @item -mc400 Produce code for a C400 Clipper processor i.e. use floating point registers f8..f15. @end table @node H8/300 Options @subsection H8/300 Options These @samp{-m} options are defined for the H8/300 implementations: @table @code @item -mrelax Shorten some address references at link time, when possible; uses the linker option @samp{-relax}. @xref{H8/300,, @code{ld} and the H8/300, ld.info, Using ld}, for a fuller description. @item -mh Generate code for the H8/300H. @item -ms Generate code for the H8/S. @item -mint32 Make @code{int} data 32 bits by default. @item -malign-300 On the h8/300h, use the same alignment rules as for the h8/300. The default for the h8/300h is to align longs and floats on 4 byte boundaries. @samp{-malign-300} causes them to be aligned on 2 byte boundaries. This option has no effect on the h8/300. @end table @node SH Options @subsection SH Options These @samp{-m} options are defined for the SH implementations: @table @code @item -m1 Generate code for the SH1. @item -m2 Generate code for the SH2. @item -m3 Generate code for the SH3. @item -m3e Generate code for the SH3e. @item -mb Compile code for the processor in big endian mode. @item -ml Compile code for the processor in little endian mode. @item -mdalign Align doubles at 64 bit boundaries. Note that this changes the calling conventions, and thus some functions from the standard C library will not work unless you recompile it first with -mdalign. @item -mrelax Shorten some address references at link time, when possible; uses the linker option @samp{-relax}. @end table @node System V Options @subsection Options for System V These additional options are available on System V Release 4 for compatibility with other compilers on those systems: @table @code @item -G Create a shared object. It is recommended that @samp{-symbolic} or @samp{-shared} be used instead. @item -Qy Identify the versions of each tool used by the compiler, in a @code{.ident} assembler directive in the output. @item -Qn Refrain from adding @code{.ident} directives to the output file (this is the default). @item -YP,@var{dirs} Search the directories @var{dirs}, and no others, for libraries specified with @samp{-l}. @item -Ym,@var{dir} Look in the directory @var{dir} to find the M4 preprocessor. The assembler uses this option. @c This is supposed to go with a -Yd for predefined M4 macro files, but @c the generic assembler that comes with Solaris takes just -Ym. @end table @node TMS320C3x/C4x Options @subsection TMS320C3x/C4x Options @cindex TMS320C3x/C4x Options These @samp{-m} options are defined for TMS320C3x/C4x implementations: @table @code @item -mcpu=@var{cpu_type} Set the instruction set, register set, and instruction scheduling parameters for machine type @var{cpu_type}. Supported values for @var{cpu_type} are @samp{c30}, @samp{c31}, @samp{c32}, @samp{c40}, and @samp{c44}. The default is @samp{c40} to generate code for the TMS320C40. @item -mbig-memory @item -mbig @itemx -msmall-memory @itemx -msmall Generates code for the big or small memory model. The small memory model assumed that all data fits into one 64K word page. At run-time the data page (DP) register must be set to point to the 64K page containing the .bss and .data program sections. The big memory model is the default and requires reloading of the DP register for every direct memory access. @item -mbk @itemx -mno-bk Allow (disallow) allocation of general integer operands into the block count register BK. @item -mdb @itemx -mno-db Enable (disable) generation of code using decrement and branch, DBcond(D), instructions. This is enabled by default for the C4x. To be on the safe side, this is disabled for the C3x, since the maximum iteration count on the C3x is 2^23 + 1 (but who iterates loops more than 2^23 times on the C3x?). Note that GCC will try to reverse a loop so that it can utilise the decrement and branch instruction, but will give up if there is more than one memory reference in the loop. Thus a loop where the loop counter is decremented can generate slightly more efficient code, in cases where the RPTB instruction cannot be utilised. @item -mdp-isr-reload @itemx -mparanoid Force the DP register to be saved on entry to an interrupt service routine (ISR), reloaded to point to the data section, and restored on exit from the ISR. This should not be required unless someone has violated the small memory model by modifying the DP register, say within an object library. @item -mmpyi @itemx -mno-mpyi For the C3x use the 24-bit MPYI instruction for integer multiplies instead of a library call to guarantee 32-bit results. Note that if one of the operands is a constant, then the multiplication will be performed using shifts and adds. If the -mmpyi option is not specified for the C3x, then squaring operations are performed inline instead of a library call. @item -mfast-fix @itemx -mno-fast-fix The C3x/C4x FIX instruction to convert a floating point value to an integer value chooses the nearest integer less than or equal to the floating point value rather than to the nearest integer. Thus if the floating point number is negative, the result will be incorrectly truncated an additional code is necessary to detect and correct this case. This option can be used to disable generation of the additional code required to correct the result. @item -mrptb @itemx -mno-rptb Enable (disable) generation of repeat block sequences using the RPTB instruction for zero overhead looping. The RPTB construct is only used for innermost loops that do not call functions or jump across the loop boundaries. There is no advantage having nested RPTB loops due to the overhead required to save and restore the RC, RS, and RE registers. This is enabled by default with -O2. @item -mrpts=@var{count} @itemx -mno-rpts Enable (disable) the use of the single instruction repeat instruction RPTS. If a repeat block contains a single instruction, and the loop count can be guaranteed to be less than the value @var{count}, GCC will emit a RPTS instruction instead of a RPTB. If no value is specified, then a RPTS will be emitted even if the loop count cannot be determined at compile time. Note that the repeated instruction following RPTS does not have to be reloaded from memory each iteration, thus freeing up the CPU buses for oeprands. However, since interrupts are blocked by this instruction, it is disabled by default. @item -mloop-unsigned @itemx -mno-loop-unsigned The maximum iteration count when using RPTS and RPTB (and DB on the C40) is 2^31 + 1 since these instructions test if the iteration count is negative to terminate the loop. If the iteration count is unsigned there is a possibility than the 2^31 + 1 maximum iteration count may be exceeded. This switch allows an unsigned iteration count. @item -mti Try to emit an assembler syntax that the TI assembler (asm30) is happy with. This also enforces compatibility with the API employed by the TI C3x C compiler. For example, long doubles are passed as structures rather than in floating point registers. @item -mregparm @itemx -mmemparm Generate code that uses registers (stack) for passing arguments to functions. By default, arguments are passed in registers where possible rather than by pushing arguments on to the stack. @item -mparallel-insns @itemx -mno-parallel-insns Allow the generation of parallel instructions. This is enabled by default with -O2. @item -mparallel-mpy @itemx -mno-parallel-mpy Allow the generation of MPY||ADD and MPY||SUB parallel instructions, provided -mparallel-insns is also specified. These instructions have tight register constraints which can pessimize the code generation of large functions. @end table @node V850 Options @subsection V850 Options @cindex V850 Options These @samp{-m} options are defined for V850 implementations: @table @code @item -mlong-calls @itemx -mno-long-calls Treat all calls as being far away (near). If calls are assumed to be far away, the compiler will always load the functions address up into a register, and call indirect through the pointer. @item -mno-ep @itemx -mep Do not optimize (do optimize) basic blocks that use the same index pointer 4 or more times to copy pointer into the @code{ep} register, and use the shorter @code{sld} and @code{sst} instructions. The @samp{-mep} option is on by default if you optimize. @item -mno-prolog-function @itemx -mprolog-function Do not use (do use) external functions to save and restore registers at the prolog and epilog of a function. The external functions are slower, but use less code space if more than one function saves the same number of registers. The @samp{-mprolog-function} option is on by default if you optimize. @item -mspace Try to make the code as small as possible. At present, this just turns on the @samp{-mep} and @samp{-mprolog-function} options. @item -mtda=@var{n} Put static or global variables whose size is @var{n} bytes or less into the tiny data area that register @code{ep} points to. The tiny data area can hold up to 256 bytes in total (128 bytes for byte references). @item -msda=@var{n} Put static or global variables whose size is @var{n} bytes or less into the small data area that register @code{gp} points to. The small data area can hold up to 64 kilobytes. @item -mzda=@var{n} Put static or global variables whose size is @var{n} bytes or less into the first 32 kilobytes of memory. @item -mv850 Specify that the target processor is the V850. @item -mbig-switch Generate code suitable for big switch tables. Use this option only if the assembler/linker complain about out of range branches within a switch table. @end table @node ARC Options @subsection ARC Options @cindex ARC Options These options are defined for ARC implementations: @table @code @item -EL Compile code for little endian mode. This is the default. @item -EB Compile code for big endian mode. @item -mmangle-cpu Prepend the name of the cpu to all public symbol names. In multiple-processor systems, there are many ARC variants with different instruction and register set characteristics. This flag prevents code compiled for one cpu to be linked with code compiled for another. No facility exists for handling variants that are "almost identical". This is an all or nothing option. @item -mcpu=@var{cpu} Compile code for ARC variant @var{cpu}. Which variants are supported depend on the configuration. All variants support @samp{-mcpu=base}, this is the default. @item -mtext=@var{text section} @itemx -mdata=@var{data section} @itemx -mrodata=@var{readonly data section} Put functions, data, and readonly data in @var{text section}, @var{data section}, and @var{readonly data section} respectively by default. This can be overridden with the @code{section} attribute. @xref{Variable Attributes}. @end table @node NS32K Options @subsection NS32K Options @cindex NS32K options These are the @samp{-m} options defined for the 32000 series. The default values for these options depends on which style of 32000 was selected when the compiler was configured; the defaults for the most common choices are given below. @table @code @item -m32032 @itemx -m32032 Generate output for a 32032. This is the default when the compiler is configured for 32032 and 32016 based systems. @item -m32332 @itemx -m32332 Generate output for a 32332. This is the default when the compiler is configured for 32332-based systems. @item -m32532 @itemx -m32532 Generate output for a 32532. This is the default when the compiler is configured for 32532-based systems. @item -m32081 Generate output containing 32081 instructions for floating point. This is the default for all systems. @item -m32381 Generate output containing 32381 instructions for floating point. This also implies @samp{-m32081}. The 32381 is only compatible with the 32332 and 32532 cpus. This is the default for the pc532-netbsd configuration. @item -mmulti-add Try and generate multiply-add floating point instructions @code{polyF} and @code{dotF}. This option is only available if the @samp{-m32381} option is in effect. Using these instructions requires changes to to register allocation which generally has a negative impact on performance. This option should only be enabled when compiling code particularly likely to make heavy use of multiply-add instructions. @item -mnomulti-add Do not try and generate multiply-add floating point instructions @code{polyF} and @code{dotF}. This is the default on all platforms. @item -msoft-float Generate output containing library calls for floating point. @strong{Warning:} the requisite libraries may not be available. @item -mnobitfield Do not use the bit-field instructions. On some machines it is faster to use shifting and masking operations. This is the default for the pc532. @item -mbitfield Do use the bit-field instructions. This is the default for all platforms except the pc532. @item -mrtd Use a different function-calling convention, in which functions that take a fixed number of arguments return pop their arguments on return with the @code{ret} instruction. This calling convention is incompatible with the one normally used on Unix, so you cannot use it if you need to call libraries compiled with the Unix compiler. Also, you must provide function prototypes for all functions that take variable numbers of arguments (including @code{printf}); otherwise incorrect code will be generated for calls to those functions. In addition, seriously incorrect code will result if you call a function with too many arguments. (Normally, extra arguments are harmlessly ignored.) This option takes its name from the 680x0 @code{rtd} instruction. @item -mregparam Use a different function-calling convention where the first two arguments are passed in registers. This calling convention is incompatible with the one normally used on Unix, so you cannot use it if you need to call libraries compiled with the Unix compiler. @item -mnoregparam Do not pass any arguments in registers. This is the default for all targets. @item -msb It is OK to use the sb as an index register which is always loaded with zero. This is the default for the pc532-netbsd target. @item -mnosb The sb register is not available for use or has not been initialized to zero by the run time system. This is the default for all targets except the pc532-netbsd. It is also implied whenever @samp{-mhimem} or @samp{-fpic} is set. @item -mhimem Many ns32000 series addressing modes use displacements of up to 512MB. If an address is above 512MB then displacements from zero can not be used. This option causes code to be generated which can be loaded above 512MB. This may be useful for operating systems or ROM code. @item -mnohimem Assume code will be loaded in the first 512MB of virtual address space. This is the default for all platforms. @end table @node Code Gen Options @section Options for Code Generation Conventions @cindex code generation conventions @cindex options, code generation @cindex run-time options These machine-independent options control the interface conventions used in code generation. Most of them have both positive and negative forms; the negative form of @samp{-ffoo} would be @samp{-fno-foo}. In the table below, only one of the forms is listed---the one which is not the default. You can figure out the other form by either removing @samp{no-} or adding it. @table @code @item -fexceptions Enable exception handling. Generates extra code needed to propagate exceptions. For some targets, this implies generation of frame unwind information for all functions. This can produce significant data size overhead, although it does not affect execution. If you do not specify this option, it is enabled by default for languages like C++ which normally require exception handling, and disabled for languages like C that do not normally require it. However, when compiling C code that needs to interoperate properly with exception handlers written in C++, you may need to enable this option. You may also wish to disable this option is you are compiling older C++ programs that don't use exception handling. @item -fpcc-struct-return Return ``short'' @code{struct} and @code{union} values in memory like longer ones, rather than in registers. This convention is less efficient, but it has the advantage of allowing intercallability between GCC-compiled files and files compiled with other compilers. The precise convention for returning structures in memory depends on the target configuration macros. Short structures and unions are those whose size and alignment match that of some integer type. @item -freg-struct-return Use the convention that @code{struct} and @code{union} values are returned in registers when possible. This is more efficient for small structures than @samp{-fpcc-struct-return}. If you specify neither @samp{-fpcc-struct-return} nor its contrary @samp{-freg-struct-return}, GCC defaults to whichever convention is standard for the target. If there is no standard convention, GCC defaults to @samp{-fpcc-struct-return}, except on targets where GCC is the principal compiler. In those cases, we can choose the standard, and we chose the more efficient register return alternative. @item -fshort-enums Allocate to an @code{enum} type only as many bytes as it needs for the declared range of possible values. Specifically, the @code{enum} type will be equivalent to the smallest integer type which has enough room. @item -fshort-double Use the same size for @code{double} as for @code{float}. @item -fshared-data Requests that the data and non-@code{const} variables of this compilation be shared data rather than private data. The distinction makes sense only on certain operating systems, where shared data is shared between processes running the same program, while private data exists in one copy per process. @item -fno-common Allocate even uninitialized global variables in the bss section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without @code{extern}) in two different compilations, you will get an error when you link them. The only reason this might be useful is if you wish to verify that the program will work on other systems which always work this way. @item -fno-ident Ignore the @samp{#ident} directive. @item -fno-gnu-linker Do not output global initializations (such as C++ constructors and destructors) in the form used by the GNU linker (on systems where the GNU linker is the standard method of handling them). Use this option when you want to use a non-GNU linker, which also requires using the @code{collect2} program to make sure the system linker includes constructors and destructors. (@code{collect2} is included in the GCC distribution.) For systems which @emph{must} use @code{collect2}, the compiler driver @code{gcc} is configured to do this automatically. @item -finhibit-size-directive Don't output a @code{.size} assembler directive, or anything else that would cause trouble if the function is split in the middle, and the two halves are placed at locations far apart in memory. This option is used when compiling @file{crtstuff.c}; you should not need to use it for anything else. @item -fverbose-asm Put extra commentary information in the generated assembly code to make it more readable. This option is generally only of use to those who actually need to read the generated assembly code (perhaps while debugging the compiler itself). @samp{-fno-verbose-asm}, the default, causes the extra information to be omitted and is useful when comparing two assembler files. @item -fvolatile Consider all memory references through pointers to be volatile. @item -fvolatile-global Consider all memory references to extern and global data items to be volatile. GCC does not consider static data items to be volatile because of this switch. @item -fvolatile-static Consider all memory references to static data to be volatile. @item -fpic @cindex global offset table @cindex PIC Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that @samp{-fpic} does not work; in that case, recompile with @samp{-fPIC} instead. (These maximums are 16k on the m88k, 8k on the Sparc, and 32k on the m68k and RS/6000. The 386 has no such limit.) Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent. @item -fPIC If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k, m88k, and the Sparc. Position-independent code requires special support, and therefore works only on certain machines. @item -ffixed-@var{reg} Treat the register named @var{reg} as a fixed register; generated code should never refer to it (except perhaps as a stack pointer, frame pointer or in some other fixed role). @var{reg} must be the name of a register. The register names accepted are machine-specific and are defined in the @code{REGISTER_NAMES} macro in the machine description macro file. This flag does not have a negative form, because it specifies a three-way choice. @item -fcall-used-@var{reg} Treat the register named @var{reg} as an allocable register that is clobbered by function calls. It may be allocated for temporaries or variables that do not live across a call. Functions compiled this way will not save and restore the register @var{reg}. It is an error to used this flag with the frame pointer or stack pointer. Use of this flag for other registers that have fixed pervasive roles in the machine's execution model will produce disastrous results. This flag does not have a negative form, because it specifies a three-way choice. @item -fcall-saved-@var{reg} Treat the register named @var{reg} as an allocable register saved by functions. It may be allocated even for temporaries or variables that live across a call. Functions compiled this way will save and restore the register @var{reg} if they use it. It is an error to used this flag with the frame pointer or stack pointer. Use of this flag for other registers that have fixed pervasive roles in the machine's execution model will produce disastrous results. A different sort of disaster will result from the use of this flag for a register in which function values may be returned. This flag does not have a negative form, because it specifies a three-way choice. @item -fpack-struct Pack all structure members together without holes. Usually you would not want to use this option, since it makes the code suboptimal, and the offsets of structure members won't agree with system libraries. @item -fcheck-memory-usage Generate extra code to check each memory access. GCC will generate code that is suitable for a detector of bad memory accesses such as @file{Checker}. Normally, you should compile all, or none, of your code with this option. If you do mix code compiled with and without this option, you must ensure that all code that has side effects and that is called by code compiled with this option is, itself, compiled with this option. If you do not, you might get erroneous messages from the detector. If you use functions from a library that have side-effects (such as @code{read}), you might not be able to recompile the library and specify this option. In that case, you can enable the @samp{-fprefix-function-name} option, which requests GCC to encapsulate your code and make other functions look as if they were compiled with @samp{-fcheck-memory-usage}. This is done by calling ``stubs'', which are provided by the detector. If you cannot find or build stubs for every function you call, you might have to specify @samp{-fcheck-memory-usage} without @samp{-fprefix-function-name}. If you specify this option, you can not use the @code{asm} or @code{__asm__} keywords in functions with memory checking enabled. The compiler cannot understand what the @code{asm} statement will do, and therefore cannot generate the appropriate code, so it is rejected. However, the function attribute @code{no_check_memory_usage} will disable memory checking within a function, and @code{asm} statements can be put inside such functions. Inline expansion of a non-checked function within a checked function is permitted; the inline function's memory accesses won't be checked, but the rest will. If you move your @code{asm} statements to non-checked inline functions, but they do access memory, you can add calls to the support code in your inline function, to indicate any reads, writes, or copies being done. These calls would be similar to those done in the stubs described above. @c FIXME: The support-routine interface is defined by the compiler and @c should be documented! @item -fprefix-function-name Request GCC to add a prefix to the symbols generated for function names. GCC adds a prefix to the names of functions defined as well as functions called. Code compiled with this option and code compiled without the option can't be linked together, unless stubs are used. If you compile the following code with @samp{-fprefix-function-name} @example extern void bar (int); void foo (int a) @{ return bar (a + 5); @} @end example @noindent GCC will compile the code as if it was written: @example extern void prefix_bar (int); void prefix_foo (int a) @{ return prefix_bar (a + 5); @} @end example This option is designed to be used with @samp{-fcheck-memory-usage}. @item -finstrument-functions Generate instrumentation calls for entry and exit to functions. Just after function entry and just before function exit, the following profiling functions will be called with the address of the current function and its call site. (On some platforms, @code{__builtin_return_address} does not work beyond the current function, so the call site information may not be available to the profiling functions otherwise.) @example void __cyg_profile_func_enter (void *this_fn, void *call_site); void __cyg_profile_func_exit (void *this_fn, void *call_site); @end example The first argument is the address of the start of the current function, which may be looked up exactly in the symbol table. This instrumentation is also done for functions expanded inline in other functions. The profiling calls will indicate where, conceptually, the inline function is entered and exited. This means that addressable versions of such functions must be available. If all your uses of a function are expanded inline, this may mean an additional expansion of code size. If you use @samp{extern inline} in your C code, an addressable version of such functions must be provided. (This is normally the case anyways, but if you get lucky and the optimizer always expands the functions inline, you might have gotten away without providing static copies.) A function may be given the attribute @code{no_instrument_function}, in which case this instrumentation will not be done. This can be used, for example, for the profiling functions listed above, high-priority interrupt routines, and any functions from which the profiling functions cannot safely be called (perhaps signal handlers, if the profiling routines generate output or allocate memory). @item -fstack-check Generate code to verify that you do not go beyond the boundary of the stack. You should specify this flag if you are running in an environment with multiple threads, but only rarely need to specify it in a single-threaded environment since stack overflow is automatically detected on nearly all systems if there is only one stack. @cindex aliasing of parameters @cindex parameters, aliased @item -fargument-alias @itemx -fargument-noalias @itemx -fargument-noalias-global Specify the possible relationships among parameters and between parameters and global data. @samp{-fargument-alias} specifies that arguments (parameters) may alias each other and may alias global storage. @samp{-fargument-noalias} specifies that arguments do not alias each other, but may alias global storage. @samp{-fargument-noalias-global} specifies that arguments do not alias each other and do not alias global storage. Each language will automatically use whatever option is required by the language standard. You should not need to use these options yourself. @item -fleading-underscore This option and its counterpart, -fno-leading-underscore, forcibly change the way C symbols are represented in the object file. One use is to help link with legacy assembly code. Be warned that you should know what you are doing when invoking this option, and that not all targets provide complete support for it. @end table @node Environment Variables @section Environment Variables Affecting GCC @cindex environment variables This section describes several environment variables that affect how GCC operates. Some of them work by specifying directories or prefixes to use when searching for various kinds of files. Some are used to specify other aspects of the compilation environment. @ifclear INTERNALS Note that you can also specify places to search using options such as @samp{-B}, @samp{-I} and @samp{-L} (@pxref{Directory Options}). These take precedence over places specified using environment variables, which in turn take precedence over those specified by the configuration of GCC. @end ifclear @ifset INTERNALS Note that you can also specify places to search using options such as @samp{-B}, @samp{-I} and @samp{-L} (@pxref{Directory Options}). These take precedence over places specified using environment variables, which in turn take precedence over those specified by the configuration of GCC. @xref{Driver}. @end ifset @table @code @item LANG @itemx LC_CTYPE @c @itemx LC_COLLATE @itemx LC_MESSAGES @c @itemx LC_MONETARY @c @itemx LC_NUMERIC @c @itemx LC_TIME @itemx LC_ALL @findex LANG @findex LC_CTYPE @c @findex LC_COLLATE @findex LC_MESSAGES @c @findex LC_MONETARY @c @findex LC_NUMERIC @c @findex LC_TIME @findex LC_ALL @cindex locale These environment variables control the way that GCC uses localization information that allow GCC to work with different national conventions. GCC inspects the locale categories @code{LC_CTYPE} and @code{LC_MESSAGES} if it has been configured to do so. These locale categories can be set to any value supported by your installation. A typical value is @samp{en_UK} for English in the United Kingdom. The @code{LC_CTYPE} environment variable specifies character classification. GCC uses it to determine the character boundaries in a string; this is needed for some multibyte encodings that contain quote and escape characters that would otherwise be interpreted as a string end or escape. The @code{LC_MESSAGES} environment variable specifies the language to use in diagnostic messages. If the @code{LC_ALL} environment variable is set, it overrides the value of @code{LC_CTYPE} and @code{LC_MESSAGES}; otherwise, @code{LC_CTYPE} and @code{LC_MESSAGES} default to the value of the @code{LANG} environment variable. If none of these variables are set, GCC defaults to traditional C English behavior. @item TMPDIR @findex TMPDIR If @code{TMPDIR} is set, it specifies the directory to use for temporary files. GCC uses temporary files to hold the output of one stage of compilation which is to be used as input to the next stage: for example, the output of the preprocessor, which is the input to the compiler proper. @item GCC_EXEC_PREFIX @findex GCC_EXEC_PREFIX If @code{GCC_EXEC_PREFIX} is set, it specifies a prefix to use in the names of the subprograms executed by the compiler. No slash is added when this prefix is combined with the name of a subprogram, but you can specify a prefix that ends with a slash if you wish. If GCC cannot find the subprogram using the specified prefix, it tries looking in the usual places for the subprogram. The default value of @code{GCC_EXEC_PREFIX} is @file{@var{prefix}/lib/gcc-lib/} where @var{prefix} is the value of @code{prefix} when you ran the @file{configure} script. Other prefixes specified with @samp{-B} take precedence over this prefix. This prefix is also used for finding files such as @file{crt0.o} that are used for linking. In addition, the prefix is used in an unusual way in finding the directories to search for header files. For each of the standard directories whose name normally begins with @samp{/usr/local/lib/gcc-lib} (more precisely, with the value of @code{GCC_INCLUDE_DIR}), GCC tries replacing that beginning with the specified prefix to produce an alternate directory name. Thus, with @samp{-Bfoo/}, GCC will search @file{foo/bar} where it would normally search @file{/usr/local/lib/bar}. These alternate directories are searched first; the standard directories come next. @item COMPILER_PATH @findex COMPILER_PATH The value of @code{COMPILER_PATH} is a colon-separated list of directories, much like @code{PATH}. GCC tries the directories thus specified when searching for subprograms, if it can't find the subprograms using @code{GCC_EXEC_PREFIX}. @item LIBRARY_PATH @findex LIBRARY_PATH The value of @code{LIBRARY_PATH} is a colon-separated list of directories, much like @code{PATH}. When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using @code{GCC_EXEC_PREFIX}. Linking using GCC also uses these directories when searching for ordinary libraries for the @samp{-l} option (but directories specified with @samp{-L} come first). @item C_INCLUDE_PATH @itemx CPLUS_INCLUDE_PATH @itemx OBJC_INCLUDE_PATH @findex C_INCLUDE_PATH @findex CPLUS_INCLUDE_PATH @findex OBJC_INCLUDE_PATH @c @itemx OBJCPLUS_INCLUDE_PATH These environment variables pertain to particular languages. Each variable's value is a colon-separated list of directories, much like @code{PATH}. When GCC searches for header files, it tries the directories listed in the variable for the language you are using, after the directories specified with @samp{-I} but before the standard header file directories. @item DEPENDENCIES_OUTPUT @findex DEPENDENCIES_OUTPUT @cindex dependencies for make as output If this variable is set, its value specifies how to output dependencies for Make based on the header files processed by the compiler. This output looks much like the output from the @samp{-M} option (@pxref{Preprocessor Options}), but it goes to a separate file, and is in addition to the usual results of compilation. The value of @code{DEPENDENCIES_OUTPUT} can be just a file name, in which case the Make rules are written to that file, guessing the target name from the source file name. Or the value can have the form @samp{@var{file} @var{target}}, in which case the rules are written to file @var{file} using @var{target} as the target name. @item LANG @findex LANG @cindex locale definition This variable is used to pass locale information to the compiler. One way in which this information is used is to determine the character set to be used when character literals, string literals and comments are parsed in C and C++. When the compiler is configured to allow multibyte characters, the following values for @code{LANG} are recognized: @table @code @item C-JIS Recognize JIS characters. @item C-SJIS Recognize SJIS characters. @item C-EUCJP Recognize EUCJP characters. @end table If @code{LANG} is not defined, or if it has some other value, then the compiler will use mblen and mbtowc as defined by the default locale to recognize and translate multibyte characters. @end table @node Running Protoize @section Running Protoize The program @code{protoize} is an optional part of GNU C. You can use it to add prototypes to a program, thus converting the program to ANSI C in one respect. The companion program @code{unprotoize} does the reverse: it removes argument types from any prototypes that are found. When you run these programs, you must specify a set of source files as command line arguments. The conversion programs start out by compiling these files to see what functions they define. The information gathered about a file @var{foo} is saved in a file named @file{@var{foo}.X}. After scanning comes actual conversion. The specified files are all eligible to be converted; any files they include (whether sources or just headers) are eligible as well. But not all the eligible files are converted. By default, @code{protoize} and @code{unprotoize} convert only source and header files in the current directory. You can specify additional directories whose files should be converted with the @samp{-d @var{directory}} option. You can also specify particular files to exclude with the @samp{-x @var{file}} option. A file is converted if it is eligible, its directory name matches one of the specified directory names, and its name within the directory has not been excluded. Basic conversion with @code{protoize} consists of rewriting most function definitions and function declarations to specify the types of the arguments. The only ones not rewritten are those for varargs functions. @code{protoize} optionally inserts prototype declarations at the beginning of the source file, to make them available for any calls that precede the function's definition. Or it can insert prototype declarations with block scope in the blocks where undeclared functions are called. Basic conversion with @code{unprotoize} consists of rewriting most function declarations to remove any argument types, and rewriting function definitions to the old-style pre-ANSI form. Both conversion programs print a warning for any function declaration or definition that they can't convert. You can suppress these warnings with @samp{-q}. The output from @code{protoize} or @code{unprotoize} replaces the original source file. The original file is renamed to a name ending with @samp{.save}. If the @samp{.save} file already exists, then the source file is simply discarded. @code{protoize} and @code{unprotoize} both depend on GCC itself to scan the program and collect information about the functions it uses. So neither of these programs will work until GCC is installed. Here is a table of the options you can use with @code{protoize} and @code{unprotoize}. Each option works with both programs unless otherwise stated. @table @code @item -B @var{directory} Look for the file @file{SYSCALLS.c.X} in @var{directory}, instead of the usual directory (normally @file{/usr/local/lib}). This file contains prototype information about standard system functions. This option applies only to @code{protoize}. @item -c @var{compilation-options} Use @var{compilation-options} as the options when running @code{gcc} to produce the @samp{.X} files. The special option @samp{-aux-info} is always passed in addition, to tell @code{gcc} to write a @samp{.X} file. Note that the compilation options must be given as a single argument to @code{protoize} or @code{unprotoize}. If you want to specify several @code{gcc} options, you must quote the entire set of compilation options to make them a single word in the shell. There are certain @code{gcc} arguments that you cannot use, because they would produce the wrong kind of output. These include @samp{-g}, @samp{-O}, @samp{-c}, @samp{-S}, and @samp{-o} If you include these in the @var{compilation-options}, they are ignored. @item -C Rename files to end in @samp{.C} instead of @samp{.c}. This is convenient if you are converting a C program to C++. This option applies only to @code{protoize}. @item -g Add explicit global declarations. This means inserting explicit declarations at the beginning of each source file for each function that is called in the file and was not declared. These declarations precede the first function definition that contains a call to an undeclared function. This option applies only to @code{protoize}. @item -i @var{string} Indent old-style parameter declarations with the string @var{string}. This option applies only to @code{protoize}. @code{unprotoize} converts prototyped function definitions to old-style function definitions, where the arguments are declared between the argument list and the initial @samp{@{}. By default, @code{unprotoize} uses five spaces as the indentation. If you want to indent with just one space instead, use @samp{-i " "}. @item -k Keep the @samp{.X} files. Normally, they are deleted after conversion is finished. @item -l Add explicit local declarations. @code{protoize} with @samp{-l} inserts a prototype declaration for each function in each block which calls the function without any declaration. This option applies only to @code{protoize}. @item -n Make no real changes. This mode just prints information about the conversions that would have been done without @samp{-n}. @item -N Make no @samp{.save} files. The original files are simply deleted. Use this option with caution. @item -p @var{program} Use the program @var{program} as the compiler. Normally, the name @file{gcc} is used. @item -q Work quietly. Most warnings are suppressed. @item -v Print the version number, just like @samp{-v} for @code{gcc}. @end table If you need special compiler options to compile one of your program's source files, then you should generate that file's @samp{.X} file specially, by running @code{gcc} on that source file with the appropriate options and the option @samp{-aux-info}. Then run @code{protoize} on the entire set of files. @code{protoize} will use the existing @samp{.X} file because it is newer than the source file. For example: @example gcc -Dfoo=bar file1.c -aux-info protoize *.c @end example @noindent You need to include the special files along with the rest in the @code{protoize} command, even though their @samp{.X} files already exist, because otherwise they won't get converted. @xref{Protoize Caveats}, for more information on how to use @code{protoize} successfully.