[cfe-commits] r132001 - in /cfe/trunk: lib/Analysis/CFG.cpp test/Analysis/misc-ps-cxx0x.cpp

Ted Kremenek kremenek at apple.com
Tue May 24 13:41:32 PDT 2011


Author: kremenek
Date: Tue May 24 15:41:31 2011
New Revision: 132001

URL: http://llvm.org/viewvc/llvm-project?rev=132001&view=rev
Log:
Add explicit CFG support for ignoring static_asserts.

Added:
    cfe/trunk/test/Analysis/misc-ps-cxx0x.cpp
Modified:
    cfe/trunk/lib/Analysis/CFG.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=132001&r1=132000&r2=132001&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue May 24 15:41:31 2011
@@ -1323,6 +1323,7 @@
   if (isa<LabelDecl>(*DS->decl_begin()))
     return Block;
   
+  // This case also handles static_asserts.
   if (DS->isSingleDecl())
     return VisitDeclSubExpr(DS);
 
@@ -1355,7 +1356,14 @@
 /// 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) {

Added: cfe/trunk/test/Analysis/misc-ps-cxx0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps-cxx0x.cpp?rev=132001&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps-cxx0x.cpp (added)
+++ cfe/trunk/test/Analysis/misc-ps-cxx0x.cpp Tue May 24 15:41:31 2011
@@ -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}}
+}
+





More information about the cfe-commits mailing list