diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-09-11 18:47:13 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-09-11 18:47:13 +0000 |
commit | 19d5886d1704e24282c86217b09d5c6d35ba604d (patch) | |
tree | 949e513cba44498fbde358b83015d0db2b52a657 /lib/StaticAnalyzer/Core/CallEvent.cpp | |
parent | c9e418c21c7a05ac90fd8013a19c6d1a86b052ee (diff) |
[analyzer] Use the static type for a virtual call if the dynamic type is worse.
reinterpret_cast does not provide any of the usual type information that
static_cast or dynamic_cast provide -- only the new type. This can get us
in a situation where the dynamic type info for an object is actually a
superclass of the static type, which does not match what CodeGen does at all.
In these cases, just fall back to the static type as the best possible type
for devirtualization.
Should fix the crashes on our internal buildbot.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163644 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core/CallEvent.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Core/CallEvent.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/StaticAnalyzer/Core/CallEvent.cpp b/lib/StaticAnalyzer/Core/CallEvent.cpp index 09ba21173b..0f71a76842 100644 --- a/lib/StaticAnalyzer/Core/CallEvent.cpp +++ b/lib/StaticAnalyzer/Core/CallEvent.cpp @@ -433,14 +433,21 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const { if (!RD || !RD->hasDefinition()) return RuntimeDefinition(); - // Find the decl for this method in that class. - const CXXMethodDecl *Result = MD->getCorrespondingMethodInClass(RD, true); + const CXXMethodDecl *Result; + if (MD->getParent()->isDerivedFrom(RD)) { + // If our static type info is better than our dynamic type info, don't + // bother doing a search. Just use the static method. + Result = MD; + } else { + // Otherwise, find the decl for the method in the dynamic class. + Result = MD->getCorrespondingMethodInClass(RD, true); + } + if (!Result) { // We might not even get the original statically-resolved method due to // some particularly nasty casting (e.g. casts to sister classes). // However, we should at least be able to search up and down our own class // hierarchy, and some real bugs have been caught by checking this. - assert(!MD->getParent()->isDerivedFrom(RD) && "Bad DynamicTypeInfo"); assert(!RD->isDerivedFrom(MD->getParent()) && "Couldn't find known method"); return RuntimeDefinition(); } |