--- p/declarations.c.orig Sun Jul 4 16:19:41 2004 +++ p/declarations.c Fri Jul 9 20:49:18 2004 @@ -1161,15 +1161,13 @@ return t; } -/* Generate a unique identifier of the form `foo_42'. - Note: The first parameter must not be longer than 200 chars! */ +/* Generate a unique identifier of the form `foo_42'. */ tree get_unique_identifier (template) const char *template; { static int idcount = 0; - char idbuf [256]; /* No buffer overflow problem here because template - is a compiler-supplied constant of limited length. */ + char *idbuf = alloca (strlen (template) + 20); assert (*template >= 'a' && *template <= 'z'); sprintf (idbuf, "%s_%d", template, idcount++); return get_identifier (idbuf); @@ -3032,6 +3030,15 @@ for (v = name_list; v; v = TREE_CHAIN (v)) { tree value; + int local_static = !pascal_global_bindings_p () && (qualifiers & VQ_STATIC) + && !(qualifiers & VQ_EXTERNAL); /* cf. local_static_variables */ +#ifndef EGCS97 + if (local_static) + { + push_obstacks_nochange (); + end_temporary_allocation (); + } +#endif d = build_decl (VAR_DECL, TREE_VALUE (v), type); TREE_USED (d) = TREE_USED (type); DECL_CONTEXT (d) = current_function_decl; @@ -3054,7 +3061,9 @@ TREE_PUBLIC (d) = DECL_EXTERNAL (d); DECL_COMMON (d) = !TREE_PUBLIC (d); SET_DECL_ASSEMBLER_NAME (d, assembler_name ? check_assembler_name (assembler_name) - : (qualifiers & VQ_EXTERNAL) ? de_capitalize (TREE_VALUE (v)) : TREE_VALUE (v)); + : (qualifiers & VQ_EXTERNAL) ? de_capitalize (TREE_VALUE (v)) + : local_static ? get_unique_identifier (ACONCAT (("static_", IDENTIFIER_POINTER (TREE_VALUE (v)), NULL))) + : TREE_VALUE (v)); pascal_decl_attributes (&d, attributes); if (DECL_EXTERNAL (d) || TREE_STATIC (d)) { @@ -3091,6 +3100,9 @@ d = pushdecl (d); assert (!EM (d)); + if (local_static) + DECL_CONTEXT (d) = NULL_TREE; + /* Output the assembler code and/or RTL code. */ rest_of_decl_compilation (d, NULL, !DECL_CONTEXT (d), 1 /* for GPC */); @@ -3105,6 +3117,11 @@ if (!(qualifiers & VQ_IMPLICIT)) handle_autoexport (TREE_VALUE (v)); +#ifndef EGCS97 + if (local_static) + pop_obstacks (); +#endif + res = tree_cons (NULL_TREE, d, res); } /* At the end of a declaration, throw away any variable type sizes @@ -3125,8 +3142,7 @@ } /* Create and return a new variable of type TYPE with a name constructed - from template + unique number. - Note: The first parameter must not be longer than 200 chars! */ + from template + unique number. */ tree make_new_variable (name_template, type) const char *name_template; --- p/statements.c.orig Sun Jul 4 16:19:42 2004 +++ p/statements.c Fri Jul 9 18:19:14 2004 @@ -1008,19 +1008,8 @@ push_obstacks_nochange (); end_temporary_allocation (); #endif - /* Defer local static variables to the global con-/destructors. - We can't keep the actual declarations since their DECL_CONTEXT - will be invalid then, and just setting the context to NULL_TREE - causes other problems. So we keep the assembler name and type - and build an external declaration later. */ - local_static_variables = tree_cons ( -#ifdef EGCS97 - DECL_ASSEMBLER_NAME (t), -#else - /* gcc-2 doesn't update DECL_ASSEMBLER_NAME when it sets a private name in make_decl_rtl. */ - get_identifier (XSTR (XEXP (DECL_RTL (t), 0), 0)), -#endif - TREE_TYPE (t), local_static_variables); + /* Defer local static variables to the global con-/destructors. */ + local_static_variables = tree_cons (NULL_TREE, t, local_static_variables); #ifndef EGCS97 pop_obstacks (); } @@ -1029,9 +1018,7 @@ } if (global) for (decl = local_static_variables; decl; decl = TREE_CHAIN (decl)) - init_any (TREE_VALUE (declare_variables (build_tree_list (NULL_TREE, TREE_PURPOSE (decl)), - TREE_VALUE (decl), NULL_TREE, VQ_EXTERNAL | VQ_IMPLICIT, - build_tree_list (get_identifier ("Name"), TREE_PURPOSE (decl)))), the_end); + init_any (TREE_VALUE (decl), the_end); } /* source is NULL_TREE in a call statement */