]> granicus.if.org Git - clang/commitdiff
Revert "[analyzer] Use the static type for a virtual call if the dynamic type is...
authorJordan Rose <jordan_rose@apple.com>
Wed, 12 Sep 2012 21:48:13 +0000 (21:48 +0000)
committerJordan Rose <jordan_rose@apple.com>
Wed, 12 Sep 2012 21:48:13 +0000 (21:48 +0000)
Using the static type may be inconsistent with later calls. We should just
report that there is no inlining definition available if the static type is
better than the dynamic type. See next commit.

This reverts r163644 / 19d5886d1704e24282c86217b09d5c6d35ba604d.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/CallEvent.cpp
test/Analysis/inlining/dyn-dispatch-bifurcate.cpp

index 0f71a76842e01b863d1a34d4863463deb14e7725..09ba21173ba5404ff53f37beb0ba6835f41a814b 100644 (file)
@@ -433,21 +433,14 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
   if (!RD || !RD->hasDefinition())
     return RuntimeDefinition();
 
-  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);
-  }
-
+  // Find the decl for this method in that class.
+  const CXXMethodDecl *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();
   }
index 12dad79433948becd01b9a3dba157cc40f2628d7..fa473aebce324f7cbf069d7ff201caf3699c2b85 100644 (file)
@@ -15,19 +15,3 @@ void testKnown() {
   A a;
   clang_analyzer_eval(a.get() == 0); // expected-warning{{TRUE}}
 }
-
-
-namespace ReinterpretDisruptsDynamicTypeInfo {
-  class Parent {};
-
-  class Child : public Parent {
-  public:
-    virtual int foo() { return 42; }
-  };
-
-  void test(Parent *a) {
-    Child *b = reinterpret_cast<Child *>(a);
-    if (!b) return;
-    clang_analyzer_eval(b->foo() == 42); // expected-warning{{TRUE}} expected-warning{{UNKNOWN}}
-  }
-}