[analyzer] Handle 'SomeVar.SomeEnumConstant', which is legal in C++.

This caused assertion failures analyzing LLVM.

<rdar://problem/12560282>

llvm-svn: 166529
This commit is contained in:
Jordan Rose 2012-10-23 23:59:08 +00:00
parent 746c06d0bc
commit 1bbd143945
2 changed files with 30 additions and 7 deletions

View File

@ -1512,13 +1512,13 @@ void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
StmtNodeBuilder Bldr(Pred, TopDst, *currBldrCtx);
ExplodedNodeSet Dst;
Decl *member = M->getMemberDecl();
ValueDecl *Member = M->getMemberDecl();
// Handle static member variables accessed via member syntax.
if (VarDecl *VD = dyn_cast<VarDecl>(member)) {
assert(M->isGLValue());
// Handle static member variables and enum constants accessed via
// member syntax.
if (isa<VarDecl>(Member) || isa<EnumConstantDecl>(Member)) {
Bldr.takeNodes(Pred);
VisitCommonDeclRefExpr(M, VD, Pred, Dst);
VisitCommonDeclRefExpr(M, Member, Pred, Dst);
Bldr.addNodes(Dst);
return;
}
@ -1528,7 +1528,7 @@ void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
Expr *BaseExpr = M->getBase();
// Handle C++ method calls.
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(member)) {
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Member)) {
if (MD->isInstance())
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
@ -1543,7 +1543,7 @@ void ExprEngine::VisitMemberExpr(const MemberExpr *M, ExplodedNode *Pred,
state = createTemporaryRegionIfNeeded(state, LCtx, BaseExpr);
SVal baseExprVal = state->getSVal(BaseExpr, LCtx);
FieldDecl *field = cast<FieldDecl>(member);
FieldDecl *field = cast<FieldDecl>(Member);
SVal L = state->getLValue(field, baseExprVal);
if (M->isGLValue()) {
if (field->getType()->isReferenceType()) {

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection %s -verify
void clang_analyzer_eval(int);
namespace EnumsViaMemberExpr {
struct Foo {
enum E {
Bar = 1
};
};
void testEnumVal(Foo Baz) {
clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
}
void testEnumRef(Foo &Baz) {
clang_analyzer_eval(Baz.Bar == Foo::Bar); // expected-warning{{TRUE}}
}
void testEnumPtr(Foo *Baz) {
clang_analyzer_eval(Baz->Bar == Foo::Bar); // expected-warning{{TRUE}}
}
}