comparison docs/ExceptionHandling.rst @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 60c9769439b8
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
140 #. where to continue when the call succeeds as per normal, and 140 #. where to continue when the call succeeds as per normal, and
141 141
142 #. where to continue if the call raises an exception, either by a throw or the 142 #. where to continue if the call raises an exception, either by a throw or the
143 unwinding of a throw 143 unwinding of a throw
144 144
145 The term used to define a the place where an ``invoke`` continues after an 145 The term used to define the place where an ``invoke`` continues after an
146 exception is called a *landing pad*. LLVM landing pads are conceptually 146 exception is called a *landing pad*. LLVM landing pads are conceptually
147 alternative function entry points where an exception structure reference and a 147 alternative function entry points where an exception structure reference and a
148 type info index are passed in as arguments. The landing pad saves the exception 148 type info index are passed in as arguments. The landing pad saves the exception
149 structure reference and then proceeds to select the catch block that corresponds 149 structure reference and then proceeds to select the catch block that corresponds
150 to the type info of the exception object. 150 to the type info of the exception object.
155 the *selector value* respectively. 155 the *selector value* respectively.
156 156
157 The ``landingpad`` instruction takes a reference to the personality function to 157 The ``landingpad`` instruction takes a reference to the personality function to
158 be used for this ``try``/``catch`` sequence. The remainder of the instruction is 158 be used for this ``try``/``catch`` sequence. The remainder of the instruction is
159 a list of *cleanup*, *catch*, and *filter* clauses. The exception is tested 159 a list of *cleanup*, *catch*, and *filter* clauses. The exception is tested
160 against the clauses sequentially from first to last. The selector value is a 160 against the clauses sequentially from first to last. The clauses have the
161 positive number if the exception matched a type info, a negative number if it 161 following meanings:
162 matched a filter, and zero if it matched a cleanup. If nothing is matched, the 162
163 behavior of the program is `undefined`_. If a type info matched, then the 163 - ``catch <type> @ExcType``
164 selector value is the index of the type info in the exception table, which can 164
165 be obtained using the `llvm.eh.typeid.for`_ intrinsic. 165 - This clause means that the landingpad block should be entered if the
166 exception being thrown is of type ``@ExcType`` or a subtype of
167 ``@ExcType``. For C++, ``@ExcType`` is a pointer to the ``std::type_info``
168 object (an RTTI object) representing the C++ exception type.
169
170 - If ``@ExcType`` is ``null``, any exception matches, so the landingpad
171 should always be entered. This is used for C++ catch-all blocks ("``catch
172 (...)``").
173
174 - When this clause is matched, the selector value will be equal to the value
175 returned by "``@llvm.eh.typeid.for(i8* @ExcType)``". This will always be a
176 positive value.
177
178 - ``filter <type> [<type> @ExcType1, ..., <type> @ExcTypeN]``
179
180 - This clause means that the landingpad should be entered if the exception
181 being thrown does *not* match any of the types in the list (which, for C++,
182 are again specified as ``std::type_info`` pointers).
183
184 - C++ front-ends use this to implement C++ exception specifications, such as
185 "``void foo() throw (ExcType1, ..., ExcTypeN) { ... }``".
186
187 - When this clause is matched, the selector value will be negative.
188
189 - The array argument to ``filter`` may be empty; for example, "``[0 x i8**]
190 undef``". This means that the landingpad should always be entered. (Note
191 that such a ``filter`` would not be equivalent to "``catch i8* null``",
192 because ``filter`` and ``catch`` produce negative and positive selector
193 values respectively.)
194
195 - ``cleanup``
196
197 - This clause means that the landingpad should always be entered.
198
199 - C++ front-ends use this for calling objects' destructors.
200
201 - When this clause is matched, the selector value will be zero.
202
203 - The runtime may treat "``cleanup``" differently from "``catch <type>
204 null``".
205
206 In C++, if an unhandled exception occurs, the language runtime will call
207 ``std::terminate()``, but it is implementation-defined whether the runtime
208 unwinds the stack and calls object destructors first. For example, the GNU
209 C++ unwinder does not call object destructors when an unhandled exception
210 occurs. The reason for this is to improve debuggability: it ensures that
211 ``std::terminate()`` is called from the context of the ``throw``, so that
212 this context is not lost by unwinding the stack. A runtime will typically
213 implement this by searching for a matching non-``cleanup`` clause, and
214 aborting if it does not find one, before entering any landingpad blocks.
166 215
167 Once the landing pad has the type info selector, the code branches to the code 216 Once the landing pad has the type info selector, the code branches to the code
168 for the first catch. The catch then checks the value of the type info selector 217 for the first catch. The catch then checks the value of the type info selector
169 against the index of type info for that catch. Since the type info index is not 218 against the index of type info for that catch. Since the type info index is not
170 known until all the type infos have been gathered in the backend, the catch code 219 known until all the type infos have been gathered in the backend, the catch code
276 325
277 This intrinsic returns the type info index in the exception table of the current 326 This intrinsic returns the type info index in the exception table of the current
278 function. This value can be used to compare against the result of 327 function. This value can be used to compare against the result of
279 ``landingpad`` instruction. The single argument is a reference to a type info. 328 ``landingpad`` instruction. The single argument is a reference to a type info.
280 329
330 Uses of this intrinsic are generated by the C++ front-end.
331
332 SJLJ Intrinsics
333 ---------------
334
335 The ``llvm.eh.sjlj`` intrinsics are used internally within LLVM's
336 backend. Uses of them are generated by the backend's
337 ``SjLjEHPrepare`` pass.
338
281 .. _llvm.eh.sjlj.setjmp: 339 .. _llvm.eh.sjlj.setjmp:
282 340
283 ``llvm.eh.sjlj.setjmp`` 341 ``llvm.eh.sjlj.setjmp``
284 ----------------------- 342 ~~~~~~~~~~~~~~~~~~~~~~~
285 343
286 .. code-block:: llvm 344 .. code-block:: llvm
287 345
288 i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf) 346 i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf)
289 347
301 available for use in a target-specific manner. 359 available for use in a target-specific manner.
302 360
303 .. _llvm.eh.sjlj.longjmp: 361 .. _llvm.eh.sjlj.longjmp:
304 362
305 ``llvm.eh.sjlj.longjmp`` 363 ``llvm.eh.sjlj.longjmp``
306 ------------------------ 364 ~~~~~~~~~~~~~~~~~~~~~~~~
307 365
308 .. code-block:: llvm 366 .. code-block:: llvm
309 367
310 void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf) 368 void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf)
311 369
314 a buffer populated by `llvm.eh.sjlj.setjmp`_. The frame pointer and stack 372 a buffer populated by `llvm.eh.sjlj.setjmp`_. The frame pointer and stack
315 pointer are restored from the buffer, then control is transferred to the 373 pointer are restored from the buffer, then control is transferred to the
316 destination address. 374 destination address.
317 375
318 ``llvm.eh.sjlj.lsda`` 376 ``llvm.eh.sjlj.lsda``
319 --------------------- 377 ~~~~~~~~~~~~~~~~~~~~~
320 378
321 .. code-block:: llvm 379 .. code-block:: llvm
322 380
323 i8* @llvm.eh.sjlj.lsda() 381 i8* @llvm.eh.sjlj.lsda()
324 382
326 the address of the Language Specific Data Area (LSDA) for the current 384 the address of the Language Specific Data Area (LSDA) for the current
327 function. The SJLJ front-end code stores this address in the exception handling 385 function. The SJLJ front-end code stores this address in the exception handling
328 function context for use by the runtime. 386 function context for use by the runtime.
329 387
330 ``llvm.eh.sjlj.callsite`` 388 ``llvm.eh.sjlj.callsite``
331 ------------------------- 389 ~~~~~~~~~~~~~~~~~~~~~~~~~
332 390
333 .. code-block:: llvm 391 .. code-block:: llvm
334 392
335 void @llvm.eh.sjlj.callsite(i32 %call_site_num) 393 void @llvm.eh.sjlj.callsite(i32 %call_site_num)
336 394