forked from OSchip/llvm-project
[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. llvm-svn: 199226
This commit is contained in:
parent
31c05a117a
commit
a3f2781259
|
@ -393,16 +393,28 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx,
|
|||
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();
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue