]> granicus.if.org Git - clang/commitdiff
[analyzer] Don't assert on a temporary of pointer-to-member type.
authorJordan Rose <jordan_rose@apple.com>
Mon, 15 Apr 2013 22:03:38 +0000 (22:03 +0000)
committerJordan Rose <jordan_rose@apple.com>
Mon, 15 Apr 2013 22:03:38 +0000 (22:03 +0000)
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

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

lib/StaticAnalyzer/Core/ExprEngine.cpp
test/Analysis/pointer-to-member.cpp

index c79cf96c4a891a9e2dbd7d1b0106746a12787d40..1969d947a4474a0d1dd6c41f22f1fd572542be4d 100644 (file)
@@ -181,7 +181,8 @@ ExprEngine::createTemporaryRegionIfNeeded(ProgramStateRef State,
   } 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();
index 84dfe30646ddd9246db8091224effa51f8d7edb0..c9150e8ca5946a3ab713bd9372285f89d42aba01 100644 (file)
@@ -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
+  }
 }
 
 // ---------------