re PR c/15007 (crash when including precompiled header with -include)

PR 15007
	* c-decl.c (current_file_decl): Rename to all_translation_units,
	adjust comment.
	(pop_scope): If popping file_scope, construct a
	TRANSLATION_UNIT_DECL and make it the context of all the
	symbols in the scope.
	(push_file_scope): Don't construct a TRANSLATION_UNIT_DECL here.
	(pushdecl): Clarify comment.  Do not set DECL_CONTEXT of
	anything to current_file_decl.
	(pushdecl_top_level): Likewise.
	(store_parm_decls_newstyle): Adjust check for nested function.
	(c_write_global_declarations): Update for renamed variable.

From-SVN: r81655
This commit is contained in:
Zack Weinberg 2004-05-09 21:26:58 +00:00 committed by Zack Weinberg
parent eb01299a99
commit eecec6986c
2 changed files with 37 additions and 18 deletions

View File

@ -1,3 +1,18 @@
2004-05-09 Zack Weinberg <zack@codesourcery.com>
PR 15007
* c-decl.c (current_file_decl): Rename to all_translation_units,
adjust comment.
(pop_scope): If popping file_scope, construct a
TRANSLATION_UNIT_DECL and make it the context of all the
symbols in the scope.
(push_file_scope): Don't construct a TRANSLATION_UNIT_DECL here.
(pushdecl): Clarify comment. Do not set DECL_CONTEXT of
anything to current_file_decl.
(pushdecl_top_level): Likewise.
(store_parm_decls_newstyle): Adjust check for nested function.
(c_write_global_declarations): Update for renamed variable
.
2004-05-09 Aldy Hernandez <aldyh@redhat.com> 2004-05-09 Aldy Hernandez <aldyh@redhat.com>
* config/rs6000/rs6000-protos.h * config/rs6000/rs6000-protos.h
@ -44,7 +59,7 @@
Generate appropriate parallels for vector arguments Generate appropriate parallels for vector arguments
passed to vararg functions. (function_arg): make the call passed to vararg functions. (function_arg): make the call
to rs6000_mixed_function_arg for vector args as needed. to rs6000_mixed_function_arg for vector args as needed.
2004-05-07 Richard Sandiford <rsandifo@redhat.com> 2004-05-07 Richard Sandiford <rsandifo@redhat.com>
* config/mips/mips.c (mips_va_arg): Fix calculation of osize for * config/mips/mips.c (mips_va_arg): Fix calculation of osize for

View File

@ -108,9 +108,11 @@ static GTY(()) tree c_scope_stmt_stack;
int c_in_iteration_stmt; int c_in_iteration_stmt;
int c_in_case_stmt; int c_in_case_stmt;
/* A DECL for the current file-scope context. */ /* Linked list of TRANSLATION_UNIT_DECLS for the translation units
included in this invocation. Note that the current translation
unit is not included in this list. */
static GTY(()) tree current_file_decl; static GTY(()) tree all_translation_units;
/* A list of decls to be made automatically visible in each file scope. */ /* A list of decls to be made automatically visible in each file scope. */
static GTY(()) tree visible_builtins; static GTY(()) tree visible_builtins;
@ -649,7 +651,12 @@ pop_scope (void)
if (scope->function_body) if (scope->function_body)
context = current_function_decl; context = current_function_decl;
else if (scope == file_scope) else if (scope == file_scope)
context = current_file_decl; {
tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
TREE_CHAIN (file_decl) = all_translation_units;
all_translation_units = file_decl;
context = file_decl;
}
else else
context = block; context = block;
@ -736,6 +743,9 @@ pop_scope (void)
TREE_CHAIN (p) = BLOCK_VARS (block); TREE_CHAIN (p) = BLOCK_VARS (block);
BLOCK_VARS (block) = p; 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;
/* Fall through. */ /* Fall through. */
/* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have /* Parameters go in DECL_ARGUMENTS, not BLOCK_VARS, and have
@ -795,9 +805,6 @@ void
push_file_scope (void) push_file_scope (void)
{ {
tree decl; tree decl;
tree file_decl = build_decl (TRANSLATION_UNIT_DECL, 0, 0);
TREE_CHAIN (file_decl) = current_file_decl;
current_file_decl = file_decl;
push_scope (); push_scope ();
file_scope = current_scope; file_scope = current_scope;
@ -1796,14 +1803,12 @@ pushdecl (tree x)
if (TREE_CODE (x) == FUNCTION_DECL && ! DECL_LANG_SPECIFIC (x)) 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_alloc_cleared (sizeof (struct lang_decl));
/* A local extern declaration for a function doesn't constitute nesting. /* Must set DECL_CONTEXT for everything not at file scope or
A local auto declaration does, since it's a forward decl DECL_FILE_SCOPE_P won't work. Local externs don't count
for a nested function coming later. */ unless they have initializers (which generate code). */
if (current_function_decl == NULL if (current_function_decl
|| ((TREE_CODE (x) == FUNCTION_DECL || TREE_CODE (x) == VAR_DECL) && ((TREE_CODE (x) != FUNCTION_DECL && TREE_CODE (x) != VAR_DECL)
&& DECL_INITIAL (x) == 0 && DECL_EXTERNAL (x))) || DECL_INITIAL (x) || !DECL_EXTERNAL (x)))
DECL_CONTEXT (x) = current_file_decl;
else
DECL_CONTEXT (x) = current_function_decl; DECL_CONTEXT (x) = current_function_decl;
/* Anonymous decls are just inserted in the scope. */ /* Anonymous decls are just inserted in the scope. */
@ -1927,7 +1932,6 @@ pushdecl_top_level (tree x)
if (I_SYMBOL_BINDING (name)) if (I_SYMBOL_BINDING (name))
abort (); abort ();
DECL_CONTEXT (x) = current_file_decl;
if (DECL_EXTERNAL (x) || TREE_PUBLIC (x)) if (DECL_EXTERNAL (x) || TREE_PUBLIC (x))
{ {
C_DECL_IN_EXTERNAL_SCOPE (x) = 1; C_DECL_IN_EXTERNAL_SCOPE (x) = 1;
@ -5825,7 +5829,7 @@ store_parm_decls_newstyle (tree fndecl, tree arg_info)
(this happens when a function definition has just an ellipsis in (this happens when a function definition has just an ellipsis in
its parameter list). */ its parameter list). */
else if (warn_traditional && !in_system_header else if (warn_traditional && !in_system_header
&& DECL_CONTEXT (fndecl) == current_file_decl && !current_scope->outer_function
&& ARG_INFO_TYPES (arg_info) != error_mark_node) && ARG_INFO_TYPES (arg_info) != error_mark_node)
warning ("%Jtraditional C rejects ISO C style function definitions", warning ("%Jtraditional C rejects ISO C style function definitions",
fndecl); fndecl);
@ -6625,7 +6629,7 @@ c_write_global_declarations (void)
return; return;
/* Process all file scopes in this compilation. */ /* Process all file scopes in this compilation. */
for (t = current_file_decl; t; t = TREE_CHAIN (t)) for (t = all_translation_units; t; t = TREE_CHAIN (t))
c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t))); c_write_global_declarations_1 (BLOCK_VARS (DECL_INITIAL (t)));
/* Now do the same for the externals scope. */ /* Now do the same for the externals scope. */