[llvm-commits] [PATCH] Use Win32 SEH in Win32/Signals.inc instead of C++ EH.

Mikhail Glushenkov foldr at codedgers.com
Fri Oct 22 17:50:53 PDT 2010


This is an alternative patch, which is more complicated, but does what was
originally intended. Also, according to [1] __try1/__except1 macros don't work
on newer versions of MinGW GCC.

[1] http://www.programmingunlimited.net/siteexec/content.cgi?page=mingw-seh
---
 lib/System/Makefile          |    5 -----
 lib/System/Win32/Signals.inc |   36 +++++++++++++++++++++++++++++++++---
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/lib/System/Makefile b/lib/System/Makefile
index bb013b9..5d4fda9 100644
--- a/lib/System/Makefile
+++ b/lib/System/Makefile
@@ -11,11 +11,6 @@ LEVEL = ../..
 LIBRARYNAME = LLVMSystem
 BUILD_ARCHIVE = 1
 REQUIRES_RTTI = 1
-include $(LEVEL)/Makefile.config
-
-ifeq ($(HOST_OS),MingW)
-  REQUIRES_EH := 1
-endif
 
 EXTRA_DIST = Unix Win32 README.txt
 
diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc
index 8f880f7..75fc142 100644
--- a/lib/System/Win32/Signals.inc
+++ b/lib/System/Win32/Signals.inc
@@ -18,6 +18,7 @@
 
 #ifdef __MINGW32__
  #include <imagehlp.h>
+ #include <excpt.h>
 #else
  #include <dbghelp.h>
 #endif
@@ -207,8 +208,26 @@ void llvm::sys::RunInterruptHandlers() {
   Cleanup();
 }
 
+#ifdef __MINGW32__
+
+EXCEPTION_DISPOSITION LLVMUnhandledExceptionFilterExceptionHandler
+(_EXCEPTION_RECORD*, void*, _CONTEXT*, void*) {
+  fprintf(stderr, "Crashed in LLVMUnhandledExceptionFilter");
+  ExitProcess(1);
+}
+
+#endif // __MINGW32__
+
+
 static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
-  try {
+
+#ifdef __MINGW32__
+  __try1(LLVMUnhandledExceptionFilterExceptionHandler);
+#elif defined(_MSC_VER)
+  __try
+#endif
+
+  {
     Cleanup();
 
 #ifdef _WIN64
@@ -291,12 +310,23 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep) {
 
 #endif
 
-  } catch (...) {
-      assert(0 && "Crashed in LLVMUnhandledExceptionFilter");
   }
 
+#ifdef __MINGW32__
+  __except1;
+#elif defined(_MSC_VER)
+  __finally {
+    if (AbnormalTermination()) {
+      fprintf(stderr, "Crashed in LLVMUnhandledExceptionFilter");
+      ExitProcess(1);
+    }
+  }
+#endif
+
+#ifdef _MSC_VER
   if (ExitOnUnhandledExceptions)
     _exit(-3);
+#endif
 
   // Allow dialog box to pop up allowing choice to start debugger.
   if (OldFilter)
-- 
1.7.3.2




More information about the llvm-commits mailing list