Add explicit CFG support for ignoring static_asserts.

llvm-svn: 132001
This commit is contained in:
Ted Kremenek 2011-05-24 20:41:31 +00:00
parent c731848a05
commit 3a60114085
2 changed files with 20 additions and 1 deletions

View File

@ -1323,6 +1323,7 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) {
if (isa<LabelDecl>(*DS->decl_begin()))
return Block;
// This case also handles static_asserts.
if (DS->isSingleDecl())
return VisitDeclSubExpr(DS);
@ -1355,7 +1356,14 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) {
/// DeclStmts and initializers in them.
CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt* DS) {
assert(DS->isSingleDecl() && "Can handle single declarations only.");
Decl *D = DS->getSingleDecl();
if (isa<StaticAssertDecl>(D)) {
// static_asserts aren't added to the CFG because they do not impact
// runtime semantics.
return Block;
}
VarDecl *VD = dyn_cast<VarDecl>(DS->getSingleDecl());
if (!VD) {

View File

@ -0,0 +1,11 @@
// RUN: %clang --analyze -std=c++0x %s -Xclang -verify
void test_static_assert() {
static_assert(sizeof(void *) == sizeof(void*), "test_static_assert");
}
void test_analyzer_working() {
int *p = 0;
*p = 0xDEADBEEF; // expected-warning {{null}}
}