blob: 41be8ab23bdebbeb8150fed8b732afd0becccf7e [file] [log] [blame]
Jim Laskeyd0d39b62007-03-14 19:29:42 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5 <title>Exception Handling in LLVM</title>
Bill Wendlingc4f661e2009-08-15 08:56:09 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Eric Christopher61f69782009-09-09 01:44:53 +00007 <meta name="description"
Bill Wendlingc4f661e2009-08-15 08:56:09 +00008 content="Exception Handling in LLVM.">
Jim Laskeyd0d39b62007-03-14 19:29:42 +00009 <link rel="stylesheet" href="llvm.css" type="text/css">
10</head>
Bill Wendlingc4f661e2009-08-15 08:56:09 +000011
Jim Laskeyd0d39b62007-03-14 19:29:42 +000012<body>
13
14<div class="doc_title">Exception Handling in LLVM</div>
15
16<table class="layout" style="width:100%">
17 <tr class="layout">
18 <td class="left">
19<ul>
20 <li><a href="#introduction">Introduction</a>
21 <ol>
22 <li><a href="#itanium">Itanium ABI Zero-cost Exception Handling</a></li>
Jim Grosbach00484d12009-08-22 01:42:39 +000023 <li><a href="#sjlj">Setjmp/Longjmp Exception Handling</a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000024 <li><a href="#overview">Overview</a></li>
25 </ol></li>
26 <li><a href="#codegen">LLVM Code Generation</a>
27 <ol>
28 <li><a href="#throw">Throw</a></li>
29 <li><a href="#try_catch">Try/Catch</a></li>
Duncan Sands6590b042007-08-27 15:47:50 +000030 <li><a href="#cleanups">Cleanups</a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000031 <li><a href="#throw_filters">Throw Filters</a></li>
Duncan Sands6590b042007-08-27 15:47:50 +000032 <li><a href="#restrictions">Restrictions</a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000033 </ol></li>
Duncan Sands8036ca42007-03-30 12:22:09 +000034 <li><a href="#format_common_intrinsics">Exception Handling Intrinsics</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000035 <ol>
36 <li><a href="#llvm_eh_exception"><tt>llvm.eh.exception</tt></a></li>
37 <li><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000038 <li><a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a></li>
Jim Grosbachf9570122009-05-14 00:46:35 +000039 <li><a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a></li>
40 <li><a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a></li>
Jim Grosbach1b747ad2009-08-11 00:09:57 +000041 <li><a href="#llvm_eh_sjlj_lsda"><tt>llvm.eh.sjlj.lsda</tt></a></li>
Jim Grosbachca752c92010-01-28 01:45:32 +000042 <li><a href="#llvm_eh_sjlj_callsite"><tt>llvm.eh.sjlj.callsite</tt></a></li>
Jim Grosbache4ad3872010-10-19 23:27:08 +000043 <li><a href="#llvm_eh_sjlj_dispatchsetup"><tt>llvm.eh.sjlj.dispatchsetup</tt></a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000044 </ol></li>
45 <li><a href="#asm">Asm Table Formats</a>
46 <ol>
47 <li><a href="#unwind_tables">Exception Handling Frame</a></li>
48 <li><a href="#exception_tables">Exception Tables</a></li>
49 </ol></li>
50 <li><a href="#todo">ToDo</a></li>
51</ul>
52</td>
53</tr></table>
54
55<div class="doc_author">
56 <p>Written by <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
57</div>
58
59
60<!-- *********************************************************************** -->
Eric Christopher61f69782009-09-09 01:44:53 +000061<div class="doc_section"><a name="introduction">Introduction</a></div>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000062<!-- *********************************************************************** -->
63
64<div class="doc_text">
65
66<p>This document is the central repository for all information pertaining to
Bill Wendlingc4f661e2009-08-15 08:56:09 +000067 exception handling in LLVM. It describes the format that LLVM exception
68 handling information takes, which is useful for those interested in creating
69 front-ends or dealing directly with the information. Further, this document
70 provides specific examples of what exception handling information is used for
71 in C/C++.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000072
73</div>
74
75<!-- ======================================================================= -->
76<div class="doc_subsection">
77 <a name="itanium">Itanium ABI Zero-cost Exception Handling</a>
78</div>
79
80<div class="doc_text">
81
82<p>Exception handling for most programming languages is designed to recover from
Bill Wendlingc4f661e2009-08-15 08:56:09 +000083 conditions that rarely occur during general use of an application. To that
84 end, exception handling should not interfere with the main flow of an
85 application's algorithm by performing checkpointing tasks, such as saving the
86 current pc or register state.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000087
88<p>The Itanium ABI Exception Handling Specification defines a methodology for
Bill Wendlingc4f661e2009-08-15 08:56:09 +000089 providing outlying data in the form of exception tables without inlining
90 speculative exception handling code in the flow of an application's main
91 algorithm. Thus, the specification is said to add "zero-cost" to the normal
92 execution of an application.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000093
94<p>A more complete description of the Itanium ABI exception handling runtime
Bill Wendlingc4f661e2009-08-15 08:56:09 +000095 support of can be found at
96 <a href="http://www.codesourcery.com/cxx-abi/abi-eh.html">Itanium C++ ABI:
97 Exception Handling</a>. A description of the exception frame format can be
98 found at
99 <a href="http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html">Exception
100 Frames</a>, with details of the DWARF 3 specification at
101 <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3 Standard</a>.
102 A description for the C++ exception table formats can be found at
103 <a href="http://www.codesourcery.com/cxx-abi/exceptions.pdf">Exception Handling
104 Tables</a>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000105
106</div>
107
108<!-- ======================================================================= -->
109<div class="doc_subsection">
Jim Grosbach00484d12009-08-22 01:42:39 +0000110 <a name="sjlj">Setjmp/Longjmp Exception Handling</a>
111</div>
112
113<div class="doc_text">
114
115<p>Setjmp/Longjmp (SJLJ) based exception handling uses LLVM intrinsics
116 <a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a> and
117 <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a> to
118 handle control flow for exception handling.</p>
119
120<p>For each function which does exception processing, be it try/catch blocks
121 or cleanups, that function registers itself on a global frame list. When
122 exceptions are being unwound, the runtime uses this list to identify which
123 functions need processing.<p>
124
125<p>Landing pad selection is encoded in the call site entry of the function
126 context. The runtime returns to the function via
127 <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a>, where
128 a switch table transfers control to the appropriate landing pad based on
129 the index stored in the function context.</p>
130
131<p>In contrast to DWARF exception handling, which encodes exception regions
132 and frame information in out-of-line tables, SJLJ exception handling
133 builds and removes the unwind frame context at runtime. This results in
134 faster exception handling at the expense of slower execution when no
135 exceptions are thrown. As exceptions are, by their nature, intended for
136 uncommon code paths, DWARF exception handling is generally preferred to
137 SJLJ.</p>
138</div>
139
140<!-- ======================================================================= -->
141<div class="doc_subsection">
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000142 <a name="overview">Overview</a>
143</div>
144
145<div class="doc_text">
146
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000147<p>When an exception is thrown in LLVM code, the runtime does its best to find a
148 handler suited to processing the circumstance.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000149
150<p>The runtime first attempts to find an <i>exception frame</i> corresponding to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000151 the function where the exception was thrown. If the programming language
152 (e.g. C++) supports exception handling, the exception frame contains a
153 reference to an exception table describing how to process the exception. If
154 the language (e.g. C) does not support exception handling, or if the
155 exception needs to be forwarded to a prior activation, the exception frame
156 contains information about how to unwind the current activation and restore
157 the state of the prior activation. This process is repeated until the
158 exception is handled. If the exception is not handled and no activations
159 remain, then the application is terminated with an appropriate error
160 message.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000161
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000162<p>Because different programming languages have different behaviors when
163 handling exceptions, the exception handling ABI provides a mechanism for
164 supplying <i>personalities.</i> An exception handling personality is defined
165 by way of a <i>personality function</i> (e.g. <tt>__gxx_personality_v0</tt>
166 in C++), which receives the context of the exception, an <i>exception
167 structure</i> containing the exception object type and value, and a reference
168 to the exception table for the current function. The personality function
169 for the current compile unit is specified in a <i>common exception
170 frame</i>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000171
172<p>The organization of an exception table is language dependent. For C++, an
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000173 exception table is organized as a series of code ranges defining what to do
174 if an exception occurs in that range. Typically, the information associated
175 with a range defines which types of exception objects (using C++ <i>type
176 info</i>) that are handled in that range, and an associated action that
177 should take place. Actions typically pass control to a <i>landing
178 pad</i>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000179
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000180<p>A landing pad corresponds to the code found in the <i>catch</i> portion of
181 a <i>try</i>/<i>catch</i> sequence. When execution resumes at a landing
182 pad, it receives the exception structure and a selector corresponding to
183 the <i>type</i> of exception thrown. The selector is then used to determine
184 which <i>catch</i> should actually process the exception.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000185
186</div>
187
188<!-- ======================================================================= -->
189<div class="doc_section">
190 <a name="codegen">LLVM Code Generation</a>
191</div>
192
193<div class="doc_text">
194
195<p>At the time of this writing, only C++ exception handling support is available
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000196 in LLVM. So the remainder of this document will be somewhat C++-centric.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000197
198<p>From the C++ developers perspective, exceptions are defined in terms of the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000199 <tt>throw</tt> and <tt>try</tt>/<tt>catch</tt> statements. In this section
200 we will describe the implementation of LLVM exception handling in terms of
201 C++ examples.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000202
203</div>
204
205<!-- ======================================================================= -->
206<div class="doc_subsection">
207 <a name="throw">Throw</a>
208</div>
209
210<div class="doc_text">
211
212<p>Languages that support exception handling typically provide a <tt>throw</tt>
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000213 operation to initiate the exception process. Internally, a throw operation
214 breaks down into two steps. First, a request is made to allocate exception
215 space for an exception structure. This structure needs to survive beyond the
216 current activation. This structure will contain the type and value of the
217 object being thrown. Second, a call is made to the runtime to raise the
218 exception, passing the exception structure as an argument.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000219
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000220<p>In C++, the allocation of the exception structure is done by
221 the <tt>__cxa_allocate_exception</tt> runtime function. The exception
222 raising is handled by <tt>__cxa_throw</tt>. The type of the exception is
223 represented using a C++ RTTI structure.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000224
225</div>
226
227<!-- ======================================================================= -->
228<div class="doc_subsection">
229 <a name="try_catch">Try/Catch</a>
230</div>
231
232<div class="doc_text">
233
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000234<p>A call within the scope of a <i>try</i> statement can potentially raise an
235 exception. In those circumstances, the LLVM C++ front-end replaces the call
236 with an <tt>invoke</tt> instruction. Unlike a call, the <tt>invoke</tt> has
237 two potential continuation points: where to continue when the call succeeds
238 as per normal; and where to continue if the call raises an exception, either
239 by a throw or the unwinding of a throw.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000240
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000241<p>The term used to define a the place where an <tt>invoke</tt> continues after
242 an exception is called a <i>landing pad</i>. LLVM landing pads are
243 conceptually alternative function entry points where an exception structure
244 reference and a type info index are passed in as arguments. The landing pad
245 saves the exception structure reference and then proceeds to select the catch
246 block that corresponds to the type info of the exception object.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000247
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000248<p>Two LLVM intrinsic functions are used to convey information about the landing
249 pad to the back end.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000250
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000251<ol>
252 <li><a href="#llvm_eh_exception"><tt>llvm.eh.exception</tt></a> takes no
253 arguments and returns a pointer to the exception structure. This only
254 returns a sensible value if called after an <tt>invoke</tt> has branched
255 to a landing pad. Due to code generation limitations, it must currently
256 be called in the landing pad itself.</li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000257
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000258 <li><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> takes a minimum
259 of three arguments. The first argument is the reference to the exception
260 structure. The second argument is a reference to the personality function
261 to be used for this <tt>try</tt>/<tt>catch</tt> sequence. Each of the
262 remaining arguments is either a reference to the type info for
263 a <tt>catch</tt> statement, a <a href="#throw_filters">filter</a>
264 expression, or the number zero (<tt>0</tt>) representing
265 a <a href="#cleanups">cleanup</a>. The exception is tested against the
266 arguments sequentially from first to last. The result of
267 the <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> is a
268 positive number if the exception matched a type info, a negative number if
269 it matched a filter, and zero if it matched a cleanup. If nothing is
270 matched, the behaviour of the program
271 is <a href="#restrictions">undefined</a>. This only returns a sensible
272 value if called after an <tt>invoke</tt> has branched to a landing pad.
273 Due to codegen limitations, it must currently be called in the landing pad
274 itself. If a type info matched, then the selector value is the index of
275 the type info in the exception table, which can be obtained using the
276 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a>
277 intrinsic.</li>
278</ol>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000279
280<p>Once the landing pad has the type info selector, the code branches to the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000281 code for the first catch. The catch then checks the value of the type info
282 selector against the index of type info for that catch. Since the type info
283 index is not known until all the type info have been gathered in the backend,
284 the catch code will call the
285 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic
286 to determine the index for a given type info. If the catch fails to match
287 the selector then control is passed on to the next catch. Note: Since the
288 landing pad will not be used if there is no match in the list of type info on
289 the call to <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>, then
290 neither the last catch nor <i>catch all</i> need to perform the check
291 against the selector.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000292
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000293<p>Finally, the entry and exit of catch code is bracketed with calls
294 to <tt>__cxa_begin_catch</tt> and <tt>__cxa_end_catch</tt>.</p>
295
296<ul>
297 <li><tt>__cxa_begin_catch</tt> takes a exception structure reference as an
298 argument and returns the value of the exception object.</li>
299
Bill Wendling169e1b02009-09-10 22:14:16 +0000300 <li><tt>__cxa_end_catch</tt> takes no arguments. This function:<br><br>
301 <ol>
Bill Wendling808b9ce2009-09-10 22:12:50 +0000302 <li>Locates the most recently caught exception and decrements its handler
303 count,</li>
304 <li>Removes the exception from the "caught" stack if the handler count
305 goes to zero, and</li>
306 <li>Destroys the exception if the handler count goes to zero, and the
307 exception was not re-thrown by throw.</li>
Bill Wendling169e1b02009-09-10 22:14:16 +0000308 </ol>
Bill Wendling808b9ce2009-09-10 22:12:50 +0000309 <p>Note: a rethrow from within the catch may replace this call with
310 a <tt>__cxa_rethrow</tt>.</p></li>
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000311</ul>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000312
313</div>
314
315<!-- ======================================================================= -->
316<div class="doc_subsection">
Duncan Sands6590b042007-08-27 15:47:50 +0000317 <a name="cleanups">Cleanups</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000318</div>
319
320<div class="doc_text">
321
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000322<p>To handle destructors and cleanups in <tt>try</tt> code, control may not run
323 directly from a landing pad to the first catch. Control may actually flow
324 from the landing pad to clean up code and then to the first catch. Since the
325 required clean up for each <tt>invoke</tt> in a <tt>try</tt> may be different
326 (e.g. intervening constructor), there may be several landing pads for a given
Jim Grosbach00484d12009-08-22 01:42:39 +0000327 try. If cleanups need to be run, an <tt>i32 0</tt> should be passed as the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000328 last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> argument.
Jim Grosbach00484d12009-08-22 01:42:39 +0000329 However, when using DWARF exception handling with C++, a <tt>i8* null</tt>
330 <a href="#restrictions">must</a> be passed instead.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000331
332</div>
333
334<!-- ======================================================================= -->
335<div class="doc_subsection">
336 <a name="throw_filters">Throw Filters</a>
337</div>
338
339<div class="doc_text">
340
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000341<p>C++ allows the specification of which exception types can be thrown from a
342 function. To represent this a top level landing pad may exist to filter out
343 invalid types. To express this in LLVM code the landing pad will
344 call <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>. The
345 arguments are a reference to the exception structure, a reference to the
346 personality function, the length of the filter expression (the number of type
347 infos plus one), followed by the type infos themselves.
348 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> will return a
349 negative value if the exception does not match any of the type infos. If no
350 match is found then a call to <tt>__cxa_call_unexpected</tt> should be made,
351 otherwise <tt>_Unwind_Resume</tt>. Each of these functions requires a
352 reference to the exception structure. Note that the most general form of an
353 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> call can contain
354 any number of type infos, filter expressions and cleanups (though having more
355 than one cleanup is pointless). The LLVM C++ front-end can generate such
356 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> calls due to
357 inlining creating nested exception handling scopes.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000358
359</div>
360
361<!-- ======================================================================= -->
Duncan Sands6590b042007-08-27 15:47:50 +0000362<div class="doc_subsection">
363 <a name="restrictions">Restrictions</a>
364</div>
365
366<div class="doc_text">
367
368<p>The semantics of the invoke instruction require that any exception that
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000369 unwinds through an invoke call should result in a branch to the invoke's
370 unwind label. However such a branch will only happen if the
371 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> matches. Thus in
372 order to ensure correct operation, the front-end must only generate
373 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> calls that are
374 guaranteed to always match whatever exception unwinds through the invoke.
375 For most languages it is enough to pass zero, indicating the presence of
376 a <a href="#cleanups">cleanup</a>, as the
377 last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> argument.
378 However for C++ this is not sufficient, because the C++ personality function
379 will terminate the program if it detects that unwinding the exception only
380 results in matches with cleanups. For C++ a <tt>null i8*</tt> should be
381 passed as the last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>
382 argument instead. This is interpreted as a catch-all by the C++ personality
383 function, and will always match.</p>
Duncan Sands6590b042007-08-27 15:47:50 +0000384
385</div>
386
387<!-- ======================================================================= -->
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000388<div class="doc_section">
Duncan Sands8036ca42007-03-30 12:22:09 +0000389 <a name="format_common_intrinsics">Exception Handling Intrinsics</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000390</div>
391
392<div class="doc_text">
393
394<p>LLVM uses several intrinsic functions (name prefixed with "llvm.eh") to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000395 provide exception handling information at various points in generated
396 code.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000397
398</div>
399
400<!-- ======================================================================= -->
401<div class="doc_subsubsection">
402 <a name="llvm_eh_exception">llvm.eh.exception</a>
403</div>
404
405<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000406
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000407<pre>
Dan Gohman3dfb3cf2010-05-28 17:07:41 +0000408 i8* %<a href="#llvm_eh_exception">llvm.eh.exception</a>()
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000409</pre>
410
Duncan Sands6531d472008-12-29 15:27:32 +0000411<p>This intrinsic returns a pointer to the exception structure.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000412
413</div>
414
415<!-- ======================================================================= -->
416<div class="doc_subsubsection">
417 <a name="llvm_eh_selector">llvm.eh.selector</a>
418</div>
419
420<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000421
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000422<pre>
Duncan Sandsb01bbdc2009-10-14 16:11:37 +0000423 i32 %<a href="#llvm_eh_selector">llvm.eh.selector</a>(i8*, i8*, i8*, ...)
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000424</pre>
425
Duncan Sands6531d472008-12-29 15:27:32 +0000426<p>This intrinsic is used to compare the exception with the given type infos,
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000427 filters and cleanups.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000428
429<p><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> takes a minimum of
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000430 three arguments. The first argument is the reference to the exception
431 structure. The second argument is a reference to the personality function to
432 be used for this try catch sequence. Each of the remaining arguments is
433 either a reference to the type info for a catch statement,
434 a <a href="#throw_filters">filter</a> expression, or the number zero
435 representing a <a href="#cleanups">cleanup</a>. The exception is tested
436 against the arguments sequentially from first to last. The result of
437 the <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> is a positive
438 number if the exception matched a type info, a negative number if it matched
439 a filter, and zero if it matched a cleanup. If nothing is matched, the
440 behaviour of the program is <a href="#restrictions">undefined</a>. If a type
441 info matched then the selector value is the index of the type info in the
442 exception table, which can be obtained using the
443 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000444
445</div>
446
447<!-- ======================================================================= -->
448<div class="doc_subsubsection">
449 <a name="llvm_eh_typeid_for">llvm.eh.typeid.for</a>
450</div>
451
452<div class="doc_text">
Bill Wendlingbf230bf2009-08-15 20:08:04 +0000453
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000454<pre>
Duncan Sandsb01bbdc2009-10-14 16:11:37 +0000455 i32 %<a href="#llvm_eh_typeid_for">llvm.eh.typeid.for</a>(i8*)
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000456</pre>
457
458<p>This intrinsic returns the type info index in the exception table of the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000459 current function. This value can be used to compare against the result
460 of <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>. The single
461 argument is a reference to a type info.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000462
463</div>
464
465<!-- ======================================================================= -->
Jim Grosbachf9570122009-05-14 00:46:35 +0000466<div class="doc_subsubsection">
467 <a name="llvm_eh_sjlj_setjmp">llvm.eh.sjlj.setjmp</a>
468</div>
469
470<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000471
Jim Grosbachf9570122009-05-14 00:46:35 +0000472<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000473 i32 %<a href="#llvm_eh_sjlj_setjmp">llvm.eh.sjlj.setjmp</a>(i8*)
Jim Grosbachf9570122009-05-14 00:46:35 +0000474</pre>
475
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000476<p>The SJLJ exception handling uses this intrinsic to force register saving for
477 the current function and to store the address of the following instruction
478 for use as a destination address by <a href="#llvm_eh_sjlj_longjmp">
479 <tt>llvm.eh.sjlj.longjmp</tt></a>. The buffer format and the overall
480 functioning of this intrinsic is compatible with the GCC
481 <tt>__builtin_setjmp</tt> implementation, allowing code built with the
482 two compilers to interoperate.</p>
Jim Grosbachf9570122009-05-14 00:46:35 +0000483
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000484<p>The single parameter is a pointer to a five word buffer in which the calling
485 context is saved. The front end places the frame pointer in the first word,
486 and the target implementation of this intrinsic should place the destination
487 address for a
488 <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a> in the
489 second word. The following three words are available for use in a
490 target-specific manner.</p>
Jim Grosbachf9570122009-05-14 00:46:35 +0000491
Benjamin Kramere15192b2009-08-05 15:42:44 +0000492</div>
493
Jim Grosbachf9570122009-05-14 00:46:35 +0000494<!-- ======================================================================= -->
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000495<div class="doc_subsubsection">
Jim Grosbach90346e22010-05-26 16:21:41 +0000496 <a name="llvm_eh_sjlj_longjmp">llvm.eh.sjlj.longjmp</a>
497</div>
498
499<div class="doc_text">
500
501<pre>
502 void %<a href="#llvm_eh_sjlj_longjmp">llvm.eh.sjlj.setjmp</a>(i8*)
503</pre>
504
505<p>The <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a>
506 intrinsic is used to implement <tt>__builtin_longjmp()</tt> for SJLJ
507 style exception handling. The single parameter is a pointer to a
508 buffer populated by <a href="#llvm_eh_sjlj_setjmp">
509 <tt>llvm.eh.sjlj.setjmp</tt></a>. The frame pointer and stack pointer
510 are restored from the buffer, then control is transfered to the
511 destination address.</p>
512
513</div>
514<!-- ======================================================================= -->
515<div class="doc_subsubsection">
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000516 <a name="llvm_eh_sjlj_lsda">llvm.eh.sjlj.lsda</a>
517</div>
518
519<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000520
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000521<pre>
Dan Gohman3dfb3cf2010-05-28 17:07:41 +0000522 i8* %<a href="#llvm_eh_sjlj_lsda">llvm.eh.sjlj.lsda</a>()
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000523</pre>
524
525<p>Used for SJLJ based exception handling, the <a href="#llvm_eh_sjlj_lsda">
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000526 <tt>llvm.eh.sjlj.lsda</tt></a> intrinsic returns the address of the Language
527 Specific Data Area (LSDA) for the current function. The SJLJ front-end code
528 stores this address in the exception handling function context for use by the
529 runtime.</p>
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000530
531</div>
532
533<!-- ======================================================================= -->
Jim Grosbachca752c92010-01-28 01:45:32 +0000534<div class="doc_subsubsection">
535 <a name="llvm_eh_sjlj_callsite">llvm.eh.sjlj.callsite</a>
536</div>
537
538<div class="doc_text">
539
540<pre>
541 void %<a href="#llvm_eh_sjlj_callsite">llvm.eh.sjlj.callsite</a>(i32)
542</pre>
543
544<p>For SJLJ based exception handling, the <a href="#llvm_eh_sjlj_callsite">
545 <tt>llvm.eh.sjlj.callsite</tt></a> intrinsic identifies the callsite value
546 associated with the following invoke instruction. This is used to ensure
547 that landing pad entries in the LSDA are generated in the matching order.</p>
548
549</div>
550
551<!-- ======================================================================= -->
Jim Grosbache4ad3872010-10-19 23:27:08 +0000552<div class="doc_subsubsection">
553 <a name="llvm_eh_sjlj_dispatchsetup">llvm.eh.sjlj.dispatchsetup</a>
554</div>
555
556<div class="doc_text">
557
558<pre>
559 void %<a href="#llvm_eh_sjlj_dispatchsetup">llvm.eh.sjlj.dispatchsetup</a>(i32)
560</pre>
561
562<p>For SJLJ based exception handling, the <a href="#llvm_eh_sjlj_dispatchsetup">
563 <tt>llvm.eh.sjlj.dispatchsetup</tt></a> intrinsic is used by targets to do
564 any unwind-edge setup they need. By default, no action is taken. </p>
565
566</div>
567
568<!-- ======================================================================= -->
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000569<div class="doc_section">
570 <a name="asm">Asm Table Formats</a>
571</div>
572
573<div class="doc_text">
574
575<p>There are two tables that are used by the exception handling runtime to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000576 determine which actions should take place when an exception is thrown.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000577
578</div>
579
580<!-- ======================================================================= -->
581<div class="doc_subsection">
582 <a name="unwind_tables">Exception Handling Frame</a>
583</div>
584
585<div class="doc_text">
586
587<p>An exception handling frame <tt>eh_frame</tt> is very similar to the unwind
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000588 frame used by dwarf debug info. The frame contains all the information
589 necessary to tear down the current frame and restore the state of the prior
590 frame. There is an exception handling frame for each function in a compile
591 unit, plus a common exception handling frame that defines information common
592 to all functions in the unit.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000593
594<p>Todo - Table details here.</p>
595
596</div>
597
598<!-- ======================================================================= -->
599<div class="doc_subsection">
600 <a name="exception_tables">Exception Tables</a>
601</div>
602
603<div class="doc_text">
604
605<p>An exception table contains information about what actions to take when an
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000606 exception is thrown in a particular part of a function's code. There is one
607 exception table per function except leaf routines and functions that have
608 only calls to non-throwing functions will not need an exception table.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000609
610<p>Todo - Table details here.</p>
611
612</div>
613
614<!-- ======================================================================= -->
615<div class="doc_section">
616 <a name="todo">ToDo</a>
617</div>
618
619<div class="doc_text">
620
621<ol>
622
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000623 <li>Testing/Testing/Testing.</li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000624
625</ol>
626
627</div>
628
629<!-- *********************************************************************** -->
630
631<hr>
632<address>
633 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000634 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000635 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000636 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000637
638 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
639 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
640 Last modified: $Date$
641</address>
642
643</body>
644</html>