[Bug c++/106057] Missed stmt_can_throw_external check in stmt_kills_ref_p
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106057 --- Comment #5 from CVS Commits --- The releases/gcc-12 branch has been updated by Richard Biener : https://gcc.gnu.org/g:ea162107bb376f5ffa18bbda70e14b47bc338070 commit r12-9478-gea162107bb376f5ffa18bbda70e14b47bc338070 Author: Jan Hubicka Date: Fri Aug 12 16:25:28 2022 +0200 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 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 PR middle-end/106057 * g++.dg/tree-ssa/pr101839.C: New test. (cherry picked from commit 0f2c7ccd14a29a8af8318f50b8296098fb0ab218)
[Bug c++/106057] Missed stmt_can_throw_external check in stmt_kills_ref_p
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106057 --- Comment #4 from CVS Commits --- The master branch has been updated by Jan Hubicka : https://gcc.gnu.org/g:0f2c7ccd14a29a8af8318f50b8296098fb0ab218 commit r13-2034-g0f2c7ccd14a29a8af8318f50b8296098fb0ab218 Author: Jan Hubicka Date: Fri Aug 12 16:25:28 2022 +0200 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 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 PR middle-end/106057 * g++.dg/tree-ssa/pr101839.C: New test.
[Bug c++/106057] Missed stmt_can_throw_external check in stmt_kills_ref_p
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106057 --- Comment #3 from CVS Commits --- The master branch has been updated by Jan Hubicka : https://gcc.gnu.org/g:7fd34782b95bbe1b4dc9936b8923f86d4aaee379 commit r13-1241-g7fd34782b95bbe1b4dc9936b8923f86d4aaee379 Author: Jan Hubicka Date: Fri Jun 24 13:52:44 2022 +0200 Fix stmt_kills_ref_p WRT external throws Add missing check to stmt_kills_ref_p for case that function is terminated by EH before call return value kills the ref. In the PR I tried to construct testcase but I don't know how to do that until I annotate EH code with fnspec attributes which I will do in separate patch and add a testcase. PR ipa/106057 * tree-ssa-alias.cc (stmt_kills_ref_p): Check for external throw.
[Bug c++/106057] Missed stmt_can_throw_external check in stmt_kills_ref_p
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106057 --- Comment #2 from Jan Hubicka --- The second testcase (with longjmp) invalid since longjmp can clobber automatic variable and making the variable static breaks the testcase since we believe htat longjmp reads global memory state (it doesn't). The first testcase is also kind-of bordeline since it is question whether const/pure can throw. Performance wise we probably do not need to care about longjmp but with cxa_throw we may want to get side effects modeled right...
[Bug c++/106057] Missed stmt_can_throw_external check in stmt_kills_ref_p
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106057 --- Comment #1 from Jan Hubicka --- C only testcase (also misoptimized in clang) #include int b; jmp_buf buf; __attribute__((noinline)) int maybethrow() { if (!b) longjmp (buf,1); return 2; } void test(int *a) { *a=1; *a=maybethrow(); } int main() { int a=-1; if (setjmp (buf) == 1) { if (a!=1) __builtin_abort (); return 0; } test (); return 0; }