* 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
2001-05-21 Jason Merrill <jason_merrill@redhat.com>
+ * 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.
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));
"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);
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);
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);
}
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);
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. */
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.
/* 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);
}
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))));
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
{"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},
{"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}
};
"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"
};
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
-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
@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.
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
@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
@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
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
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.
// Test that we can use mixins with COM classes.
-// Special g++ Options: -fvtable-thunks
struct A
{
--- /dev/null
+// Test that -fno-weak doesn't break explicit instantiation of static data.
+// Special g++ Options: -fno-weak
+
+template <class T> struct A
+{
+ static int i;
+};
+
+template <class T> int A<T>::i = 42;
+
+template class A<int>;
+
+int main ()
+{
+ return (A<int>::i != 42);
+}
// Test that non-variadic function calls using thunks work right.
-// Special g++ Options: -fvtable-thunks
struct A {
void* p;
return anExample.MixinFunc(1,A(0)).p;
}
-main ()
+int main ()
{
CExample c;
// 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 {
// 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 <stdarg.h>
return anExample.MixinFunc(1,2,3,4,5,6,7,8,9).p;
}
-main ()
+int main ()
{
CExample c;
// Build don't link:
-// Special g++ Options: -fvtable-thunks
// GROUPS passed vtable
struct C1
{
// Build don't link:
-// Special g++ Options: -fvtable-thunks
struct C1
{
-// Special g++ Options: -fvtable-thunks
-
#include <typeinfo>
int state;
return new A;
}
-main() {
+int main() {
A *aptr = bar();
aptr->foo();
if (dynamic_cast <void*> (aptr) != aptr)
-// Special g++ Options: -fvtable-thunks
-
int state;
int fail;
return new A;
}
-main() {
+int main() {
A *aptr = bar();
aptr->foo();
if (dynamic_cast <void*> (aptr) != aptr)
// by Alexandre Oliva <oliva@dcc.unicamp.br>
// based on bug report by Fredrik Öhrström <d92-foh@nada.kth.se>
-// Special g++ Options: -fvtable-thunks
-
#include <cstdlib>
using namespace std;
// Build don't link:
// Special g++ Options: -fvtable-gc
// Origin: Mark Mitchell <mitchell@codesourcery.com>
-// excess errors test - XFAIL *-*-*
struct S {
virtual void f ();