r207999 - MS ABI: Emit an error during IRgen on C++ exception handling

Reid Kleckner reid at kleckner.net
Mon May 5 14:12:12 PDT 2014


Author: rnk
Date: Mon May  5 16:12:12 2014
New Revision: 207999

URL: http://llvm.org/viewvc/llvm-project?rev=207999&view=rev
Log:
MS ABI: Emit an error during IRgen on C++ exception handling

Currently, users get error messages about RTTI descriptor mangling with
no useful source location.  This addresses that.

Another approach would be to disable C++ exceptions by default in the
driver when using the Microsoft C++ ABI.  However, this makes it
impossible to parse system headers that use exception handling
constructs.  By delaying the error to IRgen, we can figure out if we
actually need to emit code for this construct.  Additionally, users who
are only interested in building refactoring tools on Windows still get a
correct AST without having to add flags.  Finally, this is consistent
with what we do for SEH.

Added:
    cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=207999&r1=207998&r2=207999&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Mon May  5 16:12:12 2014
@@ -418,6 +418,11 @@ llvm::Value *CodeGenFunction::getSelecto
 
 void CodeGenFunction::EmitCXXThrowExpr(const CXXThrowExpr *E,
                                        bool KeepInsertionPoint) {
+  if (CGM.getTarget().getTriple().isWindowsMSVCEnvironment()) {
+    ErrorUnsupported(E, "throw expression");
+    return;
+  }
+
   if (!E->getSubExpr()) {
     EmitNoreturnRuntimeCallOrInvoke(getReThrowFn(CGM),
                                     ArrayRef<llvm::Value*>());
@@ -574,6 +579,11 @@ void CodeGenFunction::EmitEndEHSpec(cons
 }
 
 void CodeGenFunction::EmitCXXTryStmt(const CXXTryStmt &S) {
+  if (CGM.getTarget().getTriple().isWindowsMSVCEnvironment()) {
+    ErrorUnsupported(&S, "try statement");
+    return;
+  }
+
   EnterCXXTryStmt(S);
   EmitStmt(S.getTryBlock());
   ExitCXXTryStmt(S);

Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp?rev=207999&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-try-throw.cpp Mon May  5 16:12:12 2014
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -emit-llvm-only %s -triple=i386-pc-win32 -mconstructor-aliases -fcxx-exceptions -fexceptions -fno-rtti -verify -DTRY
+// RUN: %clang_cc1 -emit-llvm-only %s -triple=i386-pc-win32 -mconstructor-aliases -fcxx-exceptions -fexceptions -fno-rtti -verify -DTHROW
+
+void external();
+
+inline void not_emitted() {
+  throw int(13); // no error
+}
+
+int main() {
+  int rv = 0;
+#ifdef TRY
+  try { // expected-error {{cannot compile this try statement yet}}
+    external();
+  } catch (int) {
+    rv = 1;
+  }
+#endif
+#ifdef THROW
+  throw int(42); // expected-error {{cannot compile this throw expression yet}}
+#endif
+  return rv;
+}





More information about the cfe-commits mailing list