Fix static analyzer crash on code taking the address of a field. Fixes PR 11146.

llvm-svn: 153283
This commit is contained in:
Ted Kremenek 2012-03-22 21:42:31 +00:00
parent c4530bfe21
commit 30de950bba
3 changed files with 25 additions and 0 deletions

View File

@ -66,6 +66,7 @@ public:
DISPATCH_CASE(Record) // FIXME: Refine. VisitStructDecl? DISPATCH_CASE(Record) // FIXME: Refine. VisitStructDecl?
DISPATCH_CASE(CXXRecord) DISPATCH_CASE(CXXRecord)
DISPATCH_CASE(Enum) DISPATCH_CASE(Enum)
DISPATCH_CASE(Field)
DISPATCH_CASE(UsingDirective) DISPATCH_CASE(UsingDirective)
DISPATCH_CASE(Using) DISPATCH_CASE(Using)
default: default:
@ -82,6 +83,7 @@ public:
DEFAULT_DISPATCH(Typedef) DEFAULT_DISPATCH(Typedef)
DEFAULT_DISPATCH(Record) DEFAULT_DISPATCH(Record)
DEFAULT_DISPATCH(Enum) DEFAULT_DISPATCH(Enum)
DEFAULT_DISPATCH(Field)
DEFAULT_DISPATCH(ObjCInterface) DEFAULT_DISPATCH(ObjCInterface)
DEFAULT_DISPATCH(ObjCMethod) DEFAULT_DISPATCH(ObjCMethod)
DEFAULT_DISPATCH(ObjCProtocol) DEFAULT_DISPATCH(ObjCProtocol)

View File

@ -1384,6 +1384,13 @@ void ExprEngine::VisitCommonDeclRefExpr(const Expr *Ex, const NamedDecl *D,
ProgramPoint::PostLValueKind); ProgramPoint::PostLValueKind);
return; return;
} }
if (isa<FieldDecl>(D)) {
// FIXME: Compute lvalue of fields.
Bldr.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, UnknownVal()),
false, 0, ProgramPoint::PostLValueKind);
return;
}
assert (false && assert (false &&
"ValueDecl support for this ValueDecl not implemented."); "ValueDecl support for this ValueDecl not implemented.");
} }

View File

@ -552,3 +552,19 @@ void PR11545_positive() {
} }
} }
// Test handling taking the address of a field. While the analyzer
// currently doesn't do anything intelligent here, this previously
// resulted in a crash.
class PR11146 {
public:
struct Entry;
void baz();
};
struct PR11146::Entry {
int x;
};
void PR11146::baz() {
(void) &Entry::x;
}