re PR c++/58678 (pykde4-4.11.2 link error (devirtualization too trigger happy))

PR c++/58678
	* search.c (dfs_get_pure_virtuals): Treat the destructor of an
	abstract class as pure.

From-SVN: r208573
This commit is contained in:
Jason Merrill 2014-03-14 15:06:54 -04:00 committed by Jason Merrill
parent b1520f3d2c
commit 7e343703fe
3 changed files with 47 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2014-03-14 Jason Merrill <jason@redhat.com>
PR c++/58678
* search.c (dfs_get_pure_virtuals): Treat the destructor of an
abstract class as pure.
2014-03-13 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/60383

View File

@ -2096,6 +2096,22 @@ dfs_get_pure_virtuals (tree binfo, void *data)
if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type), BV_FN (virtuals));
}
/* Treat a virtual destructor in an abstract class as pure even if it
isn't declared as pure; there is no way it would be called through the
vtable except during construction, which causes undefined behavior. */
if (binfo == TYPE_BINFO (type)
&& CLASSTYPE_PURE_VIRTUALS (type)
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
{
tree dtor = CLASSTYPE_DESTRUCTORS (type);
if (DECL_VIRTUAL_P (dtor) && !DECL_PURE_VIRTUAL_P (dtor))
{
tree clone;
DECL_PURE_VIRTUAL_P (dtor) = true;
FOR_EACH_CLONE (clone, dtor)
DECL_PURE_VIRTUAL_P (clone) = true;
}
}
return NULL_TREE;
}

View File

@ -0,0 +1,25 @@
// PR c++/58678
// { dg-options "-O3 -fdump-ipa-devirt" }
// We shouldn't speculatively devirtualize to ~B because B is an abstract
// class; any actual object passed to f will be of some derived class which
// has its own destructor.
struct A
{
virtual void f() = 0;
virtual ~A();
};
struct B : A
{
virtual ~B() {}
};
void f(B* b)
{
delete b;
}
// { dg-final { scan-ipa-dump-not "Speculatively devirtualizing" "devirt" } }
// { dg-final { cleanup-ipa-dump "devirt" } }