This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, PR45875] Fix get_binfo_at_offset


Hi,

the patch below fixes the original problem reported in PR 45875.  The
if statement is not only totally unnecessary but also wrong because it
does not take into account the expected_type parameter.

This currently leads to some IPA_JF_ANCESTOR jump functions which
should not be there, which then leads to propagations which should not
happen and wrong binfos being used for virtual method lookups.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin


2010-10-20  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/45875
	* tree.c (get_binfo_at_offset): Remove initial zero offset test.

	* testsuite/g++.dg/ipa/pr45875.C: New test.

Index: icln/gcc/testsuite/g++.dg/ipa/pr45875.C
===================================================================
--- /dev/null
+++ icln/gcc/testsuite/g++.dg/ipa/pr45875.C
@@ -0,0 +1,48 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-early-inlining -fno-ipa-cp"  } */
+
+extern "C" void abort (void);
+
+class A
+{
+public:
+  virtual int foo (int i);
+};
+
+class B
+{
+public:
+  class A confusion;
+};
+
+int A::foo (int i)
+{
+  return i + 1;
+}
+
+int __attribute__ ((noinline,noclone)) get_input(void)
+{
+  return 1;
+}
+
+static int middleman_a (class A *obj, int i)
+{
+  return obj->foo (i);
+}
+
+static int middleman_b (class B *obj, int i)
+{
+  return middleman_a (&obj->confusion, i);
+}
+
+
+int main (int argc, char *argv[])
+{
+  class B b;
+  int i, j = get_input ();
+
+  for (i = 0; i < j; i++)
+    if (middleman_b (&b, j) != 2)
+      abort ();
+  return 0;
+}
Index: icln/gcc/tree.c
===================================================================
--- icln.orig/gcc/tree.c
+++ icln/gcc/tree.c
@@ -10884,9 +10884,6 @@ get_binfo_at_offset (tree binfo, HOST_WI
 {
   tree type;
 
-  if (offset == 0)
-    return binfo;
-
   type = TREE_TYPE (binfo);
   while (offset > 0)
     {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]