[llvm-commits] CVS: llvm/runtime/GCCLibraries/libexception/Exception.cpp Exception.h C++-Exception.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Aug 30 18:19:02 PDT 2003
Changes in directory llvm/runtime/GCCLibraries/libexception:
Exception.cpp added (r1.1)
Exception.h updated: 1.5 -> 1.6
C++-Exception.cpp updated: 1.7 -> 1.8
---
Log message:
Move language independent exception handling routines OUT of C++Exception.cpp
---
Diffs of the changes:
Index: llvm/runtime/GCCLibraries/libexception/Exception.cpp
diff -c /dev/null llvm/runtime/GCCLibraries/libexception/Exception.cpp:1.1
*** /dev/null Sat Aug 30 18:18:31 2003
--- llvm/runtime/GCCLibraries/libexception/Exception.cpp Sat Aug 30 18:17:51 2003
***************
*** 0 ****
--- 1,57 ----
+ //===- Exception.cpp - Generic language-independent exceptions ------------===//
+ //
+ // This file defines the the shared data structures used by all language
+ // specific exception handling runtime libraries.
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "Exception.h"
+ #include <cassert>
+
+ // Thread local state for exception handling. FIXME: This should really be made
+ // thread-local!
+
+ // UncaughtExceptionStack - The stack of exceptions currently being thrown.
+ static llvm_exception *UncaughtExceptionStack = 0;
+
+ // __llvm_eh_has_uncaught_exception - This is used to implement
+ // std::uncaught_exception.
+ //
+ bool __llvm_eh_has_uncaught_exception() throw() {
+ return UncaughtExceptionStack != 0;
+ }
+
+ // __llvm_eh_current_uncaught_exception - This function checks to see if the
+ // current uncaught exception is of the specified language type. If so, it
+ // returns a pointer to the exception area data.
+ //
+ void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
+ assert(UncaughtExceptionStack && "No uncaught exception!");
+ if (UncaughtExceptionStack->ExceptionType == HandlerType)
+ return UncaughtExceptionStack+1;
+ return 0;
+ }
+
+ // __llvm_eh_add_uncaught_exception - This adds the specified exception to the
+ // top of the uncaught exception stack. The exception should not already be on
+ // the stack!
+ void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw() {
+ E->Next = UncaughtExceptionStack;
+ UncaughtExceptionStack = E;
+ }
+
+
+ // __llvm_eh_get_uncaught_exception - Returns the current uncaught exception.
+ // There must be an uncaught exception for this to work!
+ llvm_exception *__llvm_eh_get_uncaught_exception() throw() {
+ assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?");
+ return UncaughtExceptionStack;
+ }
+
+ // __llvm_eh_pop_from_uncaught_stack - Remove the current uncaught exception
+ // from the top of the stack.
+ llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw() {
+ llvm_exception *E = __llvm_eh_get_uncaught_exception();
+ UncaughtExceptionStack = E->Next;
+ return E;
+ }
Index: llvm/runtime/GCCLibraries/libexception/Exception.h
diff -u llvm/runtime/GCCLibraries/libexception/Exception.h:1.5 llvm/runtime/GCCLibraries/libexception/Exception.h:1.6
--- llvm/runtime/GCCLibraries/libexception/Exception.h:1.5 Sat Aug 30 17:48:16 2003
+++ llvm/runtime/GCCLibraries/libexception/Exception.h Sat Aug 30 18:17:51 2003
@@ -52,6 +52,10 @@
extern "C" {
bool __llvm_eh_has_uncaught_exception() throw();
void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw();
+ void __llvm_eh_add_uncaught_exception(llvm_exception *E) throw();
+
+ llvm_exception *__llvm_eh_get_uncaught_exception() throw();
+ llvm_exception *__llvm_eh_pop_from_uncaught_stack() throw();
}
#endif
Index: llvm/runtime/GCCLibraries/libexception/C++-Exception.cpp
diff -u llvm/runtime/GCCLibraries/libexception/C++-Exception.cpp:1.7 llvm/runtime/GCCLibraries/libexception/C++-Exception.cpp:1.8
--- llvm/runtime/GCCLibraries/libexception/C++-Exception.cpp:1.7 Sat Aug 30 17:47:59 2003
+++ llvm/runtime/GCCLibraries/libexception/C++-Exception.cpp Sat Aug 30 18:17:51 2003
@@ -17,44 +17,14 @@
#include <stdio.h>
#endif
-//===----------------------------------------------------------------------===//
-// Generic exception support
-//
-
-// Thread local state for exception handling.
-// FIXME: This should really be made thread-local!
-//
-
// LastCaughtException - The last exception caught by this handler. This is for
// implementation of _rethrow and _get_last_caught.
//
-static llvm_exception *LastCaughtException = 0;
-
-// UncaughtExceptionStack - The stack of exceptions currently being thrown.
-static llvm_exception *UncaughtExceptionStack = 0;
-
-// __llvm_eh_has_uncaught_exception - This is used to implement
-// std::uncaught_exception.
+// FIXME: This should be thread-local!
//
-bool __llvm_eh_has_uncaught_exception() throw() {
- return UncaughtExceptionStack != 0;
-}
-
-// __llvm_eh_current_uncaught_exception - This function checks to see if the
-// current uncaught exception is of the specified language type. If so, it
-// returns a pointer to the exception area data.
-//
-void *__llvm_eh_current_uncaught_exception_type(unsigned HandlerType) throw() {
- assert(UncaughtExceptionStack && "No uncaught exception!");
- if (UncaughtExceptionStack->ExceptionType == HandlerType)
- return UncaughtExceptionStack+1;
- return 0;
-}
+static llvm_exception *LastCaughtException = 0;
-//===----------------------------------------------------------------------===//
-// C++ Specific exception handling support...
-//
using namespace __cxxabiv1;
// __llvm_cxxeh_allocate_exception - This function allocates space for the
@@ -113,8 +83,6 @@
llvm_cxx_exception *E = (llvm_cxx_exception *)ObjectPtr - 1;
E->BaseException.ExceptionDestructor = cxx_destructor;
E->BaseException.ExceptionType = CXXException;
- E->BaseException.Next = UncaughtExceptionStack;
- UncaughtExceptionStack = &E->BaseException;
E->BaseException.HandlerCount = 0;
E->BaseException.isRethrown = 0;
@@ -122,6 +90,8 @@
E->ExceptionObjectDestructor = DtorPtr;
E->UnexpectedHandler = __unexpected_handler;
E->TerminateHandler = __terminate_handler;
+
+ __llvm_eh_add_uncaught_exception(&E->BaseException);
}
@@ -163,16 +133,15 @@
// appropriate, otherwise it returns null.
//
void *__llvm_cxxeh_current_uncaught_exception_isa(void *CatchType) throw() {
- assert(UncaughtExceptionStack && "No uncaught exception!");
- if (UncaughtExceptionStack->ExceptionType != CXXException)
- return 0; // If it's not a c++ exception, it doesn't match!
+ void *EPtr = __llvm_eh_current_uncaught_exception_type(CXXException);
+ if (EPtr == 0) return 0; // If it's not a c++ exception, it doesn't match!
// If it is a C++ exception, use the type info object stored in the exception
// to see if TypeID matches and, if so, to adjust the exception object
// pointer.
//
const std::type_info *Info = (const std::type_info *)CatchType;
- return CXXExceptionISA(get_cxx_exception(UncaughtExceptionStack), Info);
+ return CXXExceptionISA((llvm_cxx_exception*)EPtr - 1, Info);
}
@@ -182,12 +151,8 @@
// function must work with foreign exceptions.
//
void *__llvm_cxxeh_begin_catch() throw() {
- llvm_exception *E = UncaughtExceptionStack;
- assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?");
+ llvm_exception *E = __llvm_eh_pop_from_uncaught_stack();
- // The exception is now no longer uncaught.
- UncaughtExceptionStack = E->Next;
-
// The exception is now caught.
LastCaughtException = E;
E->Next = 0;
@@ -254,9 +219,9 @@
// time.
void __llvm_cxxeh_call_terminate() throw() {
void (*Handler)(void) = __terminate_handler;
- if (UncaughtExceptionStack)
- if (UncaughtExceptionStack->ExceptionType == CXXException)
- Handler = get_cxx_exception(UncaughtExceptionStack)->TerminateHandler;
+ if (__llvm_eh_has_uncaught_exception())
+ if (void *EPtr = __llvm_eh_current_uncaught_exception_type(CXXException))
+ Handler = ((llvm_cxx_exception*)EPtr - 1)->TerminateHandler;
__terminate(Handler);
}
@@ -279,8 +244,7 @@
// Add the exception to the top of the uncaught stack, to preserve the
// invariant that the top of the uncaught stack is the current exception.
- E->Next = UncaughtExceptionStack;
- UncaughtExceptionStack = E;
+ __llvm_eh_add_uncaught_exception(E);
// Return to the caller, which should perform the unwind now.
}
@@ -320,8 +284,6 @@
//
void __llvm_cxxeh_check_eh_spec(void *Info, ...) {
const std::type_info *TypeInfo = (const std::type_info *)Info;
- llvm_exception *E = UncaughtExceptionStack;
- assert(E && "No uncaught exceptions!");
if (TypeInfo == 0) { // Empty exception specification
// Whatever exception this is, it is not allowed by the (empty) spec, call
@@ -337,6 +299,9 @@
}
}
+ llvm_exception *E = __llvm_eh_get_uncaught_exception();
+ assert(E && "No uncaught exceptions!");
+
// Check to see if the exception matches one of the types allowed by the
// exception specification. If so, return to the caller to have the
// exception rethrown.
@@ -369,8 +334,7 @@
// Grab the newly caught exception. If this exception is permitted by the
// specification, allow it to be thrown.
- E = UncaughtExceptionStack;
- assert(E && "No uncaught exceptions!");
+ E = __llvm_eh_get_uncaught_exception();
va_start(Args, Info);
Ok = ExceptionSpecificationPermitsException(E, TypeInfo, Args);
@@ -385,8 +349,7 @@
}
// Grab the new bad_exception...
- E = UncaughtExceptionStack;
- assert(E && "No uncaught exceptions!");
+ E = __llvm_eh_get_uncaught_exception();
// If it's permitted, allow it to be thrown instead.
va_start(Args, Info);
More information about the llvm-commits
mailing list