Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilities static analyzer update #557

Merged
merged 1 commit into from
Aug 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions Utilities/StaticAnalyzers/src/ClassChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ if (BO->isAssignmentOp()) {
} else
if (clang::MemberExpr * ME = dyn_cast<clang::MemberExpr>(BO->getLHS())){
if (ME->isImplicitAccess()) ReportMember(ME);
} else
if (clang::UnaryOperator * UO = llvm::dyn_cast<clang::UnaryOperator>(BO->getLHS()->IgnoreParenImpCasts()) ) {
if (UO->getOpcode() == clang::UnaryOperatorKind::UO_Deref) {
if (clang::MemberExpr * ME = dyn_cast<clang::MemberExpr>(UO->getSubExpr()->IgnoreParenImpCasts())){
if (ME->isImplicitAccess()) ReportMember(ME);
}
if (clang::DeclRefExpr * DRE =dyn_cast<clang::DeclRefExpr>(UO->getSubExpr()->IgnoreParenImpCasts())){
if (const clang::VarDecl * D = llvm::dyn_cast<clang::VarDecl>(DRE->getDecl())) {
clang::QualType t = D->getType();
const clang::Expr * E = llvm::dyn_cast<clang::Expr>(D->getInit());
if (E && t->isPointerType() ) {
const clang::MemberExpr * ME = dyn_cast<clang::MemberExpr>(E->IgnoreParenImpCasts());
if (ME && ME->isImplicitAccess()) ReportMember(ME);
}

}
}
}
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions Utilities/StaticAnalyzers/test/class_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,38 @@ static int const* g_ptr_staticConst = &g_staticConst;
static int g_static;
static int * g_ptr_static = &g_static;

class ClassTest {
public:
explicit ClassTest();
~ClassTest();

void testConst() const;

private:

mutable int m_testMutable;
int * m_testPointer;
int m_testInteger;

};

void
ClassTest::testConst() const
{
// 1) reported by class checker
m_testMutable = 23;

// 2) compiles, not reported
(*m_testPointer) = 23;

// 3) compiles, not reported
int * localPtr = m_testPointer;
(*localPtr) = 23;

// 4) will not compile
// error: invalid conversion from 'const int*' to 'int*'
//int * localPtrToInt = &m_testInteger;
}

class Foo
{
Expand Down