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++: Fixing vtable thunks


This patch fixes the old bug in vtable thunks, related to polymorphic
vbases. I consider this patch complete, and would like to see it
included in egcs 1.2. Compared to the previous version of this patch,
it now emits vtable lists using the same heuristics used for vtables
themselves (using import_export and finish_vtable_vardecl). It also
documents the new ABI in gxxint.texi.

The patch adds a new flag to cc1plus, -fv1-thunks. It defaults to the
same setting as -fvtable-thunks. No other default setting is changed,
so by default, this patch does not affect code generation at all (this
is easily seen since all code tests for TYPE_USES_PVBASES, and this
bit is only set when v2 thunks are requested). The new behaviour can
be activated either with -fnew-abi, or with -fvtable-thunks
-fno-v1-thunks.

With that patch, users of egcs 1.2 on Linux have the choice of either
working around the bug, or recompiling all C++ code with
-fno-v1-thunks. Currently, they can only work-around. I suggested that
a binary compatibility extension is possible, but I won't finish this
in time for egcs 1.2 (I haven't even started).

This patch passes the testsuite with v2 thunks enabled on
i586-pc-linux-gnu (with one unexpected pass) and
sparc-sun-solaris2.5.1. With standard settings, I only ran the
testsuite on Solaris. There seems to be one unrelated failure on
Solaris at the moment.

Mark, Jason, what do you think?

Martin

Sat Apr 17 23:16:33 1999  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* invoke.texi: Document -fv1-thunks.

1999-04-17  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 (flag_v1_thunks): Declare.
	(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 (flag_v1_thunks): Define.
	(lang_f_options): Add v1-thunks.
	(lang_decode_option): Reset flag_v1_thunks for new-abi.
	(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.

	* lang-options.h: New flag v1-thunks.

	* 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.106
diff -u -p -r1.106 invoke.texi
--- invoke.texi	1999/04/14 05:34:37	1.106
+++ invoke.texi	1999/04/17 20:47:04
@@ -108,8 +108,8 @@ in the following sections.
 -fhonor-std -fhuge-objects  -fno-implicit-templates  -finit-priority
 -fno-implement-inlines -fname-mangling-version-@var{n}  -fno-default-inline  
 -foperator-names  -fno-optional-diags  -frepo  -fstrict-prototype
--fsquangle  -ftemplate-depth-@var{n}  -fthis-is-variable  -fvtable-thunks
--nostdinc++  -Wctor-dtor-privacy -Wno-deprecated -Weffc++  
+-fsquangle  -ftemplate-depth-@var{n}  -fthis-is-variable  -fv1-thunks 
+-fvtable-thunks -nostdinc++  -Wctor-dtor-privacy -Wno-deprecated -Weffc++  
 -Wno-non-template-friend 
 -Wnon-virtual-dtor  -Wold-style-cast  -Woverloaded-virtual  
 -Wno-pmf-conversions  -Wreorder  -Wsign-promo  -Wsynth
@@ -1149,6 +1149,14 @@ anachronism.  Therefore, by default it i
 @samp{this} in a member function of class @code{X} as a non-lvalue of
 type @samp{X *}.  However, for backwards compatibility, you can make it
 valid with @samp{-fthis-is-variable}.
+
+@item -fv1-thunks
+Make @samp{thunks} implementation compatible with version 1 of vtable
+thunks (used e.g. in gcc 2.8 and egcs 1.1 on Linux). The original
+implementation had limitations in the area of virtual bases (see
+gxxint.texi for details). Version 2 fixes these problems, at the expense
+of binary compatibility. Use this option to produce the older version
+of thunks.
 
 @item -fvtable-thunks
 Use @samp{thunks} to implement the virtual function dispatch table

v2thunks.gz


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