r179563 - [analyzer] Don't assert on a temporary of pointer-to-member type.

Jordan Rose jordan_rose at apple.com
Mon Apr 15 15:03:38 PDT 2013


Author: jrose
Date: Mon Apr 15 17:03:38 2013
New Revision: 179563

URL: http://llvm.org/viewvc/llvm-project?rev=179563&view=rev
Log:
[analyzer] Don't assert on a temporary of pointer-to-member type.

While we don't do anything intelligent with pointers-to-members today,
it's perfectly legal to need a temporary of pointer-to-member type to, say,
pass by const reference. Tweak an assertion to allow this.

PR15742 and PR15747

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/test/Analysis/pointer-to-member.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=179563&r1=179562&r2=179563&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Apr 15 17:03:38 2013
@@ -181,7 +181,8 @@ ExprEngine::createTemporaryRegionIfNeede
   } else {
     // We need to create a region no matter what. For sanity, make sure we don't
     // try to stuff a Loc into a non-pointer temporary region.
-    assert(!V.getAs<Loc>() || Loc::isLocType(Result->getType()));
+    assert(!V.getAs<Loc>() || Loc::isLocType(Result->getType()) ||
+           Result->getType()->isMemberPointerType());
   }
 
   ProgramStateManager &StateMgr = State->getStateManager();

Modified: cfe/trunk/test/Analysis/pointer-to-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/pointer-to-member.cpp?rev=179563&r1=179562&r2=179563&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/pointer-to-member.cpp (original)
+++ cfe/trunk/test/Analysis/pointer-to-member.cpp Mon Apr 15 17:03:38 2013
@@ -8,6 +8,9 @@ struct A {
   operator MemberPointer() const { return m_ptr ? &A::m_ptr : 0; }
 
   A *m_ptr;
+
+  A *getPtr();
+  typedef A * (A::*MemberFnPointer)(void);
 };
 
 void testConditionalUse() {
@@ -22,6 +25,40 @@ void testConditionalUse() {
   clang_analyzer_eval(obj.m_ptr); // expected-warning{{FALSE}}
   clang_analyzer_eval(A::MemberPointer(0)); // expected-warning{{FALSE}}
   clang_analyzer_eval(obj); // expected-warning{{FALSE}}
+
+  clang_analyzer_eval(&A::getPtr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(A::MemberFnPointer(0)); // expected-warning{{FALSE}}
+}
+
+
+void testComparison() {
+  clang_analyzer_eval(&A::getPtr == &A::getPtr); // expected-warning{{TRUE}}
+
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(&A::m_ptr == &A::m_ptr); // expected-warning{{UNKNOWN}}
+}
+
+namespace PR15742 {
+  template <class _T1, class _T2> struct A {
+    A (const _T1 &, const _T2 &);
+  };
+  
+  typedef void *NPIdentifier;
+
+  template <class T> class B {
+  public:
+    typedef A<NPIdentifier, bool (T::*) (const NPIdentifier *, unsigned,
+                                         NPIdentifier *)> MethodMapMember;
+  };
+
+  class C : public B<C> {
+  public:
+    bool Find(const NPIdentifier *, unsigned, NPIdentifier *);
+  };
+
+  void InitStaticData () {
+    C::MethodMapMember(0, &C::Find); // don't crash
+  }
 }
 
 // ---------------





More information about the cfe-commits mailing list