[clang] ebcf030 - [analyzer] Engine: fix crash with SEH __leave keyword

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Mon May 17 11:12:24 PDT 2021


Author: Abbas Sabra
Date: 2021-05-17T20:10:26+02:00
New Revision: ebcf030efc5ef149e423f8fa2ca705b590a129ed

URL: https://github.com/llvm/llvm-project/commit/ebcf030efc5ef149e423f8fa2ca705b590a129ed
DIFF: https://github.com/llvm/llvm-project/commit/ebcf030efc5ef149e423f8fa2ca705b590a129ed.diff

LOG: [analyzer] Engine: fix crash with SEH __leave keyword

MSVC has a `try-except` statement.
This statement could containt a `__leave` keyword, which is similar to
`goto` to the end of the try block. The semantic of this keyword is not
implemented.

We should at least parse such code without crashing.

https://docs.microsoft.com/en-us/cpp/cpp/try-except-statement?view=msvc-160

Patch By: AbbasSabra!

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D102280

Added: 
    clang/test/Analysis/ms-seh.cpp

Modified: 
    clang/lib/StaticAnalyzer/Core/CoreEngine.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 70deb13a8e1ae..ae45ae5aa02f3 100644
--- a/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -349,6 +349,7 @@ void CoreEngine::HandleBlockExit(const CFGBlock * B, ExplodedNode *Pred) {
         HandleBranch(cast<ForStmt>(Term)->getCond(), Term, B, Pred);
         return;
 
+      case Stmt::SEHLeaveStmtClass:
       case Stmt::ContinueStmtClass:
       case Stmt::BreakStmtClass:
       case Stmt::GotoStmtClass:

diff  --git a/clang/test/Analysis/ms-seh.cpp b/clang/test/Analysis/ms-seh.cpp
new file mode 100644
index 0000000000000..a2f01f8080746
--- /dev/null
+++ b/clang/test/Analysis/ms-seh.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -triple x86_64-pc-windows-msvc19.11.0 -fms-extensions -verify %s
+
+void clang_analyzer_warnIfReached();
+int filter();
+
+void try_except_leave() {
+  __try {
+    __leave;                        // no-crash
+    clang_analyzer_warnIfReached(); // no-warning
+  } __except (filter()) {
+  }
+  clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+}


        


More information about the cfe-commits mailing list