This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++: vtable thunks


This update to the vtable thunks code implements all of Mark's
suggestion; -fvtable-thunks takes a numeric argument, and gxxint.texi
explains virtual tables in detail. On Linux, -fvtable-thunks has no
effect (as it does now); the default version is 1. On all other
platforms, -fvtable-thunks switches from 0 to 2. To get the new
behaviour on Linux as well, -fvtable-thunks=2 is necessary.

This patch work with egcs-2.93.20 19990501; adjustments were necessary
after Mark changed the vtable generation procedures.

Jason, will this go into 1.2?

Regards,
Martin

Sun May  2 08:49:27 1999  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* invoke.texi (-fvtable-thunks): Document numeric argument.

1999-05-02  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* class.c (prepare_ctor_vtable, finish_one_ctor_vtable,
	prepend_ctor_vfields_for_vbase, finish_ctor_vtables_for_vbases,
	finish_ctor_vtables_1, prepend_vbase_vfields,
	finish_ctor_vtables): New functions.
	(finish_struct_1): Call finish_ctor_vtables.

	* cp-tree.h (TYPE_USES_PVBASES): New macro.
	(constructor_for_vbase_attr): Widen to two bits.
	(CONSTRUCTOR_FOR_VBASE, CONSTRUCTOR_FOR_PVBASE,
	DESTRUCTOR_FOR_PVBASE): New macros.
	(DECL_CONSTRUCTOR_FOR_VBASE_P): Adopt to new enumeration.
	(DECL_CONSTRUCTOR_FOR_VBASE): New macro.
	(DECL_CONSTRUCTOR_FOR_PVBASE_P, DECL_DESTRUCTOR_FOR_PVBASE_P): New
	macros.
	(vlist_identifier, vlist_type_node, vlist_zero_node): Declare.
	(VCTABLE_NAME, VLIST_NAME_FORMAT, VLIST_NAME, VLIST1_NAME,
	VLIST_TYPE_NAME): New macros.
	(LOOKUP_HAS_VLIST): New macro.
	(build_base_dtor_call, init_vlist): Declare.
	(build_destructor_name): Add int argument.

	* decl.c (vlist_identifier, vlist_type_node, vlist_zero_node):
	Define.
	(init_decl_processing): Initialize them.
	(grokdeclarator): Handle vlist argument.
	(copy_args_p): Likewise.
	(grok_ctor_properties): Don't try to skip initial int for
	templates.  Skip vlist if available.
	(xref_basetypes): Set TYPE_USES_PVBASES.
	(finish_dtor, finish_ctor): New functions, moved out of ...
	(finish_function): ... here.

	* decl2.c (lang_decode_option): Set flag_vtable_thunks explicitly.
	(maybe_retrofit_in_chrg): Retrofit __vlist parameter.
	(grokclassfn): Pass pvbase flag into mangled name.

	* init.c (build_base_dtor_call): New function.
	(build_partial_cleanup_for): Call it.
	(pvbasecount, init_vlist, ): New functions.
	(emit_base_init): Process vlist argument.
	(expand_aggr_vbase_init_1): Likewise.
	(expand_aggr_vbase_init): Likewise.
	(expand_default_init): Likewise.
	(build_new_1): Pass null vlist argument.
	(build_delete): Likewise. Call build_base_dtor_call.

	* method.c (process_overload_item): Mangle _Vlist specially.
	(build_base_path, get_vlist_vtable_id): New functions.
	(build_destructor_name): Potentially mangle _Vlist into it.
	(do_build_copy_constructor): Skip vlist argument.
	(synthesize_method): Likewise.

	* pt.c (has_pvbases_p): New function.
	(instantiate_class_template): Call it.
	(tsubst_decl): Retrofit before mangling. Pass pvbase_p to
	destructor mangling.

	* search.c (expand_direct_vtbls_init_thunks): New function.
	(expand_indirect_vtbls_init_thunks): New function.
	(expand_indirect_vtbls_init): Call it.

	* call.c (add_function_candidate): Process vlist argument.
	(build_user_type_conversion_1): Add vlist argument.
	(convert_like): Likewise.
	(build_over_call): Likewise.
	(build_new_method_call): Likewise.

Index: invoke.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/invoke.texi,v
retrieving revision 1.110
diff -u -r1.110 invoke.texi
--- invoke.texi	1999/04/26 00:54:45	1.110
+++ invoke.texi	1999/05/02 06:38:25
@@ -1151,7 +1151,7 @@
 type @samp{X *}.  However, for backwards compatibility, you can make it
 valid with @samp{-fthis-is-variable}.
 
-@item -fvtable-thunks
+@item -fvtable-thunks=@var{thunks-version}
 Use @samp{thunks} to implement the virtual function dispatch table
 (@samp{vtable}).  The traditional (cfront-style) approach to
 implementing vtables was to store a pointer to the function and two
@@ -1159,13 +1159,25 @@
 implementations store a single pointer to a @samp{thunk} function which
 does any necessary adjustment and then calls the target function.
 
+The original implementation of thunks (version 1) had a bug regarding
+virtual base classes; this bug is fixed with version 2 of the thunks
+implementation.
+
 This option also enables a heuristic for controlling emission of
 vtables; if a class has any non-inline virtual functions, the vtable
 will be emitted in the translation unit containing the first one of
 those.
 
 Like all options that change the ABI, all C++ code, @emph{including
-libgcc.a} must be built with the same setting of this option.
+libgcc.a} must be built with the same setting of this option. Since
+version 1 and version 2 are also incompatible (for classes with virtual
+bases defining virtual functions), all code must also be compiled with
+the same version.
+
+On some targets (e.g. Linux), version 1 thunks are the default. On these
+targets, no option or -fvtable-thunks will produce version 1 thunks. On
+all other targets, not giving the option will use the traditional
+implementation, and -fvtable-thunks will produce version 2 thunks.
 
 @item -nostdinc++
 Do not search for header files in the standard directories specific to

v2thunks-990502.bz2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]