]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix wrong assumption in contains_type_p (PR ipa/71207).
authorMartin Liska <mliska@suse.cz>
Fri, 20 Jan 2017 08:49:08 +0000 (09:49 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 20 Jan 2017 08:49:08 +0000 (08:49 +0000)
2017-01-20  Martin Liska  <mliska@suse.cz>

Backport from mainline
2017-01-17  Martin Liska  <mliska@suse.cz>

PR ipa/71207
* ipa-polymorphic-call.c (contains_type_p): Fix wrong
assumption and add comment.
2017-01-20  Martin Liska  <mliska@suse.cz>

Backport from mainline
2017-01-17  Martin Liska  <mliska@suse.cz>

PR ipa/71207
* g++.dg/ipa/pr71207.C: New test.

From-SVN: r244688

gcc/ChangeLog
gcc/ipa-polymorphic-call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ipa/pr71207.C [new file with mode: 0644]

index 2dc5f06ff3000549e3e4f6eba04c04a6a2de73e1..44e57619de11c18c0af3e9a0dbb66ba571233415 100644 (file)
@@ -1,3 +1,12 @@
+2017-01-20  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2017-01-17  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/71207
+       * ipa-polymorphic-call.c (contains_type_p): Fix wrong
+       assumption and add comment.
+
 2017-01-17 Thomas Preud'homme <thomas.preudhomme@arm.com>
 
        Backport from mainline
index 9fd302e03d30ab2dbf93720f5d86227e5b24fc0e..4f61e3a90160185e660683d8b50cdad81084b27a 100644 (file)
@@ -506,12 +506,12 @@ contains_type_p (tree outer_type, HOST_WIDE_INT offset,
   /* Check that type is within range.  */
   if (offset < 0)
     return false;
-  if (TYPE_SIZE (outer_type) && TYPE_SIZE (otr_type)
-      && TREE_CODE (TYPE_SIZE (outer_type)) == INTEGER_CST
-      && TREE_CODE (TYPE_SIZE (otr_type)) == INTEGER_CST
-      && wi::ltu_p (wi::to_offset (TYPE_SIZE (outer_type)),
-                   (wi::to_offset (TYPE_SIZE (otr_type)) + offset)))
-    return false;
+
+  /* PR ipa/71207
+     As OUTER_TYPE can be a type which has a diamond virtual inheritance,
+     it's not necessary that INNER_TYPE will fit within OUTER_TYPE with
+     a given offset.  It can happen that INNER_TYPE also contains a base object,
+     however it would point to the same instance in the OUTER_TYPE.  */
 
   context.offset = offset;
   context.outer_type = TYPE_MAIN_VARIANT (outer_type);
index 049dfcf7dc94c97f95833e72c21be11f23131560..733321f35f703acfe1b15d637517f5d16a1cd4a7 100644 (file)
@@ -1,3 +1,11 @@
+2017-01-20  Martin Liska  <mliska@suse.cz>
+
+       Backport from mainline
+       2017-01-17  Martin Liska  <mliska@suse.cz>
+
+       PR ipa/71207
+       * g++.dg/ipa/pr71207.C: New test.
+
 2017-01-17 Thomas Preud'homme <thomas.preudhomme@arm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/g++.dg/ipa/pr71207.C b/gcc/testsuite/g++.dg/ipa/pr71207.C
new file mode 100644 (file)
index 0000000..19a0399
--- /dev/null
@@ -0,0 +1,42 @@
+/* PR ipa/71207 */
+/* { dg-do run } */
+
+class Class1
+{
+public:
+  Class1() {};
+  virtual ~Class1() {};
+
+protected:
+  unsigned Field1;
+};
+
+class Class2 : public virtual Class1
+{
+};
+
+class Class3 : public virtual Class1
+{
+public:
+  virtual void Method1() = 0;
+
+  void Method2()
+  {
+    Method1();
+  }
+};
+
+class Class4 : public Class2, public virtual Class3
+{
+public:
+  Class4() {};
+  virtual void Method1() {};
+};
+
+int main()
+{
+  Class4 var1;
+  var1.Method2();
+
+  return 0;
+}