]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix invalid devirtualization when combining final keyword and anonymous types
authorJan Hubicka <jh@suse.cz>
Fri, 12 Aug 2022 14:25:28 +0000 (16:25 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 27 Apr 2023 11:54:48 +0000 (13:54 +0200)
commitea162107bb376f5ffa18bbda70e14b47bc338070
treed417532ed80a1433504d2afb5482b1e65cce2dca
parent28d9ed038a043de36efedaa784d253a97edda231
Fix invalid devirtualization when combining final keyword and anonymous types

this patch fixes a wrong code issue where we incorrectly devirtualize to
__builtin_unreachable.  The problem occurs in combination of anonymous
namespaces and final keyword used on methods.  We do two optimizations here
 1) when reacing final method we cut the search for possible new targets
 2) if the type is anonymous we detect whether it is ever instatiated by
    looking if its vtable is referred to.
Now this goes wrong when thre is an anonymous type with final method that
is not instantiated while its derived type is.  So if 1 triggers we need
to make 2 to look for vtables of all derived types as done by this patch.

Bootstrpaped/regtested x86_64-linux

Honza

gcc/ChangeLog:

2022-08-10  Jan Hubicka  <hubicka@ucw.cz>

PR middle-end/106057
* ipa-devirt.cc (type_or_derived_type_possibly_instantiated_p): New
function.
(possible_polymorphic_call_targets): Use it.

gcc/testsuite/ChangeLog:

2022-08-10  Jan Hubicka  <hubicka@ucw.cz>

PR middle-end/106057
* g++.dg/tree-ssa/pr101839.C: New test.

(cherry picked from commit 0f2c7ccd14a29a8af8318f50b8296098fb0ab218)
gcc/ipa-devirt.cc
gcc/testsuite/g++.dg/tree-ssa/pr101839.C [new file with mode: 0644]