From a41844e513aa643b1bc41815f7f4ae48aba90464 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Wed, 30 Jul 2014 13:27:20 -0400 Subject: [PATCH] re PR ipa/61659 (Extra undefined symbol because of devirtualization) PR c++/61659 PR c++/61687 Revert: gcc/c-family/ * c.opt (-fuse-all-virtuals): New. gcc/cp/ * decl2.c (mark_all_virtuals): New variable. (maybe_emit_vtables): Check it instead of flag_devirtualize. (cp_write_global_declarations): Set it and give helpful diagnostic if it introduces errors. * class.c (finish_struct_1): Check it. From-SVN: r213308 --- gcc/c-family/ChangeLog | 7 +++++ gcc/c-family/c.opt | 4 --- gcc/cp/ChangeLog | 9 +++++++ gcc/cp/class.c | 2 +- gcc/cp/decl2.c | 37 -------------------------- gcc/doc/invoke.texi | 12 +-------- gcc/testsuite/g++.dg/template/dtor9.C | 1 - gcc/testsuite/g++.dg/template/dtor9a.C | 13 --------- 8 files changed, 18 insertions(+), 67 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/template/dtor9a.C diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 31d10b070c2..645b9403b7e 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2014-07-30 Jason Merrill + + PR c++/61659 + PR c++/61687 + Revert: + * c.opt (-fuse-all-virtuals): New. + 2014-07-30 Tom Tromey PR c/59855 diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index ac3eb440372..f427da10fb8 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1276,10 +1276,6 @@ funsigned-char C ObjC C++ ObjC++ LTO Var(flag_signed_char, 0) Make \"char\" unsigned by default -fuse-all-virtuals -C++ ObjC++ Var(flag_use_all_virtuals) Init(1) -Treat all virtual functions as odr-used - fuse-cxa-atexit C++ ObjC++ Var(flag_use_cxa_atexit) Init(DEFAULT_USE_CXA_ATEXIT) Use __cxa_atexit to register destructors diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3d8bf6d58a5..25d9b8acb32 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,14 @@ 2014-07-30 Jason Merrill + PR c++/61659 + PR c++/61687 + Revert: + * decl2.c (mark_all_virtuals): New variable. + (maybe_emit_vtables): Check it instead of flag_devirtualize. + (cp_write_global_declarations): Set it and give helpful diagnostic + if it introduces errors. + * class.c (finish_struct_1): Check it. + PR lto/53808 PR c++/61659 * pt.c (push_template_decl_real): Set DECL_COMDAT on templates. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 0f611e10a6f..235c68a962e 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6408,7 +6408,7 @@ finish_struct_1 (tree t) in every translation unit where the class definition appears. If we're devirtualizing, we can look into the vtable even if we aren't emitting it. */ - if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE || flag_use_all_virtuals) + if (CLASSTYPE_KEY_METHOD (t) == NULL_TREE) keyed_classes = tree_cons (NULL_TREE, t, keyed_classes); } diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 884be0a954e..eafdce57690 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -106,11 +106,6 @@ static GTY(()) vec *no_linkage_decls; /* Nonzero if we're done parsing and into end-of-file activities. */ int at_eof; - -/* Nonzero if we've instantiated everything used directly, and now want to - mark all virtual functions as used so that they are available for - devirtualization. */ -static int mark_all_virtuals; /* Return a member function type (a METHOD_TYPE), given FNTYPE (a @@ -2020,15 +2015,6 @@ maybe_emit_vtables (tree ctype) if (DECL_COMDAT (primary_vtbl) && CLASSTYPE_DEBUG_REQUESTED (ctype)) note_debug_info_needed (ctype); - if (mark_all_virtuals && !DECL_ODR_USED (primary_vtbl)) - { - /* Make sure virtual functions get instantiated/synthesized so that - they can be inlined after devirtualization even if the vtable is - never emitted. */ - mark_used (primary_vtbl); - mark_vtable_entries (primary_vtbl); - return true; - } return false; } @@ -4345,8 +4331,6 @@ cp_write_global_declarations (void) instantiated, etc., etc. */ emit_support_tinfos (); - int errs = errorcount + sorrycount; - bool explained_devirt = false; do { @@ -4579,27 +4563,6 @@ cp_write_global_declarations (void) pending_statics->length ())) reconsider = true; - if (flag_use_all_virtuals) - { - if (!reconsider && !mark_all_virtuals) - { - mark_all_virtuals = true; - reconsider = true; - errs = errorcount + sorrycount; - } - else if (mark_all_virtuals - && !explained_devirt - && (errorcount + sorrycount > errs)) - { - inform (global_dc->last_location, "this error is seen due to " - "instantiation of all virtual functions, which the C++ " - "standard says are always considered used; this is done " - "to support devirtualization optimizations, but can be " - "disabled with -fno-use-all-virtuals"); - explained_devirt = true; - } - } - retries++; } while (reconsider); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 5dfa5868108..51757f07efa 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -189,7 +189,7 @@ in the following sections. -fno-pretty-templates @gol -frepo -fno-rtti -fstats -ftemplate-backtrace-limit=@var{n} @gol -ftemplate-depth=@var{n} @gol --fno-threadsafe-statics -fno-use-all-virtuals -fuse-cxa-atexit @gol +-fno-threadsafe-statics -fuse-cxa-atexit @gol -fno-weak -nostdinc++ @gol -fvisibility-inlines-hidden @gol -fvtable-verify=@var{std|preinit|none} @gol @@ -2319,16 +2319,6 @@ ABI for thread-safe initialization of local statics. You can use this option to reduce code size slightly in code that doesn't need to be thread-safe. -@item -fno-use-all-virtuals -@opindex fno-use-all-virtuals -By default, G++ now treats all virtual functions declared in a -translation unit as odr-used, so they will be instantiated or -synthesized if possible even if they are not needed for the final -output. This is done so that such functions can be inlined after -devirtualization changes an indirect call into a direct call. If this -instantiation and synthesis prevents your code from compiling -successfully, you can disable it with this option. - @item -fuse-cxa-atexit @opindex fuse-cxa-atexit Register destructors for objects with static storage duration with the diff --git a/gcc/testsuite/g++.dg/template/dtor9.C b/gcc/testsuite/g++.dg/template/dtor9.C index 006a75489d6..fd71389b865 100644 --- a/gcc/testsuite/g++.dg/template/dtor9.C +++ b/gcc/testsuite/g++.dg/template/dtor9.C @@ -1,5 +1,4 @@ // PR c++/60347 -// { dg-options "-fno-use-all-virtuals" } struct A; diff --git a/gcc/testsuite/g++.dg/template/dtor9a.C b/gcc/testsuite/g++.dg/template/dtor9a.C deleted file mode 100644 index aaae8b6add0..00000000000 --- a/gcc/testsuite/g++.dg/template/dtor9a.C +++ /dev/null @@ -1,13 +0,0 @@ -// PR c++/60347 -// { dg-options "-fuse-all-virtuals" } - -struct A; - -template -struct B -{ - T* p; - virtual ~B() { p->~T(); } // { dg-error "incomplete" } -}; - -struct C: B { };