Commit 91bc34a9 by Jan Hubicka Committed by Jan Hubicka

invoke.texi (Wsuggest-final-types, [...]): Document.


	* doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods): Document.
	* ipa-devirt.c: Include hash-map.h
	(struct polymorphic_call_target_d): Add type_warning and decl_warning.
	(clear_speculation): Break out of ...
	(get_class_context): ... here; speed up handling obviously useless
	speculations.
	(odr_type_warn_count, decl_warn_count): New structures.
	(final_warning_record): New structure.
	(final_warning_records): New static variable.
	(possible_polymorphic_call_targets): Cleanup handling of speculative info;
	do not build speculation when user do not care; record info about warnings
	when asked for.
	(add_decl_warning): New function.
	(type_warning_cmp): New function.
	(decl_warning_cmp): New function.
	(ipa_devirt): Handle -Wsuggest-final-methods and -Wsuggest-final-types.
	(gate): Enable pass when warnings are requested.
	* common.opt (Wsuggest-final-types, Wsuggest-final-methods): New options.

	* g++.dg/warn/Wsuggest-final.C: New testcase.
	* g++.dg/ipa/devirt-34.C: Fix.

From-SVN: r213518
parent b787e7a2
2014-08-01 Jan Hubicka <hubicka@ucw.cz>
* doc/invoke.texi (Wsuggest-final-types, Wsuggest-final-methods): Document.
* ipa-devirt.c: Include hash-map.h
(struct polymorphic_call_target_d): Add type_warning and decl_warning.
(clear_speculation): Break out of ...
(get_class_context): ... here; speed up handling obviously useless
speculations.
(odr_type_warn_count, decl_warn_count): New structures.
(final_warning_record): New structure.
(final_warning_records): New static variable.
(possible_polymorphic_call_targets): Cleanup handling of speculative info;
do not build speculation when user do not care; record info about warnings
when asked for.
(add_decl_warning): New function.
(type_warning_cmp): New function.
(decl_warning_cmp): New function.
(ipa_devirt): Handle -Wsuggest-final-methods and -Wsuggest-final-types.
(gate): Enable pass when warnings are requested.
* common.opt (Wsuggest-final-types, Wsuggest-final-methods): New options.
2014-08-02 Trevor Saunders <tsaunders@mozilla.com> 2014-08-02 Trevor Saunders <tsaunders@mozilla.com>
* hash-map.h (default_hashmap_traits::mark_key_deleted): * hash-map.h (default_hashmap_traits::mark_key_deleted):
......
...@@ -651,6 +651,14 @@ Wsuggest-attribute=noreturn ...@@ -651,6 +651,14 @@ Wsuggest-attribute=noreturn
Common Var(warn_suggest_attribute_noreturn) Warning Common Var(warn_suggest_attribute_noreturn) Warning
Warn about functions which might be candidates for __attribute__((noreturn)) Warn about functions which might be candidates for __attribute__((noreturn))
Wsuggest-final-types
Common Var(warn_suggest_final_types) Warning
Warn about C++ polymorphic types where adding final keyword would improve code quality
Wsuggest-final-methods
Common Var(warn_suggest_final_methods) Warning
Warn about C++ virtual methods where adding final keyword would improve code quality
Wsystem-headers Wsystem-headers
Common Var(warn_system_headers) Warning Common Var(warn_system_headers) Warning
Do not suppress warnings from system headers Do not suppress warnings from system headers
......
...@@ -271,6 +271,7 @@ Objective-C and Objective-C++ Dialects}. ...@@ -271,6 +271,7 @@ Objective-C and Objective-C++ Dialects}.
-Wstack-protector -Wstack-usage=@var{len} -Wstrict-aliasing @gol -Wstack-protector -Wstack-usage=@var{len} -Wstrict-aliasing @gol
-Wstrict-aliasing=n @gol -Wstrict-overflow -Wstrict-overflow=@var{n} @gol -Wstrict-aliasing=n @gol -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
-Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol -Wsuggest-attribute=@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{]} @gol
-Wsuggest-final-types @gol -Wsuggest-final-methods @gol
-Wmissing-format-attribute @gol -Wmissing-format-attribute @gol
-Wswitch -Wswitch-default -Wswitch-enum -Wswitch-bool -Wsync-nand @gol -Wswitch -Wswitch-default -Wswitch-enum -Wswitch-bool -Wsync-nand @gol
-Wsystem-headers -Wtrampolines -Wtrigraphs -Wtype-limits -Wundef @gol -Wsystem-headers -Wtrampolines -Wtrigraphs -Wtype-limits -Wundef @gol
...@@ -4193,6 +4194,25 @@ case, and some functions for which @code{format} attributes are ...@@ -4193,6 +4194,25 @@ case, and some functions for which @code{format} attributes are
appropriate may not be detected. appropriate may not be detected.
@end table @end table
@item -Wsuggest-final-types
@opindex Wno-suggest-final-types
@opindex Wsuggest-final-types
Warn about types with virtual methods where code quality would be improved
if the type was declared with C++11 final specifier, or, if possible,
declared in anonymous namespace. This allows GCC to devritualize more aggressively
the polymorphic calls. This warning is more effective with link time optimization,
where the information about the class hiearchy graph is more complete.
@item -Wsuggest-final-methods
@opindex Wno-suggest-final-methods
@opindex Wsuggest-final-methods
Warn about virtual methods where code quality would be improved if the method
was declared with C++11 final specifier, or, if possible, its type was declared
in the anonymous namespace or with final specifier. This warning is more
effective with link time optimization, where the information about the class
hiearchy graph is more complete. It is recommended to first consider suggestins
of @option{-Wsuggest-final-types} and then rebuild with new annotations.
@item -Warray-bounds @item -Warray-bounds
@opindex Wno-array-bounds @opindex Wno-array-bounds
@opindex Warray-bounds @opindex Warray-bounds
...@@ -9622,7 +9642,7 @@ before applying @option{--param inline-unit-growth}. The default is 10000. ...@@ -9622,7 +9642,7 @@ before applying @option{--param inline-unit-growth}. The default is 10000.
@item inline-unit-growth @item inline-unit-growth
Specifies maximal overall growth of the compilation unit caused by inlining. Specifies maximal overall growth of the compilation unit caused by inlining.
The default value is 30 which limits unit growth to 1.3 times the original The default value is 30 which limits unit growth to 1.3 times the original
size. Cold functions (either marked cold via an attribibute or by profile size. Cold functions (either marked cold via an attribute or by profile
feedback) are not accounted into the unit size. feedback) are not accounted into the unit size.
@item ipcp-unit-growth @item ipcp-unit-growth
......
2014-08-01 Jan Hubicka <hubicka@ucw.cz>
* g++.dg/warn/Wsuggest-final.C: New testcase.
* g++.dg/ipa/devirt-34.C: Fix.
2014-08-02 Marek Polacek <polacek@redhat.com> 2014-08-02 Marek Polacek <polacek@redhat.com>
PR c/59855 PR c/59855
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
/* { dg-options "-O2 -fdump-ipa-devirt" } */ /* { dg-options "-O2 -fdump-ipa-devirt" } */
struct A {virtual int t(){return 42;}}; struct A {virtual int t(){return 42;}};
struct B:A {virtual int t(){return 1;}}; struct B:A {virtual int t(){return 1;}};
struct A aa;
struct B bb;
int int
t(struct B *b) t(struct B *b)
{ {
......
// { dg-do compile }
// { dg-options "-O2 -Wsuggest-final-types -Wsuggest-final-methods" }
struct A { // { dg-warning "final would enable devirtualization of 4 calls" }
virtual void a() {} // { dg-warning "final would enable devirtualization of 2 calls" }
virtual void b() {} // { dg-warning "final would enable devirtualization of 2 calls" }
};
void
t(struct A *a)
{
a->a();
a->a();
a->b();
a->b();
}
...@@ -340,8 +340,16 @@ varpool_node::ctor_useable_for_folding_p (void) ...@@ -340,8 +340,16 @@ varpool_node::ctor_useable_for_folding_p (void)
/* Variables declared 'const' without an initializer /* Variables declared 'const' without an initializer
have zero as the initializer if they may not be have zero as the initializer if they may not be
overridden at link or run time. */ overridden at link or run time.
if (!DECL_INITIAL (real_node->decl)
It is actually requirement for C++ compiler to optimize const variables
consistently. As a GNU extension, do not enfore this rule for user defined
weak variables, so we support interposition on:
static const int dummy = 0;
extern const int foo __attribute__((__weak__, __alias__("dummy")));
*/
if ((!DECL_INITIAL (real_node->decl)
|| (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
&& (DECL_EXTERNAL (decl) || decl_replaceable_p (decl))) && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
return false; return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment