[PATCH] Teach static analyzer about AttributedStmts

Pavel Labath labath at google.com
Mon Jun 24 03:32:25 PDT 2013


Static analyzer used to abort when encountering AttributedStmts, because it
asserted that the statements should not appear in the CFG. This is however not
the case, since at least the clang::fallthrough annotation makes it through.

This commit simply makes the analyzer ignore the statement attributes. If any
attribute actually required special handling, it can be added later.

http://llvm-reviews.chandlerc.com/D1030

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/cxx11-crashes.cpp

Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===================================================================
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -652,9 +652,7 @@
     case Stmt::IfStmtClass:
     case Stmt::IndirectGotoStmtClass:
     case Stmt::LabelStmtClass:
-    case Stmt::AttributedStmtClass:
     case Stmt::NoStmtClass:
-    case Stmt::NullStmtClass:
     case Stmt::SwitchStmtClass:
     case Stmt::WhileStmtClass:
     case Expr::MSDependentExistsStmtClass:
@@ -665,6 +663,14 @@
     case Stmt::ObjCPropertyRefExprClass:
       llvm_unreachable("These are handled by PseudoObjectExpr");
 
+    case Stmt::AttributedStmtClass:
+      Visit(cast<AttributedStmt>(S)->getSubStmt(), Pred, DstTop);
+      break;
+
+    case Stmt::NullStmtClass:
+      Bldr.generateNode(S, Pred, Pred->getState());
+      break;
+
     case Stmt::GNUNullExprClass: {
       // GNU __null is a pointer-width integer, not an actual pointer.
       ProgramStateRef state = Pred->getState();
Index: test/Analysis/cxx11-crashes.cpp
===================================================================
--- test/Analysis/cxx11-crashes.cpp
+++ test/Analysis/cxx11-crashes.cpp
@@ -85,4 +85,12 @@
 void test() {
   SocketWireProtocolStream stream{};
   JSONWireProtocolReader reader{stream};
-}
\ No newline at end of file
+}
+
+// this crashed because the analyzer did not understand AttributedStmts
+void fallthrough() {
+  switch (1) {
+    case 1:
+      [[clang::fallthrough]];
+  }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1030.1.patch
Type: text/x-patch
Size: 1526 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130624/5fd2317f/attachment.bin>


More information about the cfe-commits mailing list