g++.bob/static1.C
Zack Weinberg
zack@codesourcery.com
Wed Oct 24 01:21:00 GMT 2001
On Tue, Oct 23, 2001 at 08:13:41AM -0700, Mark Mitchell wrote:
>
> >This was introduced by the patch in
> > http://gcc.gnu.org/ml/gcc-patches/1999-09n/msg00782.html which is
> >trying to enforce a distinction between poplevel and poplevel_class.
> >(I do not see why this is desirable.)
>
> This was done to avoid a semi-common bug in the C++ front end: popping
> a class binding level when you meant to be popping an ordinary binding
> level. It sounds like one solution is to create a new callback, called
> pop_all_binding_levels, which defaults to calling poplevel(0, 0, 0)
> repeatedly, but in the C++ front-end is pop_everything.
This patch does just that. I considered cleaning up a bit - both C
and C++ currently pop all binding levels in several other places on
the way out of the parser - but decided just to fix the current
problem.
Bootstrapped i686-linux; the difference in testsuite results is
-FAIL: g++.dg/parse/saved1.C (test for excess errors)
-FAIL: g++.bob/static1.C (test for excess errors)
+FAIL: g77.f-torture/compile/20010519-1.f, -O1
The new Fortran failure is an ICE in alloc_aux_for_edge (cfg.c:649)
and I do not believe it is a consequence of this patch. I've updated
again and will run another build to see if it's a transient glitch.
Why is struct lang_hooks in toplev.h instead of langhooks.h?
zw
* langhooks.c (lang_hook_default_clear_binding_stack): New.
(lang_hook_default_get_alias_set): Move next to other alias
hooks.
* langhooks.h: Prototype lang_hook_default_clear_binding_stack.
(LANG_HOOKS_CLEAR_BINDING_STACK): New macro.
(LANG_HOOKS_INITIALIZER): Add it.
* toplev.h (struct lang_hooks): Add clear_binding_stack.
* toplev.c (compile_file): Call lang_hooks.clear_binding_stack
instead of a loop calling poplevel.
cp:
* cp-lang.c: Redefine LANG_HOOKS_CLEAR_BINDING_STACK to
pop_everything.
===================================================================
Index: langhooks.c
--- langhooks.c 2001/10/23 18:51:08 1.5
+++ langhooks.c 2001/10/24 08:16:50
@@ -36,16 +36,6 @@ lang_hook_default_do_nothing ()
{
}
-/* Provide a default routine for alias sets that always returns -1. This
- is used by languages that don't need to do anything special. */
-
-HOST_WIDE_INT
-lang_hook_default_get_alias_set (t)
- tree t ATTRIBUTE_UNUSED;
-{
- return -1;
-}
-
/* Do nothing; the default hook to decode an option. */
int
@@ -54,6 +44,25 @@ lang_hook_default_decode_option (argc, a
char **argv ATTRIBUTE_UNUSED;
{
return 0;
+}
+
+/* Provide a default routine to clear the binding stack. This is used
+ by languages that don't need to do anything special. */
+void
+lang_hook_default_clear_binding_stack ()
+{
+ while (! global_bindings_p ())
+ poplevel (0, 0, 0);
+}
+
+/* Provide a default routine for alias sets that always returns -1. This
+ is used by languages that don't need to do anything special. */
+
+HOST_WIDE_INT
+lang_hook_default_get_alias_set (t)
+ tree t ATTRIBUTE_UNUSED;
+{
+ return -1;
}
/* Provide a hook routine for alias sets that always returns 0. This is
===================================================================
Index: langhooks.h
--- langhooks.h 2001/10/23 18:51:08 1.4
+++ langhooks.h 2001/10/24 08:16:50
@@ -38,9 +38,11 @@ extern HOST_WIDE_INT hook_get_alias_set_
extern void lang_hook_default_do_nothing PARAMS ((void));
extern int lang_hook_default_decode_option PARAMS ((int, char **));
extern HOST_WIDE_INT lang_hook_default_get_alias_set PARAMS ((tree));
+extern void lang_hook_default_clear_binding_stack PARAMS ((void));
#define LANG_HOOKS_INIT lang_hook_default_do_nothing
#define LANG_HOOKS_FINISH lang_hook_default_do_nothing
+#define LANG_HOOKS_CLEAR_BINDING_STACK lang_hook_default_clear_binding_stack
#define LANG_HOOKS_INIT_OPTIONS lang_hook_default_do_nothing
#define LANG_HOOKS_DECODE_OPTION lang_hook_default_decode_option
#define LANG_HOOKS_POST_OPTIONS lang_hook_default_do_nothing
@@ -99,6 +101,7 @@ int tree_inlining_default_hook_anon_aggr
#define LANG_HOOKS_INITIALIZER { \
LANG_HOOKS_INIT, \
LANG_HOOKS_FINISH, \
+ LANG_HOOKS_CLEAR_BINDING_STACK, \
LANG_HOOKS_INIT_OPTIONS, \
LANG_HOOKS_DECODE_OPTION, \
LANG_HOOKS_POST_OPTIONS, \
===================================================================
Index: toplev.c
--- toplev.c 2001/10/23 13:34:23 1.525
+++ toplev.c 2001/10/24 08:16:51
@@ -2334,8 +2334,7 @@ compile_file (name)
/* In case there were missing block closers,
get us back to the global binding level. */
- while (! global_bindings_p ())
- poplevel (0, 0, 0);
+ (*lang_hooks.clear_binding_stack) ();
/* Compilation is now finished except for writing
what's left of the symbol table output. */
===================================================================
Index: toplev.h
--- toplev.h 2001/10/23 18:51:13 1.78
+++ toplev.h 2001/10/24 08:16:51
@@ -149,6 +149,9 @@ struct lang_hooks
/* Called last, as a finalizer. */
void (*finish) PARAMS ((void));
+ /* Called immediately after parsing to clear the binding stack. */
+ void (*clear_binding_stack) PARAMS ((void));
+
/* Called to initialize options, before any calls to decode_option. */
void (*init_options) PARAMS ((void));
===================================================================
Index: cp/cp-lang.c
--- cp/cp-lang.c 2001/10/23 18:50:16 1.2
+++ cp/cp-lang.c 2001/10/24 08:16:52
@@ -32,6 +32,8 @@ static HOST_WIDE_INT cxx_get_alias_set P
#define LANG_HOOKS_INIT cxx_init
#undef LANG_HOOKS_FINISH
#define LANG_HOOKS_FINISH cxx_finish
+#undef LANG_HOOKS_CLEAR_BINDING_STACK
+#define LANG_HOOKS_CLEAR_BINDING_STACK pop_everything
#undef LANG_HOOKS_INIT_OPTIONS
#define LANG_HOOKS_INIT_OPTIONS cxx_init_options
#undef LANG_HOOKS_DECODE_OPTION
More information about the Gcc-patches
mailing list