]> granicus.if.org Git - clang/commitdiff
Add explicit CFG support for ignoring static_asserts.
authorTed Kremenek <kremenek@apple.com>
Tue, 24 May 2011 20:41:31 +0000 (20:41 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 24 May 2011 20:41:31 +0000 (20:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132001 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
test/Analysis/misc-ps-cxx0x.cpp [new file with mode: 0644]

index f1201913d0c8c9ea4685dd640f893e47f032d053..621adb3e51c6e84c33cb30fa193efc86a4817651 100644 (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) {
diff --git a/test/Analysis/misc-ps-cxx0x.cpp b/test/Analysis/misc-ps-cxx0x.cpp
new file mode 100644 (file)
index 0000000..f21e82c
--- /dev/null
@@ -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}}
+}
+