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]];
+ }
+}
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]];
+ }
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits