llvm.org GIT mirror llvm / 23b9b05
Add new __llvm_cxxeh_begin_catch_if_isa function, change C -> C++ comments git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8150 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
4 changed file(s) with 110 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
4141 }
4242
4343
44 /*===----------------------------------------------------------------------===**
45 * C++ Specific exception handling support...
46 */
44 //===----------------------------------------------------------------------===//
45 // C++ Specific exception handling support...
46 //
4747
4848 // __llvm_cxxeh_allocate_exception - This function allocates space for the
4949 // specified number of bytes, plus a C++ exception object header.
112112
113113 E->TypeInfo = TypeInfoPtr;
114114 E->ExceptionObjectDestructor = DtorPtr;
115 E->UnexpectedHandler = 0; /* FIXME */
116 E->TerminateHandler = 0; /* FIXME */
115 E->UnexpectedHandler = 0; // FIXME
116 E->TerminateHandler = 0; // FIXME
117117 }
118118
119119 // __llvm_cxxeh_current_uncaught_exception_isa - This function checks to see if
125125 const std::type_info *CatchType) {
126126 assert(UncaughtExceptionStack && "No uncaught exception!");
127127 if (UncaughtExceptionStack->ExceptionType != CXXException)
128 return 0; /* If it's not a c++ exception, it doesn't match! */
128 return 0; // If it's not a c++ exception, it doesn't match!
129129
130130 // If it is a C++ exception, use the type info object stored in the exception
131131 // to see if TypeID matches and, if so, to adjust the exception object
155155 }
156156
157157
158 /* __llvm_cxxeh_begin_catch - This function is called by "exception handlers",
159 * which transition an exception from being uncaught to being caught. It
160 * returns a pointer to the exception object portion of the exception. This
161 * function must work with foreign exceptions.
162 */
158 // __llvm_cxxeh_begin_catch - This function is called by "exception handlers",
159 // which transition an exception from being uncaught to being caught. It
160 // returns a pointer to the exception object portion of the exception. This
161 // function must work with foreign exceptions.
162 //
163163 void *__llvm_cxxeh_begin_catch(void) {
164164 llvm_exception *E = UncaughtExceptionStack;
165165 assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?");
166166
167 /* The exception is now no longer uncaught... */
167 // The exception is now no longer uncaught.
168168 UncaughtExceptionStack = E->Next;
169169
170 /* The exception is now caught... */
170 // The exception is now caught.
171171 E->Next = CaughtExceptionStack;
172172 CaughtExceptionStack = E->Next;
173173
174 /* Increment the handler count for this exception. */
174 // Increment the handler count for this exception.
175175 E->HandlerCount++;
176
177 /* Return a pointer to the exception object */
176
177 // Return a pointer to the raw exception object.
178178 return E+1;
179179 }
180180
181 /* __llvm_cxxeh_end_catch - This function decrements the HandlerCount of the
182 * top-level caught exception, destroying it if this is the last handler for the
183 * exception.
184 */
181 // __llvm_cxxeh_begin_catch_if_isa - This function checks to see if the current
182 // uncaught exception is of the specified type. If not, it returns a null
183 // pointer, otherwise it 'catches' the exception and returns a pointer to the
184 // object of the specified type. This function does never succeeds with foreign
185 // exceptions (because they can never be of type CatchType).
186 //
187 void *__llvm_cxxeh_begin_catch_if_isa(const std::type_info *CatchType) {
188 void *ObjPtr = __llvm_cxxeh_current_uncaught_exception_isa(CatchType);
189 if (!ObjPtr) return 0;
190
191 // begin_catch, meaning that the object is now "caught", not "uncaught"
192 __llvm_cxxeh_begin_catch();
193 return ObjPtr;
194 }
195
196
197 // __llvm_cxxeh_end_catch - This function decrements the HandlerCount of the
198 // top-level caught exception, destroying it if this is the last handler for the
199 // exception.
200 //
185201 void __llvm_cxxeh_end_catch(void) {
186202 llvm_exception *E = CaughtExceptionStack;
187203 assert(E && "There are no caught exceptions!");
188204
189 /* If this is the last handler using the exception, destroy it now! */
205 // If this is the last handler using the exception, destroy it now!
190206 if (--E->HandlerCount == 0) {
191 CaughtExceptionStack = E->Next; /* Unlink from the stack */
192 E->ExceptionDestructor(E); /* Release memory for the exception */
207 CaughtExceptionStack = E->Next; // Unlink from the stack
208 E->ExceptionDestructor(E); // Release memory for the exception
193209 }
194210 }
195211
196 /* __llvm_cxxeh_rethrow - This function turns the top-level caught exception
197 * into an uncaught exception, in preparation for an llvm.unwind, which should
198 * follow immediately after the call to this function. This function must be
199 * prepared to deal with foreign exceptions.
200 */
212 // __llvm_cxxeh_rethrow - This function turns the top-level caught exception
213 // into an uncaught exception, in preparation for an llvm.unwind, which should
214 // follow immediately after the call to this function. This function must be
215 // prepared to deal with foreign exceptions.
216 //
201217 void __llvm_cxxeh_rethrow(void) {
202218 llvm_exception *E = CaughtExceptionStack;
203219 if (E == 0) {
204 /* 15.1.8 - If there are no uncaught exceptions being thrown, 'throw;'
205 * should call terminate.
206 */
207 /* FIXME */assert(0 && "FIXME: this should call E->Terminate!");
220 // 15.1.8 - If there are no uncaught exceptions being thrown, 'throw;'
221 // should call terminate.
222 //
223 assert(0 && "FIXME: this should call E->Terminate!"); // FIXME!
208224 }
209225
210 /* Otherwise we have an exception to rethrow. Move it back to the uncaught
211 * stack.
212 */
226 // Otherwise we have an exception to rethrow. Move it back to the uncaught
227 // stack.
213228 CaughtExceptionStack = E->Next;
214229 E->Next = UncaughtExceptionStack;
215230 UncaughtExceptionStack = E;
216231
217 /* Decrement the number of handlers which are using the exception. */
232 // Decrement the number of handlers which are using the exception.
218233 --E->HandlerCount;
219234
220 /* Return to the caller, which should perform the unwind now. */
221 }
222
235 // Return to the caller, which should perform the unwind now.
236 }
237
5353
5454 void * __llvm_cxxeh_current_uncaught_exception_isa(const std::type_info *Ty);
5555 void *__llvm_cxxeh_begin_catch(void);
56 void *__llvm_cxxeh_begin_catch_if_isa(const std::type_info *CatchType);
5657 void __llvm_cxxeh_end_catch(void);
5758
5859 void __llvm_cxxeh_rethrow(void);
4141 }
4242
4343
44 /*===----------------------------------------------------------------------===**
45 * C++ Specific exception handling support...
46 */
44 //===----------------------------------------------------------------------===//
45 // C++ Specific exception handling support...
46 //
4747
4848 // __llvm_cxxeh_allocate_exception - This function allocates space for the
4949 // specified number of bytes, plus a C++ exception object header.
112112
113113 E->TypeInfo = TypeInfoPtr;
114114 E->ExceptionObjectDestructor = DtorPtr;
115 E->UnexpectedHandler = 0; /* FIXME */
116 E->TerminateHandler = 0; /* FIXME */
115 E->UnexpectedHandler = 0; // FIXME
116 E->TerminateHandler = 0; // FIXME
117117 }
118118
119119 // __llvm_cxxeh_current_uncaught_exception_isa - This function checks to see if
125125 const std::type_info *CatchType) {
126126 assert(UncaughtExceptionStack && "No uncaught exception!");
127127 if (UncaughtExceptionStack->ExceptionType != CXXException)
128 return 0; /* If it's not a c++ exception, it doesn't match! */
128 return 0; // If it's not a c++ exception, it doesn't match!
129129
130130 // If it is a C++ exception, use the type info object stored in the exception
131131 // to see if TypeID matches and, if so, to adjust the exception object
155155 }
156156
157157
158 /* __llvm_cxxeh_begin_catch - This function is called by "exception handlers",
159 * which transition an exception from being uncaught to being caught. It
160 * returns a pointer to the exception object portion of the exception. This
161 * function must work with foreign exceptions.
162 */
158 // __llvm_cxxeh_begin_catch - This function is called by "exception handlers",
159 // which transition an exception from being uncaught to being caught. It
160 // returns a pointer to the exception object portion of the exception. This
161 // function must work with foreign exceptions.
162 //
163163 void *__llvm_cxxeh_begin_catch(void) {
164164 llvm_exception *E = UncaughtExceptionStack;
165165 assert(UncaughtExceptionStack && "There are no uncaught exceptions!?!?");
166166
167 /* The exception is now no longer uncaught... */
167 // The exception is now no longer uncaught.
168168 UncaughtExceptionStack = E->Next;
169169
170 /* The exception is now caught... */
170 // The exception is now caught.
171171 E->Next = CaughtExceptionStack;
172172 CaughtExceptionStack = E->Next;
173173
174 /* Increment the handler count for this exception. */
174 // Increment the handler count for this exception.
175175 E->HandlerCount++;
176
177 /* Return a pointer to the exception object */
176
177 // Return a pointer to the raw exception object.
178178 return E+1;
179179 }
180180
181 /* __llvm_cxxeh_end_catch - This function decrements the HandlerCount of the
182 * top-level caught exception, destroying it if this is the last handler for the
183 * exception.
184 */
181 // __llvm_cxxeh_begin_catch_if_isa - This function checks to see if the current
182 // uncaught exception is of the specified type. If not, it returns a null
183 // pointer, otherwise it 'catches' the exception and returns a pointer to the
184 // object of the specified type. This function does never succeeds with foreign
185 // exceptions (because they can never be of type CatchType).
186 //
187 void *__llvm_cxxeh_begin_catch_if_isa(const std::type_info *CatchType) {
188 void *ObjPtr = __llvm_cxxeh_current_uncaught_exception_isa(CatchType);
189 if (!ObjPtr) return 0;
190
191 // begin_catch, meaning that the object is now "caught", not "uncaught"
192 __llvm_cxxeh_begin_catch();
193 return ObjPtr;
194 }
195
196
197 // __llvm_cxxeh_end_catch - This function decrements the HandlerCount of the
198 // top-level caught exception, destroying it if this is the last handler for the
199 // exception.
200 //
185201 void __llvm_cxxeh_end_catch(void) {
186202 llvm_exception *E = CaughtExceptionStack;
187203 assert(E && "There are no caught exceptions!");
188204
189 /* If this is the last handler using the exception, destroy it now! */
205 // If this is the last handler using the exception, destroy it now!
190206 if (--E->HandlerCount == 0) {
191 CaughtExceptionStack = E->Next; /* Unlink from the stack */
192 E->ExceptionDestructor(E); /* Release memory for the exception */
207 CaughtExceptionStack = E->Next; // Unlink from the stack
208 E->ExceptionDestructor(E); // Release memory for the exception
193209 }
194210 }
195211
196 /* __llvm_cxxeh_rethrow - This function turns the top-level caught exception
197 * into an uncaught exception, in preparation for an llvm.unwind, which should
198 * follow immediately after the call to this function. This function must be
199 * prepared to deal with foreign exceptions.
200 */
212 // __llvm_cxxeh_rethrow - This function turns the top-level caught exception
213 // into an uncaught exception, in preparation for an llvm.unwind, which should
214 // follow immediately after the call to this function. This function must be
215 // prepared to deal with foreign exceptions.
216 //
201217 void __llvm_cxxeh_rethrow(void) {
202218 llvm_exception *E = CaughtExceptionStack;
203219 if (E == 0) {
204 /* 15.1.8 - If there are no uncaught exceptions being thrown, 'throw;'
205 * should call terminate.
206 */
207 /* FIXME */assert(0 && "FIXME: this should call E->Terminate!");
220 // 15.1.8 - If there are no uncaught exceptions being thrown, 'throw;'
221 // should call terminate.
222 //
223 assert(0 && "FIXME: this should call E->Terminate!"); // FIXME!
208224 }
209225
210 /* Otherwise we have an exception to rethrow. Move it back to the uncaught
211 * stack.
212 */
226 // Otherwise we have an exception to rethrow. Move it back to the uncaught
227 // stack.
213228 CaughtExceptionStack = E->Next;
214229 E->Next = UncaughtExceptionStack;
215230 UncaughtExceptionStack = E;
216231
217 /* Decrement the number of handlers which are using the exception. */
232 // Decrement the number of handlers which are using the exception.
218233 --E->HandlerCount;
219234
220 /* Return to the caller, which should perform the unwind now. */
221 }
222
235 // Return to the caller, which should perform the unwind now.
236 }
237
5353
5454 void * __llvm_cxxeh_current_uncaught_exception_isa(const std::type_info *Ty);
5555 void *__llvm_cxxeh_begin_catch(void);
56 void *__llvm_cxxeh_begin_catch_if_isa(const std::type_info *CatchType);
5657 void __llvm_cxxeh_end_catch(void);
5758
5859 void __llvm_cxxeh_rethrow(void);