aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2019-06-01 18:36:49 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2019-06-01 16:36:49 +0000
commite4b44fd741ee25aa5ad086949ccfbcbd3736c0f3 (patch)
treede277309e24560ad8eaec387435ea436ae9943ba
parent5a2a2fb3152a801b5652bb65c380d92db2d900d3 (diff)
downloadgcc-e4b44fd741ee25aa5ad086949ccfbcbd3736c0f3.zip
gcc-e4b44fd741ee25aa5ad086949ccfbcbd3736c0f3.tar.gz
gcc-e4b44fd741ee25aa5ad086949ccfbcbd3736c0f3.tar.bz2
alias.c: Include ipa-utils.h.
* alias.c: Include ipa-utils.h. (get_alias_set): Try to complete ODR type via ODR type hash lookup. * ipa-devirt.c (prevailing_odr_type): New. * ipa-utils.h (previaling_odr_type): Declare. * g++.dg/lto/alias-1_0.C: New testcase. * g++.dg/lto/alias-1_1.C: New testcase. From-SVN: r271837
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/alias.c9
-rw-r--r--gcc/ipa-devirt.c14
-rw-r--r--gcc/ipa-utils.h1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/lto/alias-1_0.C31
-rw-r--r--gcc/testsuite/g++.dg/lto/alias-1_1.C16
7 files changed, 83 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a1e8127..491577b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2019-05-31 Jan Hubicka <jh@suse.cz>
+
+ * alias.c: Include ipa-utils.h.
+ (get_alias_set): Try to complete ODR type via ODR type hash lookup.
+ * ipa-devirt.c (prevailing_odr_type): New.
+ * ipa-utils.h (previaling_odr_type): Declare.
+
2019-05-31 H.J. Lu <hongjiu.lu@intel.com>
Hongtao Liu <hongtao.liu@intel.com>
diff --git a/gcc/alias.c b/gcc/alias.c
index d3cc07c..eece84a 100644
--- a/gcc/alias.c
+++ b/gcc/alias.c
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see
#include "cfganal.h"
#include "rtl-iter.h"
#include "cgraph.h"
+#include "ipa-utils.h"
/* The aliasing API provided here solves related but different problems:
@@ -1008,6 +1009,14 @@ get_alias_set (tree t)
}
p = TYPE_MAIN_VARIANT (p);
+ /* In LTO for C++ programs we can turn in complete types to complete
+ using ODR name lookup. */
+ if (in_lto_p && TYPE_STRUCTURAL_EQUALITY_P (p) && odr_type_p (p))
+ {
+ p = prevailing_odr_type (p);
+ gcc_checking_assert (TYPE_MAIN_VARIANT (p) == p);
+ }
+
/* Make void * compatible with char * and also void **.
Programs are commonly violating TBAA by this.
diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c
index a51b151..e9cb180 100644
--- a/gcc/ipa-devirt.c
+++ b/gcc/ipa-devirt.c
@@ -2170,6 +2170,20 @@ get_odr_type (tree type, bool insert)
return val;
}
+/* Return type that in ODR type hash prevailed TYPE. Be careful and punt
+ on ODR violations. */
+
+tree
+prevailing_odr_type (tree type)
+{
+ odr_type t = get_odr_type (type, false);
+ if (!t || t->odr_violated)
+ return type;
+ return t->type;
+}
+
+/* Return true if we reported some ODR violation on TYPE. */
+
bool
odr_type_violation_reported_p (tree type)
{
diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h
index b70e8c5..77cf3d3d 100644
--- a/gcc/ipa-utils.h
+++ b/gcc/ipa-utils.h
@@ -92,6 +92,7 @@ void warn_types_mismatch (tree t1, tree t2, location_t loc1 = UNKNOWN_LOCATION,
bool odr_or_derived_type_p (const_tree t);
bool odr_types_equivalent_p (tree type1, tree type2);
bool odr_type_violation_reported_p (tree type);
+tree prevailing_odr_type (tree type);
/* Return vector containing possible targets of polymorphic call E.
If COMPLETEP is non-NULL, store true if the list is complete.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 04fb8bc..0663f4c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-05-31 Jan Hubicka <jh@suse.cz>
+
+ * g++.dg/lto/alias-1_0.C: New testcase.
+ * g++.dg/lto/alias-1_1.C: New testcase.
+
2019-05-31 H.J. Lu <hongjiu.lu@intel.com>
PR target/89355
diff --git a/gcc/testsuite/g++.dg/lto/alias-1_0.C b/gcc/testsuite/g++.dg/lto/alias-1_0.C
new file mode 100644
index 0000000..32f3ff0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alias-1_0.C
@@ -0,0 +1,31 @@
+/* { dg-lto-do run } */
+/* { dg-lto-options { { -O2 -flto } } } */
+
+/* With LTO we consider all pointers to incomplete types to be possibly
+ aliasing. This makes *bptr to alias with aptr.
+ However with C++ ODR rule we can turn incomplete pointers to complete
+ dragging in info from alias-1_1.C. */
+
+#include <string.h>
+
+typedef int (*fnptr) ();
+
+__attribute__ ((used))
+struct a *aptr;
+
+__attribute__ ((used))
+struct b **bptr = (struct b**)&aptr;
+extern void init ();
+extern void inline_me_late (int);
+
+
+int
+main (int argc, char **argv)
+{
+ init ();
+ aptr = 0;
+ inline_me_late (argc);
+ if (!__builtin_constant_p (aptr == 0))
+ __builtin_abort ();
+ return (size_t)aptr;
+}
diff --git a/gcc/testsuite/g++.dg/lto/alias-1_1.C b/gcc/testsuite/g++.dg/lto/alias-1_1.C
new file mode 100644
index 0000000..49e8217
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/alias-1_1.C
@@ -0,0 +1,16 @@
+#include <string.h>
+struct a {int a;} a;
+struct b {short b;} b;
+extern struct b **bptr;
+void
+inline_me_late (int argc)
+{
+ if (argc == -1)
+ *bptr = (struct b *)(size_t)1;
+}
+void
+init()
+{
+ a.a=1;
+ b.b=2;
+}