binding_freelist = b->prev;
}
else
- b = ggc_alloc (sizeof (struct c_binding));
+ b = GGC_NEW (struct c_binding);
b->shadowed = 0;
b->decl = decl;
scope_freelist = scope->outer;
}
else
- scope = ggc_alloc_cleared (sizeof (struct c_scope));
+ scope = GGC_CNEW (struct c_scope);
scope->keep = keep_next_level_flag;
scope->outer = current_scope;
{
if (DECL_EXTERNAL (newdecl))
{
- if (warn_traditional)
+ if (!DECL_FILE_SCOPE_P (olddecl))
+ {
+ error ("%Jextern declaration of %qD follows "
+ "declaration with no linkage", newdecl, newdecl);
+ locate_old_decl (olddecl, error);
+ return false;
+ }
+ else if (warn_traditional)
{
warning ("%Jnon-static declaration of '%D' follows "
"static declaration", newdecl, newdecl);
}
/* Two objects with the same name declared at the same block
scope must both be external references (6.7p3). */
- else if (!DECL_FILE_SCOPE_P (newdecl)
- && DECL_CONTEXT (newdecl) == DECL_CONTEXT (olddecl)
- && (!DECL_EXTERNAL (newdecl) || !DECL_EXTERNAL (olddecl)))
+ else if (!DECL_FILE_SCOPE_P (newdecl))
{
if (DECL_EXTERNAL (newdecl))
- error ("%Jextern declaration of '%D' follows "
- "declaration with no linkage", newdecl, newdecl);
+ abort ();
else if (DECL_EXTERNAL (olddecl))
error ("%Jdeclaration of '%D' with no linkage follows "
"extern declaration", newdecl, newdecl);
}
/* warnings */
- /* All decls must agree on a non-default visibility. */
- if (DECL_VISIBILITY (newdecl) != VISIBILITY_DEFAULT
- && DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT
+ /* All decls must agree on a visibility. */
+ if (DECL_VISIBILITY_SPECIFIED (newdecl) && DECL_VISIBILITY_SPECIFIED (olddecl)
&& DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
{
warning ("%Jredeclaration of '%D' with different visibility "
definition. */
&& !(TREE_CODE (newdecl) == FUNCTION_DECL
&& DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))
+ /* Don't warn about redundant redeclarations of builtins. */
+ && !(TREE_CODE (newdecl) == FUNCTION_DECL
+ && !DECL_BUILT_IN (newdecl)
+ && DECL_BUILT_IN (olddecl)
+ && !C_DECL_DECLARED_BUILTIN (olddecl))
/* Don't warn about an extern followed by a definition. */
&& !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl))
/* Don't warn about forward parameter decls. */
Currently, it can only be defined in the prototype. */
COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
- /* If either declaration has a nondefault visibility, use it. */
- if (DECL_VISIBILITY (olddecl) != VISIBILITY_DEFAULT)
- DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
+ /* Use visibility of whichever declaration had it specified */
+ if (DECL_VISIBILITY_SPECIFIED (olddecl))
+ {
+ DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
+ DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
+ }
if (TREE_CODE (newdecl) == FUNCTION_DECL)
{
&& (TREE_CODE (olddecl) == FUNCTION_DECL
|| (TREE_CODE (olddecl) == VAR_DECL
&& TREE_STATIC (olddecl))))
- make_decl_rtl (olddecl, NULL);
+ make_decl_rtl (olddecl);
}
/* Handle when a new declaration NEWDECL has the same name as an old
}
\f
-/* Check whether decl-node NEW shadows an existing declaration. */
+/* Check whether decl-node NEW_DECL shadows an existing declaration. */
static void
-warn_if_shadowing (tree new)
+warn_if_shadowing (tree new_decl)
{
struct c_binding *b;
/* Shadow warnings wanted? */
if (!warn_shadow
/* No shadow warnings for internally generated vars. */
- || DECL_IS_BUILTIN (new)
+ || DECL_IS_BUILTIN (new_decl)
/* No shadow warnings for vars made for inlining. */
- || DECL_FROM_INLINE (new)
+ || DECL_FROM_INLINE (new_decl)
/* Don't warn about the parm names in function declarator
within a function declarator. It would be nice to avoid
warning in any function declarator in a declaration, as
opposed to a definition, but there is no way to tell
it's not a definition at this point. */
- || (TREE_CODE (new) == PARM_DECL && current_scope->outer->parm_flag))
+ || (TREE_CODE (new_decl) == PARM_DECL && current_scope->outer->parm_flag))
return;
/* 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->invisible)
+ for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed)
+ if (b->decl && b->decl != new_decl && !b->invisible)
{
- tree old = b->decl;
+ tree old_decl = b->decl;
- if (TREE_CODE (old) == PARM_DECL)
- warning ("%Jdeclaration of '%D' shadows a parameter", new, new);
- else if (DECL_FILE_SCOPE_P (old))
+ if (TREE_CODE (old_decl) == PARM_DECL)
+ warning ("%Jdeclaration of '%D' shadows a parameter",
+ new_decl, new_decl);
+ else if (DECL_FILE_SCOPE_P (old_decl))
warning ("%Jdeclaration of '%D' shadows a global declaration",
- new, new);
- else if (TREE_CODE (old) == FUNCTION_DECL && DECL_BUILT_IN (old))
+ new_decl, new_decl);
+ else if (TREE_CODE (old_decl) == FUNCTION_DECL
+ && DECL_BUILT_IN (old_decl))
warning ("%Jdeclaration of '%D' shadows a built-in function",
- new, new);
+ new_decl, new_decl);
else
- warning ("%Jdeclaration of '%D' shadows a previous local", new, new);
+ warning ("%Jdeclaration of '%D' shadows a previous local",
+ new_decl, new_decl);
- if (TREE_CODE (old) != FUNCTION_DECL || !DECL_BUILT_IN (old))
- warning ("%Jshadowed declaration is here", old);
+ if (TREE_CODE (old_decl) != FUNCTION_DECL
+ || ! DECL_BUILT_IN (old_decl))
+ warning ("%Jshadowed declaration is here", old_decl);
break;
}
/* Functions need the lang_decl data. */
if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x))
- DECL_LANG_SPECIFIC (x) = ggc_alloc_cleared (sizeof (struct lang_decl));
+ DECL_LANG_SPECIFIC (x) = GGC_CNEW (struct lang_decl);
/* Must set DECL_CONTEXT for everything not at file scope or
DECL_FILE_SCOPE_P won't work. Local externs don't count
implicit_decl_warning (functionid, decl);
C_DECL_IMPLICIT (decl) = 1;
}
+ if (DECL_BUILT_IN (decl))
+ {
+ if (!comptypes (default_function_type, TREE_TYPE (decl)))
+ {
+ warning ("incompatible implicit declaration of built-in"
+ " function %qD", decl);
+ }
+ }
+ else
+ {
+ if (!comptypes (default_function_type, TREE_TYPE (decl)))
+ {
+ error ("incompatible implicit declaration of function %qD",
+ decl);
+ locate_old_decl (decl, error);
+ }
+ }
bind (functionid, decl, current_scope,
/*invisible=*/false, /*nested=*/true);
return decl;
decl = pushdecl (decl);
/* No need to call objc_check_decl here - it's a function type. */
- rest_of_decl_compilation (decl, NULL, 0, 0);
+ rest_of_decl_compilation (decl, 0, 0);
/* Write a record describing this implicit function declaration
to the prototypes file (if requested). */
tree
builtin_function (const char *name, tree type, int function_code,
- enum built_in_class class, const char *library_name,
+ enum built_in_class cl, const char *library_name,
tree attrs)
{
tree id = get_identifier (name);
tree decl = build_decl (FUNCTION_DECL, id, type);
TREE_PUBLIC (decl) = 1;
DECL_EXTERNAL (decl) = 1;
- DECL_LANG_SPECIFIC (decl) = ggc_alloc_cleared (sizeof (struct lang_decl));
- DECL_BUILT_IN_CLASS (decl) = class;
+ DECL_LANG_SPECIFIC (decl) = GGC_CNEW (struct lang_decl);
+ DECL_BUILT_IN_CLASS (decl) = cl;
DECL_FUNCTION_CODE (decl) = function_code;
if (library_name)
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (library_name));
shadow_tag_warned (declspecs, 0);
}
+/* WARNED is 1 if we have done a pedwarn, 2 if we have done a warning,
+ but no pedwarn. */
void
shadow_tag_warned (tree declspecs, int warned)
-
-
- /* 1 => we have done a pedwarn. 2 => we have done a warning, but
- no pedwarn. */
{
int found_tag = 0;
tree link;
/* Decode a "typename", such as "int **", returning a ..._TYPE node. */
tree
-groktypename (tree typename)
+groktypename (tree type_name)
{
tree specs, attrs;
- if (TREE_CODE (typename) != TREE_LIST)
- return typename;
+ if (TREE_CODE (type_name) != TREE_LIST)
+ return type_name;
- split_specs_attrs (TREE_PURPOSE (typename), &specs, &attrs);
+ split_specs_attrs (TREE_PURPOSE (type_name), &specs, &attrs);
- typename = grokdeclarator (TREE_VALUE (typename), specs, TYPENAME, 0,
+ type_name = grokdeclarator (TREE_VALUE (type_name), specs, TYPENAME, 0,
NULL);
/* Apply attributes. */
- decl_attributes (&typename, attrs, 0);
+ decl_attributes (&type_name, attrs, 0);
- return typename;
+ return type_name;
}
/* Return a PARM_DECL node for a given pair of specs and declarator. */
tree
-groktypename_in_parm_context (tree typename)
+groktypename_in_parm_context (tree type_name)
{
- if (TREE_CODE (typename) != TREE_LIST)
- return typename;
- return grokdeclarator (TREE_VALUE (typename),
- TREE_PURPOSE (typename),
+ if (TREE_CODE (type_name) != TREE_LIST)
+ return type_name;
+ return grokdeclarator (TREE_VALUE (type_name),
+ TREE_PURPOSE (type_name),
PARM, 0, NULL);
}
if (initialized)
{
- DECL_EXTERNAL (decl) = 0;
if (current_scope == file_scope)
TREE_STATIC (decl) = 1;
TEM may equal DECL or it may be a previous decl of the same name. */
tem = pushdecl (decl);
+ if (initialized)
+ DECL_EXTERNAL (tem) = 0;
+
return tem;
}
store_init_value (decl, init);
if (c_dialect_objc () && (TREE_CODE (decl) == VAR_DECL
- || TREE_CODE (decl) == FUNCTION_DECL
- || TREE_CODE (decl) == FIELD_DECL))
+ || TREE_CODE (decl) == FUNCTION_DECL
+ || TREE_CODE (decl) == FIELD_DECL))
objc_check_decl (decl);
/* Deduce size of array from initialization, if not already known. */
in the array, because we start counting at zero. Therefore,
warn only if the value is less than zero. */
else if (pedantic && TYPE_DOMAIN (type) != 0
- && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
+ && tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) < 0)
error ("%Jzero or negative size array '%D'", decl, decl);
layout_decl (decl, 0);
/* Don't give an error if we already gave one earlier. */
&& TREE_TYPE (decl) != error_mark_node
&& (TREE_STATIC (decl)
- ?
- /* A static variable with an incomplete type
- is an error if it is initialized.
- Also if it is not file scope.
- Otherwise, let it through, but if it is not `extern'
- then it may cause an error message later. */
- (DECL_INITIAL (decl) != 0
+ /* A static variable with an incomplete type
+ is an error if it is initialized.
+ Also if it is not file scope.
+ Otherwise, let it through, but if it is not `extern'
+ then it may cause an error message later. */
+ ? (DECL_INITIAL (decl) != 0
|| !DECL_FILE_SCOPE_P (decl))
- :
- /* An automatic variable with an incomplete type
- is an error. */
- !DECL_EXTERNAL (decl)))
- {
- error ("%Jstorage size of '%D' isn't known", decl, decl);
- TREE_TYPE (decl) = error_mark_node;
- }
+ /* An automatic variable with an incomplete type
+ is an error. */
+ : !DECL_EXTERNAL (decl)))
+ {
+ error ("%Jstorage size of '%D' isn't known", decl, decl);
+ TREE_TYPE (decl) = error_mark_node;
+ }
if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
&& DECL_SIZE (decl) != 0)
was a normal built-in. */
if (TREE_CODE (decl) == FUNCTION_DECL && asmspec)
{
- /* ASMSPEC is given, and not the name of a register. Mark the
- name with a star so assemble_name won't munge it. */
- char *starred = alloca (strlen (asmspec) + 2);
- starred[0] = '*';
- strcpy (starred + 1, asmspec);
-
if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL)
{
tree builtin = built_in_decls [DECL_FUNCTION_CODE (decl)];
- SET_DECL_RTL (builtin, NULL_RTX);
- change_decl_assembler_name (builtin, get_identifier (starred));
- 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);
- }
- SET_DECL_RTL (decl, NULL_RTX);
- change_decl_assembler_name (decl, get_identifier (starred));
+ set_user_assembler_name (builtin, asmspec);
+ if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMCPY)
+ init_block_move_fn (asmspec);
+ else if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MEMSET)
+ init_block_clear_fn (asmspec);
+ }
+ set_user_assembler_name (decl, asmspec);
}
/* If #pragma weak was used, mark the decl weak now. */
if (c_dialect_objc ())
objc_check_decl (decl);
+ if (asmspec)
+ {
+ /* If this is not a static variable, issue a warning.
+ It doesn't make any sense to give an ASMSPEC for an
+ ordinary, non-register local variable. Historically,
+ GCC has accepted -- but ignored -- the ASMSPEC in
+ this case. */
+ if (! DECL_FILE_SCOPE_P (decl)
+ && TREE_CODE (decl) == VAR_DECL
+ && !C_DECL_REGISTER (decl)
+ && !TREE_STATIC (decl))
+ warning ("%Jignoring asm-specifier for non-static local "
+ "variable '%D'", decl, decl);
+ else if (C_DECL_REGISTER (decl))
+ change_decl_assembler_name (decl, get_identifier (asmspec));
+ else
+ set_user_assembler_name (decl, asmspec);
+ }
+
if (DECL_FILE_SCOPE_P (decl))
{
if (DECL_INITIAL (decl) == NULL_TREE
when a tentative file-scope definition is seen.
But at end of compilation, do output code for them. */
DECL_DEFER_OUTPUT (decl) = 1;
- rest_of_decl_compilation (decl, asmspec, true, 0);
+ rest_of_decl_compilation (decl, true, 0);
}
else
{
- /* This is a local variable. If there is an ASMSPEC, the
- user has requested that we handle it specially. */
- if (asmspec)
+ /* In conjunction with an ASMSPEC, the `register'
+ keyword indicates that we should place the variable
+ in a particular register. */
+ if (asmspec && C_DECL_REGISTER (decl))
{
- /* In conjunction with an ASMSPEC, the `register'
- keyword indicates that we should place the variable
- in a particular register. */
- if (C_DECL_REGISTER (decl))
- {
- DECL_HARD_REGISTER (decl) = 1;
- /* This cannot be done for a structure with volatile
- fields, on which DECL_REGISTER will have been
- reset. */
- if (!DECL_REGISTER (decl))
- error ("cannot put object with volatile field into register");
- }
-
- /* If this is not a static variable, issue a warning.
- It doesn't make any sense to give an ASMSPEC for an
- ordinary, non-register local variable. Historically,
- GCC has accepted -- but ignored -- the ASMSPEC in
- this case. */
- if (TREE_CODE (decl) == VAR_DECL
- && !C_DECL_REGISTER (decl)
- && !TREE_STATIC (decl))
- warning ("%Jignoring asm-specifier for non-static local "
- "variable '%D'", decl, decl);
- else
- change_decl_assembler_name (decl, get_identifier (asmspec));
+ DECL_HARD_REGISTER (decl) = 1;
+ /* This cannot be done for a structure with volatile
+ fields, on which DECL_REGISTER will have been
+ reset. */
+ if (!DECL_REGISTER (decl))
+ error ("cannot put object with volatile field into register");
}
if (TREE_CODE (decl) != FUNCTION_DECL)
add_stmt (build_stmt (DECL_EXPR, decl));
}
+
if (!DECL_FILE_SCOPE_P (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);
+ rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
}
/* At the end of a declaration, throw away any variable type sizes
DECL_COMDAT (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
pushdecl (decl);
- rest_of_decl_compilation (decl, NULL, 1, 0);
+ rest_of_decl_compilation (decl, 1, 0);
}
return complit;
maxindex = fold (build (PLUS_EXPR, integer_type_node,
maxindex, integer_one_node));
}
- maxindex = copy_node (maxindex);
}
else
{
{
TYPE_DOMAIN (type) = build_index_type (maxindex);
if (!TREE_TYPE (maxindex))
- TREE_TYPE (maxindex) = TYPE_DOMAIN (type);
+ abort ();
}
/* Lay out the type now that we can get the real answer. */
decl = build_decl_attribute_variant (decl, decl_attr);
DECL_LANG_SPECIFIC (decl)
- = ggc_alloc_cleared (sizeof (struct lang_decl));
+ = GGC_CNEW (struct lang_decl);
if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl))
pedwarn ("ISO C forbids qualified function types");
if (inlinep)
pedwarn ("%Jvariable '%D' declared `inline'", decl, decl);
- DECL_EXTERNAL (decl) = extern_ref;
+ /* At file scope, an initialized extern declaration may follow
+ a static declaration. In that case, DECL_EXTERNAL will be
+ reset later in start_decl. */
+ DECL_EXTERNAL (decl) = !!(specbits & (1 << (int) RID_EXTERN));
/* At file scope, the presence of a `static' or `register' storage
class specifier, or the absence of all storage class specifiers
ensure that this lives as long as the rest of the struct decl.
All decls in an inline function need to be saved. */
- space = ggc_alloc_cleared (sizeof (struct lang_type));
- space2 = ggc_alloc (sizeof (struct sorted_fields_type) + len * sizeof (tree));
+ space = GGC_CNEW (struct lang_type);
+ space2 = GGC_NEWVAR (struct sorted_fields_type,
+ sizeof (struct sorted_fields_type) + len * sizeof (tree));
len = 0;
space->s = space2;
layout_decl (decl, 0);
if (c_dialect_objc ())
objc_check_decl (decl);
- rest_of_decl_compilation (decl, NULL, toplevel, 0);
+ rest_of_decl_compilation (decl, toplevel, 0);
if (! toplevel)
expand_decl (decl);
}
/* Record the min/max values so that we can warn about bit-field
enumerations that are too small for the values. */
- lt = ggc_alloc_cleared (sizeof (struct lang_type));
+ lt = GGC_CNEW (struct lang_type);
lt->enum_min = minnode;
lt->enum_max = maxnode;
TYPE_LANG_SPECIFIC (enumtype) = lt;
start_function (tree declspecs, tree declarator, tree attributes)
{
tree decl1, old_decl;
- tree restype;
+ tree restype, resdecl;
current_function_returns_value = 0; /* Assume, until we see it does. */
current_function_returns_null = 0;
else
restype = integer_type_node;
}
- DECL_RESULT (current_function_decl)
- = build_decl (RESULT_DECL, NULL_TREE, restype);
+
+ resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
+ DECL_ARTIFICIAL (resdecl) = 1;
+ DECL_IGNORED_P (resdecl) = 1;
+ DECL_RESULT (current_function_decl) = resdecl;
start_fname_decls ();
c_push_function_context (struct function *f)
{
struct language_function *p;
- p = ggc_alloc (sizeof (struct language_function));
+ p = GGC_NEW (struct language_function);
f->language = p;
p->base.x_stmt_tree = c_stmt_tree;
if (!DECL_LANG_SPECIFIC (decl))
return;
- ld = ggc_alloc (sizeof (struct lang_decl));
+ ld = GGC_NEW (struct lang_decl);
memcpy (ld, DECL_LANG_SPECIFIC (decl), sizeof (struct lang_decl));
DECL_LANG_SPECIFIC (decl) = ld;
}
void
record_builtin_type (enum rid rid_index, const char *name, tree type)
{
- tree id;
+ tree id, decl;
if (name == 0)
id = ridpointers[(int) rid_index];
else
id = get_identifier (name);
- pushdecl (build_decl (TYPE_DECL, id, type));
+ decl = build_decl (TYPE_DECL, id, type);
+ pushdecl (decl);
+ if (debug_hooks->type_decl)
+ debug_hooks->type_decl (decl, false);
}
/* Build the void_list_node (void_type_node having been created). */
c_write_global_declarations_1 (tree globals)
{
size_t len = list_length (globals);
- tree *vec = xmalloc (sizeof (tree) * len);
+ tree *vec = XNEWVEC (tree, len);
size_t i;
tree decl;