From 98592d9c4dff79480fdc25b83988de03f912b647 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 16 Sep 2013 21:46:30 +0000 Subject: [PATCH] Emit an error when attempting to generate IR for SEH __try Currently we silently omit the code in the try and finally bodies, which is pretty bad. This way we fail loudly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190809 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGException.cpp | 4 ++++ lib/CodeGen/CGStmt.cpp | 3 ++- lib/CodeGen/CodeGenFunction.h | 1 + test/CodeGen/exceptions-seh.c | 18 ++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/exceptions-seh.c diff --git a/lib/CodeGen/CGException.cpp b/lib/CodeGen/CGException.cpp index 0c2cfc4c07..1748621da3 100644 --- a/lib/CodeGen/CGException.cpp +++ b/lib/CodeGen/CGException.cpp @@ -1697,3 +1697,7 @@ llvm::BasicBlock *CodeGenFunction::getEHResumeBlock(bool isCleanup) { return EHResumeBlock; } + +void CodeGenFunction::EmitSEHTryStmt(const SEHTryStmt &S) { + CGM.ErrorUnsupported(&S, "SEH __try"); +} diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index e3095403f9..4492ea9a8f 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -168,8 +168,9 @@ void CodeGenFunction::EmitStmt(const Stmt *S) { break; case Stmt::CXXForRangeStmtClass: EmitCXXForRangeStmt(cast(*S)); + break; case Stmt::SEHTryStmtClass: - // FIXME Not yet implemented + EmitSEHTryStmt(cast(*S)); break; } } diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 20c0b82553..5889d05860 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1838,6 +1838,7 @@ public: void ExitCXXTryStmt(const CXXTryStmt &S, bool IsFnTryBlock = false); void EmitCXXTryStmt(const CXXTryStmt &S); + void EmitSEHTryStmt(const SEHTryStmt &S); void EmitCXXForRangeStmt(const CXXForRangeStmt &S); llvm::Function *EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K); diff --git a/test/CodeGen/exceptions-seh.c b/test/CodeGen/exceptions-seh.c new file mode 100644 index 0000000000..eadbe15cff --- /dev/null +++ b/test/CodeGen/exceptions-seh.c @@ -0,0 +1,18 @@ +// RUN: not %clang_cc1 -triple i686-pc-win32 -fexceptions -fms-extensions -emit-llvm -o - %s 2>&1 | FileCheck %s + +// This is a codegen test because we only emit the diagnostic when we start +// generating code. + +int SaveDiv(int numerator, int denominator, int *res) { + int myres = 0; + __try { + myres = numerator / denominator; + } __except (1) { + return 0; + } + *res = myres; + return 1; +} +// CHECK-NOT error +// CHECK: error: cannot compile this SEH __try yet +// CHECK-NOT error -- 2.40.0