[cfe-commits] r163744 - in /cfe/trunk: lib/StaticAnalyzer/Core/CallEvent.cpp test/Analysis/inlining/dyn-dispatch-bifurcate.cpp

Jordan Rose jordan_rose at apple.com
Wed Sep 12 14:48:13 PDT 2012


Author: jrose
Date: Wed Sep 12 16:48:13 2012
New Revision: 163744

URL: http://llvm.org/viewvc/llvm-project?rev=163744&view=rev
Log:
Revert "[analyzer] Use the static type for a virtual call if the dynamic type is worse."

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.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
    cfe/trunk/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=163744&r1=163743&r2=163744&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Wed Sep 12 16:48:13 2012
@@ -433,21 +433,14 @@
   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();
   }

Modified: cfe/trunk/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp?rev=163744&r1=163743&r2=163744&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp (original)
+++ cfe/trunk/test/Analysis/inlining/dyn-dispatch-bifurcate.cpp Wed Sep 12 16:48:13 2012
@@ -15,19 +15,3 @@
   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}}
-  }
-}





More information about the cfe-commits mailing list