From: Jason Merrill Date: Mon, 21 May 2001 15:55:40 +0000 (-0400) Subject: class.c (build_vtable_entry_ref): Lose vtbl parm. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=90ecce3e49d93a4e39e8ec93038eb335515e35ad;p=gcc.git class.c (build_vtable_entry_ref): Lose vtbl parm. * class.c (build_vtable_entry_ref): Lose vtbl parm. Fix for new abi. (build_vtbl_ref): Adjust. (dfs_accumulate_vtbl_inits): Set TREE_CONSTANT on the vtable address. * decl2.c (lang_f_options): Remove huge-objects, vtable-thunks. Re-add vtable-gc. (unsupported_options): Correspondingly. * decl2.c (maybe_make_one_only): Check flag_weak, not supports_one_only(). From-SVN: r42393 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 55427d6674b..eda85ecfa41 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,15 @@ 2001-05-21 Jason Merrill + * class.c (build_vtable_entry_ref): Lose vtbl parm. Fix for new abi. + (build_vtbl_ref): Adjust. + (dfs_accumulate_vtbl_inits): Set TREE_CONSTANT on the vtable address. + * decl2.c (lang_f_options): Remove huge-objects, vtable-thunks. + Re-add vtable-gc. + (unsupported_options): Correspondingly. + + * decl2.c (maybe_make_one_only): Check flag_weak, not + supports_one_only(). + * cp-tree.def (START_CATCH_STMT): Lose. * dump.c (cp_dump_tree): Don't dump it. Do dump HANDLER_PARMS. * tree.c (cp_statement_code_p): Don't case it. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 52c43c38ba3..4566200f3ac 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -136,7 +136,7 @@ static tree add_implicitly_declared_members PARAMS ((tree, int, int, int)); static tree fixed_type_or_null PARAMS ((tree, int *, int *)); static tree resolve_address_of_overloaded_function PARAMS ((tree, tree, int, int, int, tree)); -static void build_vtable_entry_ref PARAMS ((tree, tree, tree)); +static void build_vtable_entry_ref PARAMS ((tree, tree)); static tree build_vtbl_initializer PARAMS ((tree, tree, tree, tree, int *)); static int count_fields PARAMS ((tree)); static int add_fields_to_vec PARAMS ((tree, tree, int)); @@ -518,22 +518,20 @@ build_vbase_path (code, type, expr, path, nonnull) "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */ static void -build_vtable_entry_ref (basetype, vtbl, idx) - tree basetype, vtbl, idx; +build_vtable_entry_ref (basetype, idx) + tree basetype, idx; { static char asm_stmt[] = ".vtable_entry %c0, %c1"; tree s, i, i2; + tree vtable = get_vtbl_decl_for_binfo (TYPE_BINFO (basetype)); + tree first_fn = TYPE_BINFO_VTABLE (basetype); - s = build_unary_op (ADDR_EXPR, - get_vtbl_decl_for_binfo (TYPE_BINFO (basetype)), - 0); + s = build_unary_op (ADDR_EXPR, vtable, 0); s = build_tree_list (build_string (1, "s"), s); - i = build_array_ref (vtbl, idx); - if (!flag_vtable_thunks) - i = build_component_ref (i, pfn_identifier, vtable_entry_type, 0); + i = build_array_ref (first_fn, idx); i = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i, 0)); - i2 = build_array_ref (vtbl, build_int_2(0,0)); + i2 = build_array_ref (vtable, build_int_2 (0,0)); i2 = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i2, 0)); i = cp_build_binary_op (MINUS_EXPR, i, i2); i = build_tree_list (build_string (1, "i"), i); @@ -621,7 +619,7 @@ build_vtbl_ref (instance, idx) assemble_external (vtbl); if (flag_vtable_gc) - build_vtable_entry_ref (basetype, vtbl, idx); + build_vtable_entry_ref (basetype, idx); aref = build_array_ref (vtbl, idx); @@ -726,13 +724,13 @@ build_vtable (class_type, name, vtable_type) tree decl; decl = build_lang_decl (VAR_DECL, name, vtable_type); + /* vtable names are already mangled; give them their DECL_ASSEMBLER_NAME + now to avoid confusion in mangle_decl. */ + SET_DECL_ASSEMBLER_NAME (decl, name); DECL_CONTEXT (decl) = class_type; DECL_ARTIFICIAL (decl) = 1; TREE_STATIC (decl) = 1; -#ifndef WRITABLE_VTABLES - /* Make them READONLY by default. (mrs) */ TREE_READONLY (decl) = 1; -#endif DECL_VIRTUAL_P (decl) = 1; import_export_vtable (decl, class_type, 0); @@ -761,7 +759,6 @@ get_vtable_decl (type, complete) } decl = build_vtable (type, name, void_type_node); - SET_DECL_ASSEMBLER_NAME (decl, name); decl = pushdecl_top_level (decl); my_friendly_assert (IDENTIFIER_GLOBAL_VALUE (name) == decl, 20000517); @@ -2448,7 +2445,7 @@ duplicate_tag_error (t) SET_IS_AGGR_TYPE (t, 1); } -/* Make the BINFO's vtablehave N entries, including RTTI entries, +/* Make BINFO's vtable have N entries, including RTTI entries, vbase and vcall offsets, etc. Set its type and call the backend to lay it out. */ @@ -6996,7 +6993,8 @@ initialize_array (decl, inits) This holds 1 - primary virtual pointer for complete object T - 2 - secondary VTTs for each direct non-virtual base of T which requires a VTT + 2 - secondary VTTs for each direct non-virtual base of T which requires a + VTT 3 - secondary virtual pointers for each direct or indirect base of T which has virtual bases or is reachable via a virtual path from T. 4 - secondary VTTs for each direct or indirect virtual base of T. @@ -7027,7 +7025,6 @@ build_vtt (t) /* Now, build the VTT object itself. */ vtt = build_vtable (t, get_vtt_name (t), type); - SET_DECL_ASSEMBLER_NAME (vtt, DECL_NAME (vtt)); pushdecl_top_level (vtt); initialize_array (vtt, inits); } @@ -7482,6 +7479,7 @@ dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l) vtbl = build1 (ADDR_EXPR, vtbl_ptr_type_node, vtbl); + TREE_CONSTANT (vtbl) = 1; index = size_binop (PLUS_EXPR, size_int (non_fn_entries), size_int (list_length (TREE_VALUE (l)))); @@ -7508,7 +7506,7 @@ dfs_accumulate_vtbl_inits (binfo, orig_binfo, rtti_binfo, t, l) return inits; } -/* Construct the initializer for BINFOs virtual function table. BINFO +/* Construct the initializer for BINFO's virtual function table. BINFO is part of the hierarchy dominated by T. If we're building a construction vtable, the ORIG_BINFO is the binfo we should use to find the actual function pointers to put in the vtable - but they diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 01f643fd927..ba98dc5e7e7 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -463,7 +463,6 @@ lang_f_options[] = {"gnu-keywords", &flag_no_gnu_keywords, 0}, {"handle-exceptions", &flag_exceptions, 1}, {"honor-std", &flag_honor_std, 1}, - {"huge-objects", &flag_huge_objects, 1}, {"implement-inlines", &flag_implement_inlines, 1}, {"implicit-inline-templates", &flag_implicit_inline_templates, 1}, {"implicit-templates", &flag_implicit_templates, 1}, @@ -475,8 +474,8 @@ lang_f_options[] = {"repo", &flag_use_repository, 1}, {"rtti", &flag_rtti, 1}, {"stats", &flag_detailed_statistics, 1}, + {"vtable-gc", &flag_vtable_gc, 1}, {"use-cxa-atexit", &flag_use_cxa_atexit, 1}, - {"vtable-thunks", &flag_vtable_thunks, 1}, {"weak", &flag_weak, 1} }; @@ -488,13 +487,14 @@ static const char * const unsupported_options[] = { "cond-mismatch", "enum-int-equiv", "guiding-decls", + "huge-objects", "labels-ok", "new-abi", "nonnull-objects", "squangle", "strict-prototype", "this-is-variable", - "vtable-gc", + "vtable-thunks", "xref" }; @@ -2354,7 +2354,7 @@ maybe_make_one_only (decl) after a weak one is an error. Also, not making explicit instantiations one_only means that we can end up with two copies of some template instantiations. */ - if (! supports_one_only ()) + if (! flag_weak) return; /* We can't set DECL_COMDAT on functions, or finish_file will think diff --git a/gcc/invoke.texi b/gcc/invoke.texi index 694d711921c..579775f78ba 100644 --- a/gcc/invoke.texi +++ b/gcc/invoke.texi @@ -172,13 +172,13 @@ in the following sections. -fno-enforce-eh-specs -fexternal-templates @gol -falt-external-templates @gol -ffor-scope -fno-for-scope -fno-gnu-keywords -fhonor-std @gol --fhuge-objects -fno-implicit-templates @gol +-fno-implicit-templates @gol -fno-implicit-inline-templates @gol -fno-implement-inlines -fms-extensions @gol -fno-nonansi-builtins -fno-operator-names @gol -fno-optional-diags -fpermissive @gol -frepo -fno-rtti -fstats -ftemplate-depth-@var{n} @gol --fuse-cxa-atexit -fvtable-thunks -fno-weak -nostdinc++ @gol +-fuse-cxa-atexit -fvtable-gc -fno-weak -nostdinc++ @gol -fno-default-inline -Wctor-dtor-privacy @gol -Wnon-virtual-dtor -Wreorder @gol -Weffc++ -Wno-deprecated @gol @@ -1312,16 +1312,6 @@ by default, ignore @code{namespace-declarations}, @code{using-declarations}, @code{using-directives}, and @code{namespace-names}, if they involve @code{std}. -@item -fhuge-objects -Support virtual function calls for objects that exceed the size -representable by a @samp{short int}. Users should not use this flag by -default; if you need to use it, the compiler will tell you so. - -This flag is not useful when compiling with -fvtable-thunks. - -Like all options that change the ABI, all C++ code, @emph{including -libgcc} must be built with the same setting of this option. - @item -fno-implicit-templates Never emit code for non-inline templates which are instantiated implicitly (i.e. by use); only emit code for explicit instantiations. @@ -1392,24 +1382,18 @@ This option is required for fully standards-compliant handling of static destructors, but will only work if your C library supports @code{__cxa_atexit}. -@item -fvtable-thunks -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 -offsets for adjusting the @samp{this} pointer at the call site. Newer -implementations store a single pointer to a @samp{thunk} function which -does any necessary adjustment and then calls the target function. - -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. +@item -fvtable-gc +Emit special relocations for vtables and virtual function references +so that the linker can identify unused virtual functions and zero out +vtable slots that refer to them. This is most useful with +@samp{-ffunction-sections} and @samp{-Wl,--gc-sections}, in order to +also discard the functions themselves. -Like all options that change the ABI, all C++ code, @emph{including -libgcc.a} must be built with the same setting of this option. +This optimization requires GNU as and GNU ld. Not all systems support +this option. @samp{-Wl,--gc-sections} is ignored without @samp{-static}. @item -fno-weak -Do not use weak symbol support, even if it is provied by the linker. +Do not use weak symbol support, even if it is provided by the linker. By default, G++ will use weak symbols if they are available. This option exists only for testing, and should not be used by end-users; it will result in inferior code and has no benefits. This option may @@ -1489,7 +1473,8 @@ but disables the helpful warning. @item -Wold-style-cast (C++ only) Warn if an old-style (C-style) cast is used within a C++ program. The new-style casts (@samp{static_cast}, @samp{reinterpret_cast}, and -@samp{const_cast}) are less vulnerable to unintended effects. +@samp{const_cast}) are less vulnerable to unintended effects, and much +easier to grep for. @item -Woverloaded-virtual (C++ only) @cindex overloaded virtual fn, warning @@ -3417,7 +3402,7 @@ If @var{n} is not specified, use a machine-dependent default. @item -fssa Perform optimizations in static single assignment form. Each function's flow graph is translated into SSA form, optimizations are performed, and -the flow graph is translated back from SSA form. User's should not +the flow graph is translated back from SSA form. Users should not specify this option, since it is not yet ready for production use. @item -fdce @@ -8101,7 +8086,7 @@ exceptions. For some targets, this implies GNU CC will generate frame unwind information for all functions, which can produce significant data size overhead, although it does not affect execution. If you do not specify this option, GNU CC will enable it by default for languages like -C++ which normally require exception handling, and disable itfor +C++ which normally require exception handling, and disable it for languages like C that do not normally require it. However, you may need to enable this option when compiling C code that needs to interoperate properly with exception handlers written in C++. You may also wish to @@ -8154,7 +8139,7 @@ shared between processes running the same program, while private data exists in one copy per process. @item -fno-common -Allocate even uninitialized global variables in the data section of the +In C, allocate even uninitialized global variables in the data section of the object file, rather than generating them as common blocks. This has the effect that if the same variable is declared (without @code{extern}) in two different compilations, you will get an error when you link them. diff --git a/gcc/testsuite/g++.old-deja/g++.ext/comint1.C b/gcc/testsuite/g++.old-deja/g++.ext/comint1.C index 1b8b3c81c45..78d99e6c357 100644 --- a/gcc/testsuite/g++.old-deja/g++.ext/comint1.C +++ b/gcc/testsuite/g++.old-deja/g++.ext/comint1.C @@ -1,5 +1,4 @@ // Test that we can use mixins with COM classes. -// Special g++ Options: -fvtable-thunks struct A { diff --git a/gcc/testsuite/g++.old-deja/g++.ext/noweak1.C b/gcc/testsuite/g++.old-deja/g++.ext/noweak1.C new file mode 100644 index 00000000000..bd7d65ce701 --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.ext/noweak1.C @@ -0,0 +1,16 @@ +// Test that -fno-weak doesn't break explicit instantiation of static data. +// Special g++ Options: -fno-weak + +template struct A +{ + static int i; +}; + +template int A::i = 42; + +template class A; + +int main () +{ + return (A::i != 42); +} diff --git a/gcc/testsuite/g++.old-deja/g++.jason/thunk1.C b/gcc/testsuite/g++.old-deja/g++.jason/thunk1.C index 22c0516f1b3..a46d356a6c0 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/thunk1.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/thunk1.C @@ -1,5 +1,4 @@ // Test that non-variadic function calls using thunks work right. -// Special g++ Options: -fvtable-thunks struct A { void* p; @@ -38,7 +37,7 @@ void* test(MMixin& anExample) return anExample.MixinFunc(1,A(0)).p; } -main () +int main () { CExample c; diff --git a/gcc/testsuite/g++.old-deja/g++.jason/thunk2.C b/gcc/testsuite/g++.old-deja/g++.jason/thunk2.C index 73bb0ff33b1..3df566a68cc 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/thunk2.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/thunk2.C @@ -1,6 +1,6 @@ // Test that non-variadic function calls using thunks and PIC work right. // Skip if not native -// Special g++ Options: -fvtable-thunks -fPIC +// Special g++ Options: -fPIC // excess errors test - XFAIL m68k-motorola-sysv m88k-motorola-sysv3 struct A { diff --git a/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C b/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C index 79c0bd96e3a..8833348230d 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/thunk3.C @@ -2,7 +2,6 @@ // Note that this will break on any target that uses the generic thunk // support, because it doesn't support variadic functions. -// Special g++ Options: -fvtable-thunks // excess errors test - XFAIL mips*-*-* rs6000-*-* powerpc-*-eabi m68k-*-coff m68k-motorola-sysv m88k-motorola-sysv3 mn10300-*-* mn10200-*-* v850-*-* sh-*-* h8*-*-* #include @@ -50,7 +49,7 @@ void* test(MMixin& anExample) return anExample.MixinFunc(1,2,3,4,5,6,7,8,9).p; } -main () +int main () { CExample c; diff --git a/gcc/testsuite/g++.old-deja/g++.law/vtable2.C b/gcc/testsuite/g++.old-deja/g++.law/vtable2.C index bbc8074de91..15b31e42908 100644 --- a/gcc/testsuite/g++.old-deja/g++.law/vtable2.C +++ b/gcc/testsuite/g++.old-deja/g++.law/vtable2.C @@ -1,5 +1,4 @@ // Build don't link: -// Special g++ Options: -fvtable-thunks // GROUPS passed vtable struct C1 { diff --git a/gcc/testsuite/g++.old-deja/g++.mike/thunk1.C b/gcc/testsuite/g++.old-deja/g++.mike/thunk1.C index 9780c05bc97..fc5e9b54b47 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/thunk1.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/thunk1.C @@ -1,5 +1,4 @@ // Build don't link: -// Special g++ Options: -fvtable-thunks struct C1 { diff --git a/gcc/testsuite/g++.old-deja/g++.mike/thunk2.C b/gcc/testsuite/g++.old-deja/g++.mike/thunk2.C index 36b9659fa41..20f1379d393 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/thunk2.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/thunk2.C @@ -1,5 +1,3 @@ -// Special g++ Options: -fvtable-thunks - #include int state; @@ -26,7 +24,7 @@ A* bar() { return new A; } -main() { +int main() { A *aptr = bar(); aptr->foo(); if (dynamic_cast (aptr) != aptr) diff --git a/gcc/testsuite/g++.old-deja/g++.mike/thunk3.C b/gcc/testsuite/g++.old-deja/g++.mike/thunk3.C index 3e97aacd6ba..16a5be85da6 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/thunk3.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/thunk3.C @@ -1,5 +1,3 @@ -// Special g++ Options: -fvtable-thunks - int state; int fail; @@ -24,7 +22,7 @@ A* bar() { return new A; } -main() { +int main() { A *aptr = bar(); aptr->foo(); if (dynamic_cast (aptr) != aptr) diff --git a/gcc/testsuite/g++.old-deja/g++.oliva/thunk1.C b/gcc/testsuite/g++.old-deja/g++.oliva/thunk1.C index 225a1f98103..0aa2178da5d 100644 --- a/gcc/testsuite/g++.old-deja/g++.oliva/thunk1.C +++ b/gcc/testsuite/g++.old-deja/g++.oliva/thunk1.C @@ -3,8 +3,6 @@ // by Alexandre Oliva // based on bug report by Fredrik Öhrström -// Special g++ Options: -fvtable-thunks - #include using namespace std; diff --git a/gcc/testsuite/g++.old-deja/g++.other/crash18.C b/gcc/testsuite/g++.old-deja/g++.other/crash18.C index 2fa185f56f1..789e3166fb4 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/crash18.C +++ b/gcc/testsuite/g++.old-deja/g++.other/crash18.C @@ -1,7 +1,6 @@ // Build don't link: // Special g++ Options: -fvtable-gc // Origin: Mark Mitchell -// excess errors test - XFAIL *-*-* struct S { virtual void f ();