From: hubicka Date: Mon, 4 Apr 2016 15:54:39 +0000 (+0000) Subject: PR ipa/66223 X-Git-Tag: upstream/6.1~298 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d374a3a3e4de7f05e1188382fa9586e031e5b1c4;p=platform%2Fupstream%2Flinaro-gcc.git PR ipa/66223 * ipa-devirt.c (maybe_record_node): Do not optimize cxa_pure_virtual calls when sanitizing. (possible_polymorphic_call_target_p)" FIx formating. * g++.dg/ipa/devirt-51.C: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234719 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b478b0f..d9ad89c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2016-04-04 Jan Hubicka + + PR ipa/66223 + * ipa-devirt.c (maybe_record_node): Do not optimize cxa_pure_virtual + calls when sanitizing. + (possible_polymorphic_call_target_p)" FIx formating. + 2016-04-04 Bill Schmidt Jakub Jelinek diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index 0694951..22ece9f 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -2438,10 +2438,14 @@ maybe_record_node (vec &nodes, { gcc_assert (!target_node->global.inlined_to); gcc_assert (target_node->real_symbol_p ()); + /* When sanitizing, do not asume that cxa_pure_virutal is not called + by valid program. */ + if (flag_sanitize & SANITIZE_UNDEFINED) + ; /* Only add pure virtual if it is the only possible target. This way we will preserve the diagnostics about pure virtual called in many cases without disabling optimization in other. */ - if (pure_virtual) + else if (pure_virtual) { if (nodes.length ()) return; @@ -3374,8 +3378,7 @@ possible_polymorphic_call_target_p (tree otr_type, bool final; if (TREE_CODE (TREE_TYPE (n->decl)) == FUNCTION_TYPE - && ((fcode = DECL_FUNCTION_CODE (n->decl)) - == BUILT_IN_UNREACHABLE + && ((fcode = DECL_FUNCTION_CODE (n->decl)) == BUILT_IN_UNREACHABLE || fcode == BUILT_IN_TRAP)) return true; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c9b0205..168b769 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-04-04 Jan Hubicka + + PR ipa/66223 + * g++.dg/ipa/devirt-51.C: New testcase. + 2016-04-04 Bill Schmidt Jakub Jelinek diff --git a/gcc/testsuite/g++.dg/ipa/devirt-51.C b/gcc/testsuite/g++.dg/ipa/devirt-51.C new file mode 100644 index 0000000..fadf9e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/devirt-51.C @@ -0,0 +1,32 @@ +/* Be sure we do not optimize the virtual call into call of the only non-virtual + variant. Either keeping virtual call or optimizing to cxa_pure_virtual + is fine. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fsanitize=undefined -fdump-tree-optimized" } */ +namespace { + struct B { + B* self; + B() : self( this ) { self->f(); } + void E(void); + virtual void f() = 0; + }; + + struct D : B + { + void f() {} + }; +} + +struct D e; + +__attribute__ ((used)) +void B::E(void) + { + this->f(); +} + + int main() + { + D d; + } +/* { dg-final { scan-tree-dump "cxa_pure_virtual" "optimized" } } */