r199226 - [analyzer] Use synthesized ASTs for property getters when available.

Jordan Rose jordan_rose at apple.com
Tue Jan 14 09:29:06 PST 2014


Author: jrose
Date: Tue Jan 14 11:29:06 2014
New Revision: 199226

URL: http://llvm.org/viewvc/llvm-project?rev=199226&view=rev
Log:
[analyzer] Use synthesized ASTs for property getters when available.

This allows the analyzer to handle properties with C++ class type,
finishing up the FIXME from r198953.

Modified:
    cfe/trunk/lib/Analysis/BodyFarm.cpp
    cfe/trunk/test/Analysis/properties.mm

Modified: cfe/trunk/lib/Analysis/BodyFarm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BodyFarm.cpp?rev=199226&r1=199225&r2=199226&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp (original)
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp Tue Jan 14 11:29:06 2014
@@ -393,16 +393,28 @@ static Stmt *createObjCPropertyGetter(AS
     return 0;
   if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak)
     return 0;
+
+  const ObjCImplementationDecl *ImplDecl =
+    IVar->getContainingInterface()->getImplementation();
+  if (ImplDecl) {
+    typedef ObjCImplementationDecl::propimpl_iterator propimpl_iterator;
+    for (propimpl_iterator I = ImplDecl->propimpl_begin(),
+                           E = ImplDecl->propimpl_end();
+         I != E; ++I) {
+      if (I->getPropertyDecl() != Prop)
+        continue;
+
+      if (I->getGetterCXXConstructor()) {
+        ASTMaker M(Ctx);
+        return M.makeReturn(I->getGetterCXXConstructor());
+      }
+    }
+  }
+
   if (IVar->getType().getCanonicalType() !=
       Prop->getType().getNonReferenceType().getCanonicalType())
     return 0;
 
-  // C++ records require copy constructors, so we can't just synthesize an AST.
-  // FIXME: Use ObjCPropertyImplDecl's already-synthesized AST. Currently it's
-  // not in a form the analyzer can use.
-  if (Prop->getType()->getAsCXXRecordDecl())
-    return 0;
-
   ASTMaker M(Ctx);
 
   const VarDecl *selfVar = Prop->getGetterMethodDecl()->getSelfDecl();

Modified: cfe/trunk/test/Analysis/properties.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/properties.mm?rev=199226&r1=199225&r2=199226&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/properties.mm (original)
+++ cfe/trunk/test/Analysis/properties.mm Tue Jan 14 11:29:06 2014
@@ -42,21 +42,21 @@ struct IntWrapperStruct {
 @end
 
 void testConsistencyStruct(StructWrapper *w) {
-  clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
 
   int origValue = w.inner.value;
   if (origValue != 42)
     return;
 
-  clang_analyzer_eval(w.inner.value == 42); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
 }
 
 
 class CustomCopy {
 public:
   CustomCopy() : value(0) {}
-  CustomCopy(const CustomCopy &other) {
-    clang_analyzer_checkInlined(false);
+  CustomCopy(const CustomCopy &other) : value(other.value) {
+    clang_analyzer_checkInlined(true); // expected-warning{{TRUE}}
   }
   int value;
 };
@@ -70,11 +70,11 @@ public:
 @end
 
 void testConsistencyCustomCopy(CustomCopyWrapper *w) {
-  clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(w.inner.value == w.inner.value); // expected-warning{{TRUE}}
 
   int origValue = w.inner.value;
   if (origValue != 42)
     return;
 
-  clang_analyzer_eval(w.inner.value == 42); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(w.inner.value == 42); // expected-warning{{TRUE}}
 }





More information about the cfe-commits mailing list