From 4611c03d2b0edefc8d8e17872ef143428f56380b Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Sat, 22 Dec 2018 21:06:52 +0100 Subject: [PATCH] tree.c: (obj_type_ref_class): Move to... * tree.c: (obj_type_ref_class): Move to... * ipa-devirt.c (obj_type_ref_class): Move to here; lookup main odr type. (get_odr_type): Compensate for type simplification. * g++.dg/ipa/devirt-30.C: Add dg-do. * g++.dg/lto/devirt-1_0.C: New testcase. * g++.dg/lto/devirt-2_0.C: New testcase. * g++.dg/lto/devirt-3_0.C: New testcase. * g++.dg/lto/devirt-4_0.C: New testcase. * g++.dg/lto/devirt-5_0.C: New testcase. * g++.dg/lto/devirt-6_0.C: New testcase. * g++.dg/lto/devirt-13_0.C: New testcase. * g++.dg/lto/devirt-14_0.C: New testcase. * g++.dg/lto/devirt-19_0.C: New testcase. * g++.dg/lto/devirt-22_0.C: New testcase. * g++.dg/lto/devirt-23_0.C: New testcase. * g++.dg/lto/devirt-30_0.C: New testcase. * g++.dg/lto/devirt-34_0.C: New testcase. From-SVN: r267359 --- gcc/ipa-devirt.c | 26 ++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 17 +++++++++++++++++ gcc/testsuite/g++.dg/ipa/devirt-30.C | 1 + gcc/testsuite/g++.dg/lto/devirt-13_0.C | 5 +++++ gcc/testsuite/g++.dg/lto/devirt-14_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-19_0.C | 5 +++++ gcc/testsuite/g++.dg/lto/devirt-1_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-22_0.C | 5 +++++ gcc/testsuite/g++.dg/lto/devirt-23_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-2_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-30_0.C | 5 +++++ gcc/testsuite/g++.dg/lto/devirt-34_0.C | 6 ++++++ gcc/testsuite/g++.dg/lto/devirt-3_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-4_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-5_0.C | 4 ++++ gcc/testsuite/g++.dg/lto/devirt-6_0.C | 3 +++ gcc/tree.c | 19 ------------------- 17 files changed, 101 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lto/devirt-13_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-14_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-19_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-1_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-22_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-23_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-2_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-30_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-34_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-3_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-4_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-5_0.C create mode 100644 gcc/testsuite/g++.dg/lto/devirt-6_0.C diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index 9c6e271..ac907aa 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -1985,6 +1985,30 @@ add_type_duplicate (odr_type val, tree type) return build_bases; } +/* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */ + +tree +obj_type_ref_class (const_tree ref) +{ + gcc_checking_assert (TREE_CODE (ref) == OBJ_TYPE_REF); + ref = TREE_TYPE (ref); + gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE); + ref = TREE_TYPE (ref); + /* We look for type THIS points to. ObjC also builds + OBJ_TYPE_REF with non-method calls, Their first parameter + ID however also corresponds to class type. */ + gcc_checking_assert (TREE_CODE (ref) == METHOD_TYPE + || TREE_CODE (ref) == FUNCTION_TYPE); + ref = TREE_VALUE (TYPE_ARG_TYPES (ref)); + gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE); + tree ret = TREE_TYPE (ref); + if (!in_lto_p) + ret = TYPE_CANONICAL (ret); + else + ret = get_odr_type (ret)->type; + return ret; +} + /* Get ODR type hash entry for TYPE. If INSERT is true, create possibly new entry. */ @@ -2000,6 +2024,8 @@ get_odr_type (tree type, bool insert) int base_id = -1; type = TYPE_MAIN_VARIANT (type); + if (!in_lto_p) + type = TYPE_CANONICAL (type); gcc_checking_assert (can_be_name_hashed_p (type) || can_be_vtable_hashed_p (type)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8549514..473d0c8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,20 @@ +2018-12-21 Jan Hubicka + + * g++.dg/ipa/devirt-30.C: Add dg-do. + * g++.dg/lto/devirt-1_0.C: New testcase. + * g++.dg/lto/devirt-2_0.C: New testcase. + * g++.dg/lto/devirt-3_0.C: New testcase. + * g++.dg/lto/devirt-4_0.C: New testcase. + * g++.dg/lto/devirt-5_0.C: New testcase. + * g++.dg/lto/devirt-6_0.C: New testcase. + * g++.dg/lto/devirt-13_0.C: New testcase. + * g++.dg/lto/devirt-14_0.C: New testcase. + * g++.dg/lto/devirt-19_0.C: New testcase. + * g++.dg/lto/devirt-22_0.C: New testcase. + * g++.dg/lto/devirt-23_0.C: New testcase. + * g++.dg/lto/devirt-30_0.C: New testcase. + * g++.dg/lto/devirt-34_0.C: New testcase. + 2018-12-26 Steven G . Kargl PR fortran/85798 diff --git a/gcc/testsuite/g++.dg/ipa/devirt-30.C b/gcc/testsuite/g++.dg/ipa/devirt-30.C index 15e8597..630fb8a 100644 --- a/gcc/testsuite/g++.dg/ipa/devirt-30.C +++ b/gcc/testsuite/g++.dg/ipa/devirt-30.C @@ -1,4 +1,5 @@ // PR c++/58678 +// { dg-do compile } // { dg-options "-O3 -fdump-ipa-devirt" } // We shouldn't speculatively devirtualize to ~B because B is an abstract diff --git a/gcc/testsuite/g++.dg/lto/devirt-13_0.C b/gcc/testsuite/g++.dg/lto/devirt-13_0.C new file mode 100644 index 0000000..f9015fd --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-13_0.C @@ -0,0 +1,5 @@ +/* { dg-lto-do run } */ +/* Call to foo should be devirtualized because there are no derived types of A. */ +/* { dg-lto-options "-O2 -flto -fdump-tree-ssa" } */ +#include "../ipa/devirt-13.C" +/* { dg-final { scan-tree-dump-times "OBJ_TYPE_REF" 0 "ssa"} } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-14_0.C b/gcc/testsuite/g++.dg/lto/devirt-14_0.C new file mode 100644 index 0000000..c7528f6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-14_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options "-O2 -fdump-tree-ssa" } */ +#include "../ipa/devirt-14.C" +/* { dg-final { scan-tree-dump-not "A.*foo" "ssa"} } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-19_0.C b/gcc/testsuite/g++.dg/lto/devirt-19_0.C new file mode 100644 index 0000000..696d8c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-19_0.C @@ -0,0 +1,5 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { "-O2 -fdump-ipa-cp -Wno-return-type -flto -r -nostdlib" } } */ +/* { dg-extra-ld-options "-flinker-output=nolto-rel" } */ +#include "../ipa/devirt-19.C" +/* { dg-final { scan-wpa-ipa-dump-times "Discovered a virtual call to a known target" 1 "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-1_0.C b/gcc/testsuite/g++.dg/lto/devirt-1_0.C new file mode 100644 index 0000000..682c40f --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-1_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized -flto" } } */ +#include "../ipa/devirt-1.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to a known target.*foo" "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-22_0.C b/gcc/testsuite/g++.dg/lto/devirt-22_0.C new file mode 100644 index 0000000..9052865 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-22_0.C @@ -0,0 +1,5 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-ipa-sra -fdump-ipa-cp -flto -r -nostdlib" } } */ +/* { dg-extra-ld-options "-flinker-output=nolto-rel" } */ +#include "../ipa/devirt-22.C" +/* { dg-final { scan-wpa-ipa-dump-times "Discovered a virtual call to a known target" 2 "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-23_0.C b/gcc/testsuite/g++.dg/lto/devirt-23_0.C new file mode 100644 index 0000000..760f95f --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-23_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-ipa-sra -flto -fno-devirtualize-speculatively" } } */ +#include "../ipa/devirt-23.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to" "cp" { xfail *-*-* } } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-2_0.C b/gcc/testsuite/g++.dg/lto/devirt-2_0.C new file mode 100644 index 0000000..4e92bb6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-2_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized -flto" } } */ +#include "../ipa/devirt-2.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to a known target.*foo" "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-30_0.C b/gcc/testsuite/g++.dg/lto/devirt-30_0.C new file mode 100644 index 0000000..3e2118b --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-30_0.C @@ -0,0 +1,5 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { "-O3 -fdump-ipa-devirt -flto -r -nostdlib" } } */ +/* { dg-extra-ld-options "-flinker-output=nolto-rel" } */ +#include "../ipa/devirt-30.C" +// { dg-final { scan-wpa-ipa-dump-not "Speculatively devirtualizing" "devirt" } } diff --git a/gcc/testsuite/g++.dg/lto/devirt-34_0.C b/gcc/testsuite/g++.dg/lto/devirt-34_0.C new file mode 100644 index 0000000..7ac3a8c --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-34_0.C @@ -0,0 +1,6 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { "-O2 -fdump-ipa-devirt -flto -r -nostdlib" } } */ +/* { dg-extra-ld-options "-flinker-output=nolto-rel" } */ +#include "../ipa/devirt-34.C" +/* { dg-final { scan-wpa-ipa-dump "Speculative targets" "devirt" } } */ +/* { dg-final { scan-wpa-ipa-dump "1 speculatively devirtualized" "devirt" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-3_0.C b/gcc/testsuite/g++.dg/lto/devirt-3_0.C new file mode 100644 index 0000000..1ec9d76 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-3_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized -flto" } } */ +#include "../ipa/devirt-3.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to a known target.*foo" "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-4_0.C b/gcc/testsuite/g++.dg/lto/devirt-4_0.C new file mode 100644 index 0000000..e44dbfd --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-4_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized -flto" } } */ +#include "../ipa/devirt-4.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to a known target.*foo" "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-5_0.C b/gcc/testsuite/g++.dg/lto/devirt-5_0.C new file mode 100644 index 0000000..daf96e8 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-5_0.C @@ -0,0 +1,4 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -fno-early-inlining -fno-inline -fdump-ipa-cp -fdump-tree-optimized -flto" } } */ +#include "../ipa/devirt-5.C" +/* { dg-final { scan-wpa-ipa-dump "Discovered a virtual call to a known target.*foo" "cp" } } */ diff --git a/gcc/testsuite/g++.dg/lto/devirt-6_0.C b/gcc/testsuite/g++.dg/lto/devirt-6_0.C new file mode 100644 index 0000000..6765a74 --- /dev/null +++ b/gcc/testsuite/g++.dg/lto/devirt-6_0.C @@ -0,0 +1,3 @@ +/* { dg-lto-do run } */ +/* { dg-lto-options { "-O3 -flto" } } */ +#include "../ipa/devirt-6.C" diff --git a/gcc/tree.c b/gcc/tree.c index 5d0d4d3..c3d4bb8 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -12838,25 +12838,6 @@ virtual_method_call_p (const_tree target) return true; } -/* REF is OBJ_TYPE_REF, return the class the ref corresponds to. */ - -tree -obj_type_ref_class (const_tree ref) -{ - gcc_checking_assert (TREE_CODE (ref) == OBJ_TYPE_REF); - ref = TREE_TYPE (ref); - gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE); - ref = TREE_TYPE (ref); - /* We look for type THIS points to. ObjC also builds - OBJ_TYPE_REF with non-method calls, Their first parameter - ID however also corresponds to class type. */ - gcc_checking_assert (TREE_CODE (ref) == METHOD_TYPE - || TREE_CODE (ref) == FUNCTION_TYPE); - ref = TREE_VALUE (TYPE_ARG_TYPES (ref)); - gcc_checking_assert (TREE_CODE (ref) == POINTER_TYPE); - return TREE_TYPE (ref); -} - /* Lookup sub-BINFO of BINFO of TYPE at offset POS. */ static tree -- 2.7.4