r185417 - Teach static analyzer about AttributedStmts

Pavel Labath labath at google.com
Tue Jul 2 02:38:48 PDT 2013


Author: labath
Date: Tue Jul  2 04:38:48 2013
New Revision: 185417

URL: http://llvm.org/viewvc/llvm-project?rev=185417&view=rev
Log:
Teach static analyzer about AttributedStmts

Summary:
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.

CC: cfe-commits

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

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
    cfe/trunk/test/Analysis/cxx11-crashes.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=185417&r1=185416&r2=185417&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Tue Jul  2 04:38:48 2013
@@ -652,7 +652,6 @@ void ExprEngine::Visit(const Stmt *S, Ex
     case Stmt::IfStmtClass:
     case Stmt::IndirectGotoStmtClass:
     case Stmt::LabelStmtClass:
-    case Stmt::AttributedStmtClass:
     case Stmt::NoStmtClass:
     case Stmt::NullStmtClass:
     case Stmt::SwitchStmtClass:
@@ -709,6 +708,7 @@ void ExprEngine::Visit(const Stmt *S, Ex
     // Cases we intentionally don't evaluate, since they don't need
     // to be explicitly evaluated.
     case Stmt::AddrLabelExprClass:
+    case Stmt::AttributedStmtClass:
     case Stmt::IntegerLiteralClass:
     case Stmt::CharacterLiteralClass:
     case Stmt::ImplicitValueInitExprClass:

Modified: cfe/trunk/test/Analysis/cxx11-crashes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cxx11-crashes.cpp?rev=185417&r1=185416&r2=185417&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/cxx11-crashes.cpp (original)
+++ cfe/trunk/test/Analysis/cxx11-crashes.cpp Tue Jul  2 04:38:48 2013
@@ -85,4 +85,12 @@ class SocketWireProtocolStream : public
 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]];
+  }
+}





More information about the cfe-commits mailing list