static GTY(()) struct stmt_tree_s c_stmt_tree;
/* State saving variables. */
-int c_in_iteration_stmt;
-int c_in_case_stmt;
+tree c_break_label;
+tree c_cont_label;
/* Linked list of TRANSLATION_UNIT_DECLS for the translation units
included in this invocation. Note that the current translation
chained together by the ->prev field, which (as the name implies)
runs in reverse order. All the decls in a given namespace bound to
a given identifier are chained by the ->shadowed field, which runs
- from inner to outer scopes. Finally, the ->contour field points
- back to the relevant scope structure; this is mainly used to make
- decls in the externals scope invisible (see below).
+ from inner to outer scopes.
The ->decl field usually points to a DECL node, but there are two
exceptions. In the namespace of type tags, the bound entity is a
RECORD_TYPE, UNION_TYPE, or ENUMERAL_TYPE node. If an undeclared
identifier is encountered, it is bound to error_mark_node to
suppress further errors about that identifier in the current
- function. */
+ function.
+
+ The depth field is copied from the scope structure that holds this
+ decl. It is used to preserve the proper ordering of the ->shadowed
+ field (see bind()) and also for a handful of special-case checks.
+ Finally, the invisible bit is true for a decl which should be
+ ignored for purposes of normal name lookup, and the nested bit is
+ true for a decl that's been bound a second time in an inner scope;
+ in all such cases, the binding in the outer scope will have its
+ invisible bit true. */
struct c_binding GTY((chain_next ("%h.prev")))
{
tree id; /* the identifier it's bound to */
struct c_binding *prev; /* the previous decl in this scope */
struct c_binding *shadowed; /* the innermost decl shadowed by this one */
- struct c_scope *contour; /* the scope in which this decl is bound */
+ unsigned int depth : 28; /* depth of this scope */
+ BOOL_BITFIELD invisible : 1; /* normal lookup should ignore this binding */
+ BOOL_BITFIELD nested : 1; /* do not set DECL_CONTEXT when popping */
+ /* two free bits */
};
+#define B_IN_SCOPE(b1, b2) ((b1)->depth == (b2)->depth)
+#define B_IN_CURRENT_SCOPE(b) ((b)->depth == current_scope->depth)
+#define B_IN_FILE_SCOPE(b) ((b)->depth == 1 /*file_scope->depth*/)
+#define B_IN_EXTERNAL_SCOPE(b) ((b)->depth == 0 /*external_scope->depth*/)
#define I_SYMBOL_BINDING(node) \
(((struct lang_identifier *)IDENTIFIER_NODE_CHECK(node))->symbol_binding)
/* Functions called automatically at the beginning and end of execution. */
-tree static_ctors, static_dtors;
+static GTY(()) tree static_ctors;
+static GTY(()) tree static_dtors;
/* Forward declarations. */
static tree lookup_name_in_scope (tree, struct c_scope *);
which may be any of several kinds of DECL or TYPE or error_mark_node,
in the scope SCOPE. */
static void
-bind (tree name, tree decl, struct c_scope *scope)
+bind (tree name, tree decl, struct c_scope *scope, bool invisible, bool nested)
{
struct c_binding *b, **here;
b->shadowed = 0;
b->decl = decl;
b->id = name;
- b->contour = scope;
+ b->depth = scope->depth;
+ b->invisible = invisible;
+ b->nested = nested;
b->prev = scope->bindings;
scope->bindings = b;
/* Locate the appropriate place in the chain of shadowed decls
to insert this binding. Normally, scope == current_scope and
this does nothing. */
- while (*here && (*here)->contour->depth > scope->depth)
+ while (*here && (*here)->depth > scope->depth)
here = &(*here)->shadowed;
b->shadowed = *here;
{
struct c_binding *prev = b->prev;
- b->id = 0;
- b->decl = 0;
- b->contour = 0;
- b->shadowed = 0;
+ memset (b, 0, sizeof (struct c_binding));
b->prev = binding_freelist;
binding_freelist = b;
}
}
+/* Set the TYPE_CONTEXT of all of TYPE's variants to CONTEXT. */
+
+static void
+set_type_context (tree type, tree context)
+{
+ for (type = TYPE_MAIN_VARIANT (type); type;
+ type = TYPE_NEXT_VARIANT (type))
+ TYPE_CONTEXT (type) = context;
+}
+
/* Exit a scope. Restore the state of the identifier-decl mappings
that were in effect when this scope was entered. Return a BLOCK
node containing all the DECLs in this scope that are of interest
case ENUMERAL_TYPE:
case UNION_TYPE:
case RECORD_TYPE:
- TYPE_CONTEXT (p) = context;
+ set_type_context (p, context);
/* Types may not have tag-names, in which case the type
appears in the bindings list with b->id NULL. */
common_symbol:
/* All of these go in BLOCK_VARS, but only if this is the
binding in the home scope. */
- if (!C_DECL_IN_EXTERNAL_SCOPE (p) || scope == external_scope)
+ if (!b->nested)
{
TREE_CHAIN (p) = BLOCK_VARS (block);
BLOCK_VARS (block) = p;
}
- /* If this is the file scope, must set DECL_CONTEXT on these. */
- if (!C_DECL_IN_EXTERNAL_SCOPE (p) && scope == file_scope)
- DECL_CONTEXT (p) = context;
+ /* If this is the file scope, and we are processing more
+ than one translation unit in this compilation, set
+ DECL_CONTEXT of each decl to the TRANSLATION_UNIT_DECL.
+ This makes same_translation_unit_p work, and causes
+ static declarations to be given disambiguating suffixes. */
+ if (scope == file_scope && num_in_fnames > 1)
+ {
+ DECL_CONTEXT (p) = context;
+ if (TREE_CODE (p) == TYPE_DECL)
+ set_type_context (TREE_TYPE (p), context);
+ }
/* Fall through. */
/* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
{
tree decl;
+ if (file_scope)
+ return;
+
push_scope ();
file_scope = current_scope;
start_fname_decls ();
for (decl = visible_builtins; decl; decl = TREE_CHAIN (decl))
- bind (DECL_NAME (decl), decl, file_scope);
+ bind (DECL_NAME (decl), decl, file_scope,
+ /*invisible=*/false, /*nested=*/true);
}
void
still works without it. */
finish_fname_decls ();
- /* Kludge: don't actually pop the file scope if generating a
- precompiled header, so that macros and local symbols are still
- visible to the PCH generator. */
+ /* This is the point to write out a PCH if we're doing that.
+ In that case we do not want to do anything else. */
if (pch_file)
- return;
+ {
+ c_common_write_pch ();
+ return;
+ }
- /* And pop off the file scope. */
+ /* Pop off the file scope and close this translation unit. */
pop_scope ();
file_scope = 0;
-
- cpp_undef_all (parse_in);
+ cgraph_finalize_compilation_unit ();
}
/* Insert BLOCK at the end of the list of subblocks of the current
/* Record the identifier as the type's name if it has none. */
if (name && !TYPE_NAME (type))
TYPE_NAME (type) = name;
- bind (name, type, current_scope);
+ bind (name, type, current_scope, /*invisible=*/false, /*nested=*/false);
/* Create a fake NULL-named TYPE_DECL node whose TREE_TYPE will be the
tagged type we just added to the current scope. This fake
}
}
else if (TREE_CODE (olddecl) == FUNCTION_DECL
- && DECL_SOURCE_LINE (olddecl) == 0)
+ && DECL_IS_BUILTIN (olddecl))
{
/* A conflicting function declaration for a predeclared
function that isn't actually built in. Objective C uses
&& !(DECL_DECLARED_INLINE_P (olddecl)
&& DECL_EXTERNAL (olddecl)
&& !(DECL_DECLARED_INLINE_P (newdecl)
- && DECL_EXTERNAL (newdecl))))
+ && DECL_EXTERNAL (newdecl)
+ && same_translation_unit_p (olddecl, newdecl))))
{
error ("%Jredefinition of '%D'", newdecl, newdecl);
locate_old_decl (olddecl, error);
locate_old_decl (olddecl, error);
return false;
}
- /* Mismatched non-static and static is considered poor style.
- We only diagnose static then non-static if -Wtraditional,
- because it is the most convenient way to get some effects
- (see e.g. what unwind-dw2-fde-glibc.c does to the definition
- of _Unwind_Find_FDE in unwind-dw2-fde.c). Revisit? */
+ /* A non-static declaration (even an "extern") followed by a
+ static declaration is undefined behavior per C99 6.2.2p3-5,7.
+ The same is true for a static forward declaration at block
+ scope followed by a non-static declaration/definition at file
+ scope. Static followed by non-static at the same scope is
+ not undefined behavior, and is the most convenient way to get
+ some effects (see e.g. what unwind-dw2-fde-glibc.c does to
+ the definition of _Unwind_Find_FDE in unwind-dw2-fde.c), but
+ we do diagnose it if -Wtraditional. */
if (TREE_PUBLIC (olddecl) && !TREE_PUBLIC (newdecl))
{
- /* A static function declaration for a predeclared function
- that isn't actually built in, silently overrides the
- default. Objective C uses these. See also above.
- FIXME: Make Objective C use normal builtins. */
- if (TREE_CODE (olddecl) == FUNCTION_DECL
- && DECL_SOURCE_LINE (olddecl) == 0)
- return false;
- else
+ /* Two exceptions to the rule. If olddecl is an extern
+ inline, or a predeclared function that isn't actually
+ built in, newdecl silently overrides olddecl. The latter
+ occur only in Objective C; see also above. (FIXME: Make
+ Objective C use normal builtins.) */
+ if (!DECL_IS_BUILTIN (olddecl)
+ && !(DECL_EXTERNAL (olddecl)
+ && DECL_DECLARED_INLINE_P (olddecl)))
{
- warning ("%Jstatic declaration of '%D' follows "
- "non-static declaration", newdecl, newdecl);
- warned = true;
+ error ("%Jstatic declaration of '%D' follows "
+ "non-static declaration", newdecl, newdecl);
+ locate_old_decl (olddecl, error);
}
+ return false;
}
- else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)
- && warn_traditional)
+ else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl))
{
- warning ("%Jnon-static declaration of '%D' follows "
- "static declaration", newdecl, newdecl);
- warned = true;
+ if (DECL_CONTEXT (olddecl))
+ {
+ error ("%Jnon-static declaration of '%D' follows "
+ "static declaration", newdecl, newdecl);
+ locate_old_decl (olddecl, error);
+ return false;
+ }
+ else if (warn_traditional)
+ {
+ warning ("%Jnon-static declaration of '%D' follows "
+ "static declaration", newdecl, newdecl);
+ warned = true;
+ }
}
}
else if (TREE_CODE (newdecl) == VAR_DECL)
return false;
}
- /* Objects declared at file scope: if at least one is 'extern',
- it's fine (6.2.2p4); otherwise the linkage must agree (6.2.2p7). */
- if (DECL_FILE_SCOPE_P (newdecl))
+ /* Objects declared at file scope: if the first declaration had
+ external linkage (even if it was an external reference) the
+ second must have external linkage as well, or the behavior is
+ undefined. If the first declaration had internal linkage, then
+ the second must too, or else be an external reference (in which
+ case the composite declaration still has internal linkage).
+ As for function declarations, we warn about the static-then-
+ extern case only for -Wtraditional. See generally 6.2.2p3-5,7. */
+ if (DECL_FILE_SCOPE_P (newdecl)
+ && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
{
- if (!DECL_EXTERNAL (newdecl)
- && !DECL_EXTERNAL (olddecl)
- && TREE_PUBLIC (newdecl) != TREE_PUBLIC (olddecl))
+ if (DECL_EXTERNAL (newdecl))
+ {
+ if (warn_traditional)
+ {
+ warning ("%Jnon-static declaration of '%D' follows "
+ "static declaration", newdecl, newdecl);
+ warned = true;
+ }
+ }
+ else
{
if (TREE_PUBLIC (newdecl))
error ("%Jnon-static declaration of '%D' follows "
}
/* Two objects with the same name declared at the same block
scope must both be external references (6.7p3). */
- else if (DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)
+ else if (!DECL_FILE_SCOPE_P (newdecl)
+ && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)
&& (!DECL_EXTERNAL (newdecl) || !DECL_EXTERNAL (olddecl)))
{
if (DECL_EXTERNAL (newdecl))
/* Inline declaration after use or definition.
??? Should we still warn about this now we have unit-at-a-time
- mode and can get it right? */
- if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl))
+ mode and can get it right?
+ Definitely don't complain if the decls are in different translation
+ units. */
+ if (DECL_DECLARED_INLINE_P (newdecl) && !DECL_DECLARED_INLINE_P (olddecl)
+ && same_translation_unit_p (olddecl, newdecl))
{
if (TREE_USED (olddecl))
{
}
}
- /* This bit must not get wiped out. */
- C_DECL_IN_EXTERNAL_SCOPE (newdecl) |= C_DECL_IN_EXTERNAL_SCOPE (olddecl);
-
/* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
- But preserve OLDDECL's DECL_UID. */
+ But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
{
unsigned olddecl_uid = DECL_UID (olddecl);
+ tree olddecl_context = DECL_CONTEXT (olddecl);
memcpy ((char *) olddecl + sizeof (struct tree_common),
(char *) newdecl + sizeof (struct tree_common),
sizeof (struct tree_decl) - sizeof (struct tree_common));
DECL_UID (olddecl) = olddecl_uid;
+ DECL_CONTEXT (olddecl) = olddecl_context;
}
/* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
/* Shadow warnings wanted? */
if (!warn_shadow
/* No shadow warnings for internally generated vars. */
- || DECL_SOURCE_LINE (new) == 0
+ || DECL_IS_BUILTIN (new)
/* No shadow warnings for vars made for inlining. */
|| DECL_FROM_INLINE (new)
/* Don't warn about the parm names in function declarator
|| (TREE_CODE (new) == PARM_DECL && current_scope->outer->parm_flag))
return;
- /* Is anything being shadowed? Do not be confused by a second binding
- to the same decl in the externals scope. */
+ /* Is anything being shadowed? Invisible decls do not count. */
for (b = I_SYMBOL_BINDING (DECL_NAME (new)); b; b = b->shadowed)
- if (b->decl && b->decl != new && b->contour != external_scope)
+ if (b->decl && b->decl != new && !b->invisible)
{
tree old = b->decl;
static void
clone_underlying_type (tree x)
{
- if (DECL_SOURCE_LINE (x) == 0)
+ if (DECL_IS_BUILTIN (x))
{
if (TYPE_NAME (TREE_TYPE (x)) == 0)
TYPE_NAME (TREE_TYPE (x)) = x;
tree name = DECL_NAME (x);
struct c_scope *scope = current_scope;
struct c_binding *b;
+ bool nested = false;
/* Functions need the lang_decl data. */
if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
/* Anonymous decls are just inserted in the scope. */
if (!name)
{
- bind (name, x, scope);
+ bind (name, x, scope, /*invisible=*/false, /*nested=*/false);
return x;
}
diagnostics). In particular, we should not consider possible
duplicates in the external scope, or shadowing. */
b = I_SYMBOL_BINDING (name);
- if (b && b->contour == scope)
+ if (b && B_IN_SCOPE (b, scope))
{
if (duplicate_decls (x, b->decl))
return b->decl;
if (warn_nested_externs
&& scope != file_scope
&& !DECL_IN_SYSTEM_HEADER (x))
- warning ("nested extern declaration of `%s'",
- IDENTIFIER_POINTER (name));
+ warning ("nested extern declaration of '%D'", x);
- while (b && b->contour != external_scope)
+ while (b && !B_IN_EXTERNAL_SCOPE (b))
b = b->shadowed;
/* The point of the same_translation_unit_p check here is,
they are in different translation units. In any case,
the static does not go in the externals scope. */
if (b
- && (DECL_EXTERNAL (x) || TREE_PUBLIC (x)
- || same_translation_unit_p (x, b->decl))
+ && (TREE_PUBLIC (x) || same_translation_unit_p (x, b->decl))
&& duplicate_decls (x, b->decl))
{
- bind (name, b->decl, scope);
+ bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
return b->decl;
}
- else if (DECL_EXTERNAL (x) || TREE_PUBLIC (x))
+ else if (TREE_PUBLIC (x))
{
- C_DECL_IN_EXTERNAL_SCOPE (x) = 1;
- bind (name, x, external_scope);
+ bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
+ nested = true;
}
}
+ /* Similarly, a declaration of a function with static linkage at
+ block scope must be checked against any existing declaration
+ of that function at file scope. */
+ else if (TREE_CODE (x) == FUNCTION_DECL && scope != file_scope
+ && !TREE_PUBLIC (x) && !DECL_INITIAL (x))
+ {
+ if (warn_nested_externs && !DECL_IN_SYSTEM_HEADER (x))
+ warning ("nested static declaration of '%D'", x);
+
+ while (b && !B_IN_FILE_SCOPE (b))
+ b = b->shadowed;
+
+ if (b && same_translation_unit_p (x, b->decl)
+ && duplicate_decls (x, b->decl))
+ {
+ bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true);
+ return b->decl;
+ }
+ else
+ {
+ bind (name, x, file_scope, /*invisible=*/true, /*nested=*/false);
+ nested = true;
+ }
+ }
warn_if_shadowing (x);
if (TREE_CODE (x) == TYPE_DECL)
clone_underlying_type (x);
- bind (name, x, scope);
+ bind (name, x, scope, /*invisible=*/false, nested);
/* If x's type is incomplete because it's based on a
structure or union which has not yet been fully declared,
pushdecl_top_level (tree x)
{
tree name;
+ bool nested = false;
if (TREE_CODE (x) != VAR_DECL)
abort ();
if (I_SYMBOL_BINDING (name))
abort ();
- if (DECL_EXTERNAL (x) || TREE_PUBLIC (x))
+ if (TREE_PUBLIC (x))
{
- C_DECL_IN_EXTERNAL_SCOPE (x) = 1;
- bind (name, x, external_scope);
+ bind (name, x, external_scope, /*invisible=*/true, /*nested=*/false);
+ nested = true;
}
if (file_scope)
- bind (name, x, file_scope);
+ bind (name, x, file_scope, /*invisible=*/false, nested);
return x;
}
in the external scope because they're pushed before the file
scope gets created. Catch this here and rebind them into the
file scope. */
- if (!DECL_BUILT_IN (decl) && DECL_SOURCE_LINE (decl) == 0)
+ if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl))
{
- bind (functionid, decl, file_scope);
+ bind (functionid, decl, file_scope,
+ /*invisible=*/false, /*nested=*/true);
return decl;
}
else
implicit_decl_warning (functionid, decl);
C_DECL_IMPLICIT (decl) = 1;
}
- bind (functionid, decl, current_scope);
+ bind (functionid, decl, current_scope,
+ /*invisible=*/false, /*nested=*/true);
return decl;
}
}
will be nonnull but current_function_scope will be null. */
scope = current_function_scope ? current_function_scope : current_scope;
}
- bind (id, error_mark_node, scope);
+ bind (id, error_mark_node, scope, /*invisible=*/false, /*nested=*/false);
}
\f
/* Subroutine of lookup_label, declare_label, define_label: construct a
label = make_label (name, input_location);
/* Ordinary labels go in the current function scope. */
- bind (name, label, current_function_scope);
+ bind (name, label, current_function_scope,
+ /*invisible=*/false, /*nested=*/false);
return label;
}
/* Check to make sure that the label hasn't already been declared
at this scope */
- if (b && b->contour == current_scope)
+ if (b && B_IN_CURRENT_SCOPE (b))
{
error ("duplicate label declaration `%s'", IDENTIFIER_POINTER (name));
locate_old_decl (b->decl, error);
C_DECLARED_LABEL_FLAG (label) = 1;
/* Declared labels go in the current scope. */
- bind (name, label, current_scope);
+ bind (name, label, current_scope,
+ /*invisible=*/false, /*nested=*/false);
return label;
}
label = make_label (name, location);
/* Ordinary labels go in the current function scope. */
- bind (name, label, current_function_scope);
+ bind (name, label, current_function_scope,
+ /*invisible=*/false, /*nested=*/false);
}
if (warn_traditional && !in_system_header && lookup_name (name))
a tag in the file scope. (Primarily relevant to Objective-C
and its builtin structure tags, which get pushed before the
file scope is created.) */
- if (b->contour == current_scope
- || (current_scope == file_scope && b->contour == external_scope))
+ if (B_IN_CURRENT_SCOPE (b)
+ || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b)))
thislevel = 1;
}
lookup_name (tree name)
{
struct c_binding *b = I_SYMBOL_BINDING (name);
- if (b && (b->contour != external_scope || TREE_CODE (b->decl) == TYPE_DECL))
+ if (b && !b->invisible)
return b->decl;
return 0;
}
struct c_binding *b;
for (b = I_SYMBOL_BINDING (name); b; b = b->shadowed)
- if (b->contour == scope)
+ if (B_IN_SCOPE (b, scope))
return b->decl;
return 0;
}
/* Declarations from c_common_nodes_and_builtins must not be associated
with this input file, lest we get differences between using and not
using preprocessed headers. */
- input_location.file = "<internal>";
+#ifdef USE_MAPPED_LOCATION
+ input_location = BUILTINS_LOCATION;
+#else
+ input_location.file = "<built-in>";
input_location.line = 0;
+#endif
build_common_tree_nodes (flag_signed_char);
if (current_function_decl)
{
DECL_CONTEXT (decl) = current_function_decl;
- bind (id, decl, current_function_scope);
+ bind (id, decl, current_function_scope,
+ /*invisible=*/false, /*nested=*/false);
}
finish_decl (decl, init, NULL_TREE);
if (I_SYMBOL_BINDING (id))
abort ();
- C_DECL_IN_EXTERNAL_SCOPE (decl) = 1;
- bind (id, decl, external_scope);
+ bind (id, decl, external_scope, /*invisible=*/true, /*nested=*/false);
/* Builtins in the implementation namespace are made visible without
needing to be explicitly declared. See push_file_scope. */
for (; args; args = TREE_CHAIN (args))
{
tree type = TREE_TYPE (args);
- if (INTEGRAL_TYPE_P (type)
+ if (type && INTEGRAL_TYPE_P (type)
&& TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
DECL_ARG_TYPE (args) = integer_type_node;
}
tree builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
SET_DECL_RTL (builtin, NULL_RTX);
change_decl_assembler_name (builtin, get_identifier (starred));
-#ifdef TARGET_MEM_FUNCTIONS
if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
init_block_move_fn (starred);
else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
init_block_clear_fn (starred);
-#else
- if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BCOPY)
- init_block_move_fn (starred);
- else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_BZERO)
- init_block_clear_fn (starred);
-#endif
}
SET_DECL_RTL (decl, NULL_RTX);
change_decl_assembler_name (decl, get_identifier (starred));
}
if (TREE_CODE (decl) != FUNCTION_DECL)
- add_stmt (build_stmt (DECL_STMT, decl));
+ add_stmt (build_stmt (DECL_EXPR, decl));
}
if (!DECL_FILE_SCOPE_P (decl))
if (TREE_CODE (decl) == TYPE_DECL)
{
if (!DECL_FILE_SCOPE_P (decl)
- && variably_modified_type_p (TREE_TYPE (decl)))
- add_stmt (build_stmt (DECL_STMT, decl));
+ && variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
+ add_stmt (build_stmt (DECL_EXPR, decl));
rest_of_decl_compilation (decl, NULL, DECL_FILE_SCOPE_P (decl), 0);
}
{
tree decl;
- /* Don't attempt to expand sizes while parsing this decl.
- (We can get here with i_s_e 1 somehow from Objective-C.) */
- int save_immediate_size_expand = immediate_size_expand;
- immediate_size_expand = 0;
-
decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
TREE_PURPOSE (TREE_PURPOSE (parm)),
PARM, 0, NULL);
decl = pushdecl (decl);
finish_decl (decl, NULL_TREE, NULL_TREE);
-
- immediate_size_expand = save_immediate_size_expand;
}
/* Mark all the parameter declarations to date as forward decls.
{
/* We do not use start_decl here because we have a type, not a declarator;
and do not use finish_decl because the decl should be stored inside
- the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_STMT. */
+ the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */
tree decl = build_decl (VAR_DECL, NULL_TREE, type);
tree complit;
tree stmt;
if (type == error_mark_node || !COMPLETE_TYPE_P (type))
return error_mark_node;
- stmt = build_stmt (DECL_STMT, decl);
+ stmt = build_stmt (DECL_EXPR, decl);
complit = build1 (COMPOUND_LITERAL_EXPR, TREE_TYPE (decl), stmt);
TREE_SIDE_EFFECTS (complit) = 1;
}
if (size_varies)
- {
- /* We must be able to distinguish the
- SAVE_EXPR_CONTEXT for the variably-sized type
- so that we can set it correctly in
- set_save_expr_context. The convention is
- that all SAVE_EXPRs that need to be reset
- have NULL_TREE for their SAVE_EXPR_CONTEXT. */
- tree cfd = current_function_decl;
- if (decl_context == PARM)
- current_function_decl = NULL_TREE;
- itype = variable_size (itype);
- if (decl_context == PARM)
- current_function_decl = cfd;
- }
+ itype = variable_size (itype);
itype = build_index_type (itype);
}
}
}
else if (TREE_CODE (type) == FUNCTION_TYPE)
{
- /* Every function declaration is "external"
- except for those which are inside a function body
- in which `auto' is used.
- That is a case not specified by ANSI C,
- and we use it for forward declarations for nested functions. */
- int extern_ref = (!(specbits & (1 << (int) RID_AUTO))
- || current_scope == file_scope);
-
if (specbits & (1 << (int) RID_AUTO)
&& (pedantic || current_scope == file_scope))
pedwarn ("invalid storage class for function `%s'", name);
&& !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl))))
warning ("`noreturn' function returns non-void value");
- if (extern_ref)
+ /* Every function declaration is an external reference
+ (DECL_EXTERNAL) except for those which are not at file
+ scope and are explicitly declared "auto". This is
+ forbidden by standard C (C99 6.7.1p5) and is interpreted by
+ GCC to signify a forward declaration of a nested function. */
+ if ((specbits & (1 << RID_AUTO)) && current_scope != file_scope)
+ DECL_EXTERNAL (decl) = 0;
+ else
DECL_EXTERNAL (decl) = 1;
+
/* Record absence of global scope for `static' or `auto'. */
TREE_PUBLIC (decl)
= !(specbits & ((1 << (int) RID_STATIC) | (1 << (int) RID_AUTO)));
}
/* Install struct as DECL_CONTEXT of each field decl.
- Also process specified field sizes,m which is found in the DECL_INITIAL.
- Store 0 there, except for ": 0" fields (so we can find them
- and delete them, below). */
+ Also process specified field sizes, found in the DECL_INITIAL,
+ storing 0 there after the type has been changed to precision equal
+ to its width, rather than the precision of the specified standard
+ type. (Correct layout requires the original type to have been preserved
+ until now.) */
saw_named_field = 0;
for (x = fieldlist; x; x = TREE_CHAIN (x))
SET_DECL_C_BIT_FIELD (x);
}
- DECL_INITIAL (x) = 0;
-
/* Detect flexible array member in an invalid context. */
if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE
&& TYPE_SIZE (TREE_TYPE (x)) == NULL_TREE
layout_type (t);
- /* Delete all zero-width bit-fields from the fieldlist. */
+ /* Give bit-fields their proper types. */
{
tree *fieldlistp = &fieldlist;
while (*fieldlistp)
- if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp))
- *fieldlistp = TREE_CHAIN (*fieldlistp);
+ if (TREE_CODE (*fieldlistp) == FIELD_DECL && DECL_INITIAL (*fieldlistp)
+ && TREE_TYPE (*fieldlistp) != error_mark_node)
+ {
+ unsigned HOST_WIDE_INT width
+ = tree_low_cst (DECL_INITIAL (*fieldlistp), 1);
+ tree type = TREE_TYPE (*fieldlistp);
+ if (width != TYPE_PRECISION (type))
+ TREE_TYPE (*fieldlistp)
+ = build_nonstandard_integer_type (width, TYPE_UNSIGNED (type));
+ DECL_INITIAL (*fieldlistp) = 0;
+ }
else
fieldlistp = &TREE_CHAIN (*fieldlistp);
}
{
tree decl1, old_decl;
tree restype;
- int old_immediate_size_expand = immediate_size_expand;
current_function_returns_value = 0; /* Assume, until we see it does. */
current_function_returns_null = 0;
current_function_returns_abnormally = 0;
warn_about_return_type = 0;
current_extern_inline = 0;
- c_in_iteration_stmt = 0;
- c_in_case_stmt = 0;
+ c_switch_stack = NULL;
- /* Don't expand any sizes in the return type of the function. */
- immediate_size_expand = 0;
+ /* Indicate no valid break/continue context by setting these variables
+ to some non-null, non-label value. We'll notice and emit the proper
+ error message in c_finish_bc_stmt. */
+ c_break_label = c_cont_label = size_zero_node;
decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL);
/* If the declarator is not suitable for a function definition,
cause a syntax error. */
if (decl1 == 0)
- {
- immediate_size_expand = old_immediate_size_expand;
- return 0;
- }
+ return 0;
decl_attributes (&decl1, attributes, 0);
DECL_RESULT (current_function_decl)
= build_decl (RESULT_DECL, NULL_TREE, restype);
- immediate_size_expand = old_immediate_size_expand;
-
start_fname_decls ();
return 1;
{
DECL_CONTEXT (decl) = current_function_decl;
if (DECL_NAME (decl))
- bind (DECL_NAME (decl), decl, current_scope);
+ bind (DECL_NAME (decl), decl, current_scope,
+ /*invisible=*/false, /*nested=*/false);
else
error ("%Jparameter name omitted", decl);
}
{
DECL_CONTEXT (decl) = current_function_decl;
if (DECL_NAME (decl))
- bind (DECL_NAME (decl), decl, current_scope);
+ bind (DECL_NAME (decl), decl, current_scope,
+ /*invisible=*/false, /*nested=*/false);
}
/* And all the tag declarations. */
for (decl = tags; decl; decl = TREE_CHAIN (decl))
if (TREE_PURPOSE (decl))
- bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope);
+ bind (TREE_PURPOSE (decl), TREE_VALUE (decl), current_scope,
+ /*invisible=*/false, /*nested=*/false);
}
/* Subroutine of store_parm_decls which handles old-style function
}
b = I_SYMBOL_BINDING (TREE_VALUE (parm));
- if (b && b->contour == current_scope)
+ if (b && B_IN_CURRENT_SCOPE (b))
{
decl = b->decl;
/* If we got something other than a PARM_DECL it is an error. */
}
}
-/* A subroutine of store_parm_decls called via walk_tree. Mark all
- decls non-local. */
-
-static tree
-set_decl_nonlocal (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
-{
- tree t = *tp;
-
- if (DECL_P (t))
- {
- DECL_NONLOCAL (t) = 1;
- *walk_subtrees = 0;
- }
- else if (TYPE_P (t))
- *walk_subtrees = 0;
-
- return NULL;
-}
-
/* Store the parameter declarations into the current function declaration.
This is called after parsing the parameter declarations, before
digesting the body of the function.
{
tree fndecl = current_function_decl;
- /* The function containing FNDECL, if any. */
- tree context = decl_function_context (fndecl);
-
/* The argument information block for FNDECL. */
tree arg_info = DECL_ARGUMENTS (fndecl);
/* Begin the statement tree for this function. */
DECL_SAVED_TREE (fndecl) = push_stmt_list ();
- /* If this is a nested function, save away the sizes of any
- variable-size types so that we can expand them when generating
- RTL. */
- if (context)
- {
- tree t;
-
- DECL_LANG_SPECIFIC (fndecl)->pending_sizes
- = nreverse (get_pending_sizes ());
- for (t = DECL_LANG_SPECIFIC (fndecl)->pending_sizes;
- t;
- t = TREE_CHAIN (t))
- {
- /* We will have a nonlocal use of whatever variables are
- buried inside here. */
- walk_tree (&TREE_OPERAND (TREE_VALUE (t), 0),
- set_decl_nonlocal, NULL, NULL);
-
- SAVE_EXPR_CONTEXT (TREE_VALUE (t)) = context;
- }
- }
-
- /* This function is being processed in whole-function mode. */
- cfun->x_whole_function_mode_p = 1;
+ /* ??? Insert the contents of the pending sizes list into the function
+ to be evaluated. This just changes mis-behaviour until assign_parms
+ phase ordering problems are resolved. */
+ {
+ tree t;
+ for (t = nreverse (get_pending_sizes ()); t ; t = TREE_CHAIN (t))
+ add_stmt (TREE_VALUE (t));
+ }
/* Even though we're inside a function body, we still don't want to
call expand_expr to calculate the size of a variable-sized array.
We haven't necessarily assigned RTL to all variables yet, so it's
not safe to try to expand expressions involving them. */
- immediate_size_expand = 0;
cfun->x_dont_save_pending_sizes_p = 1;
}
\f
}
else
{
-#ifdef DEFAULT_MAIN_RETURN
- /* Make it so that `main' always returns success by default. */
- DEFAULT_MAIN_RETURN;
-#else
if (flag_isoc99)
c_finish_return (integer_zero_node);
-#endif
}
}
f->language = p;
p->base.x_stmt_tree = c_stmt_tree;
- p->x_in_iteration_stmt = c_in_iteration_stmt;
- p->x_in_case_stmt = c_in_case_stmt;
+ p->x_break_label = c_break_label;
+ p->x_cont_label = c_cont_label;
+ p->x_switch_stack = c_switch_stack;
p->returns_value = current_function_returns_value;
p->returns_null = current_function_returns_null;
p->returns_abnormally = current_function_returns_abnormally;
}
c_stmt_tree = p->base.x_stmt_tree;
- c_in_iteration_stmt = p->x_in_iteration_stmt;
- c_in_case_stmt = p->x_in_case_stmt;
+ c_break_label = p->x_break_label;
+ c_cont_label = p->x_cont_label;
+ c_switch_stack = p->x_switch_stack;
current_function_returns_value = p->returns_value;
current_function_returns_null = p->returns_null;
current_function_returns_abnormally = p->returns_abnormally;
struct c_binding *b;
for (b = I_SYMBOL_BINDING (t); b; b = b->shadowed)
- if (b->contour == file_scope || b->contour == external_scope)
+ if (B_IN_FILE_SCOPE (b) || B_IN_EXTERNAL_SCOPE (b))
return b->decl;
return 0;
return build1 (INDIRECT_REF, quals, itarget);
}
-/* A wrapper around lhd_set_decl_assembler_name that gives static
- variables their C names if they are at file scope and only one
- translation unit is being compiled, for backwards compatibility
- with certain bizarre assembler hacks (like crtstuff.c). */
-
-void
-c_static_assembler_name (tree decl)
+/* Synthesize a function which calls all the global ctors or global
+ dtors in this file. This is only used for targets which do not
+ support .ctors/.dtors sections. FIXME: Migrate into cgraph. */
+static void
+build_cdtor (int method_type, tree cdtors)
{
- if (num_in_fnames == 1
- && !TREE_PUBLIC (decl) && DECL_CONTEXT (decl)
- && TREE_CODE (DECL_CONTEXT (decl)) == TRANSLATION_UNIT_DECL)
- SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
- else
- lhd_set_decl_assembler_name (decl);
+ tree body = 0;
+
+ if (!cdtors)
+ return;
+
+ for (; cdtors; cdtors = TREE_CHAIN (cdtors))
+ append_to_statement_list (build_function_call (TREE_VALUE (cdtors), 0),
+ &body);
+
+ cgraph_build_static_cdtor (method_type, body, DEFAULT_INIT_PRIORITY);
}
-/* Perform final processing on file-scope data. */
+/* Perform final processing on one file scope's declarations (or the
+ external scope's declarations), GLOBALS. */
static void
c_write_global_declarations_1 (tree globals)
{
void
c_write_global_declarations (void)
{
- tree t;
+ tree ext_block, t;
/* We don't want to do this if generating a PCH. */
if (pch_file)
return;
- /* Process all file scopes in this compilation. */
+ /* Don't waste time on further processing if -fsyntax-only or we've
+ encountered errors. */
+ if (flag_syntax_only || errorcount || sorrycount || cpp_errors (parse_in))
+ return;
+
+ /* Close the external scope. */
+ ext_block = pop_scope ();
+ external_scope = 0;
+ if (current_scope)
+ abort ();
+
+ /* Process all file scopes in this compilation, and the external_scope,
+ through wrapup_global_declarations and check_global_declarations. */
for (t = all_translation_units; t; t = TREE_CHAIN (t))
c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
-
- /* Now do the same for the externals scope. */
- t = pop_scope ();
- if (t)
- c_write_global_declarations_1 (BLOCK_VARS (t));
+ c_write_global_declarations_1 (BLOCK_VARS (ext_block));
+
+ /* Generate functions to call static constructors and destructors
+ for targets that do not support .ctors/.dtors sections. These
+ functions have magic names which are detected by collect2. */
+ build_cdtor ('I', static_ctors); static_ctors = 0;
+ build_cdtor ('D', static_dtors); static_dtors = 0;
+
+ /* We're done parsing; proceed to optimize and emit assembly.
+ FIXME: shouldn't be the front end's responsibility to call this. */
+ cgraph_optimize ();
+
+ /* Presently this has to happen after cgraph_optimize.
+ FIXME: shouldn't be the front end's responsibility to call this. */
+ if (flag_mudflap)
+ mudflap_finish_file ();
}
#include "gt-c-decl.h"