llvm.org GIT mirror llvm / 8f3f5c3
[WinEH] Add llvm.eh.exceptionpointer intrinsic Summary: This intrinsic can be used to extract a pointer to the exception caught by a given catchpad. Its argument has token type and must be a `catchpad`. Also clarify ExtendingLLVM documentation regarding overloaded intrinsics. Reviewers: majnemer, andrew.w.kaylor, sanjoy, rnk Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D12533 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246752 91177308-0d34-0410-b5e6-96231b3b80d8 Joseph Tremoulet 4 years ago
6 changed file(s) with 99 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
398398 When used in the native Windows C++ exception handling implementation, this
399399 intrinsic serves as a placeholder to delimit code before a catch handler is
400400 outlined. After the handler is outlined, this intrinsic is simply removed.
401
402
403 .. _llvm.eh.exceptionpointer:
404
405 ``llvm.eh.exceptionpointer``
406 ----------------------
407
408 .. code-block:: llvm
409
410 i8 addrspace(N)* @llvm.eh.padparam.pNi8(token %catchpad)
411
412
413 This intrinsic retrieves a pointer to the exception caught by the given
414 ``catchpad``.
401415
402416
403417 SJLJ Intrinsics
4848
4949 Add an entry for your intrinsic. Describe its memory access characteristics
5050 for optimization (this controls whether it will be DCE'd, CSE'd, etc). Note
51 that any intrinsic using the ``llvm_int_ty`` type for an argument will
52 be deemed by ``tblgen`` as overloaded and the corresponding suffix will
53 be required on the intrinsic's name.
51 that any intrinsic using one of the ``llvm_any*_ty`` types for an argument or
52 return type will be deemed by ``tblgen`` as overloaded and the corresponding
53 suffix will be required on the intrinsic's name.
5454
5555 #. ``llvm/lib/Analysis/ConstantFolding.cpp``:
5656
435435 [NoCapture<0>, NoCapture<1>]>;
436436 def int_eh_endcatch : Intrinsic<[], []>;
437437
438 // eh.exceptionpointer returns the pointer to the exception caught by
439 // the given `catchpad`.
440 def int_eh_exceptionpointer : Intrinsic<[llvm_anyptr_ty], [llvm_token_ty],
441 [IntrNoMem]>;
442
438443 // Represents the list of actions to take when an exception is thrown.
439444 def int_eh_actions : Intrinsic<[llvm_ptr_ty], [llvm_vararg_ty], []>;
440445
36803680 "gc.relocate: relocating a pointer shouldn't change its address space", CS);
36813681 break;
36823682 }
3683 case Intrinsic::eh_exceptionpointer: {
3684 Assert(isa(CS.getArgOperand(0)),
3685 "eh.exceptionpointer argument must be a catchpad", CS);
3686 break;
3687 }
36833688 };
36843689 }
36853690
0 ; RUN: sed -e s/.T1:// %s | not opt -lint -disable-output 2>&1 | FileCheck --check-prefix=CHECK1 %s
1 ; RUN: sed -e s/.T2:// %s | not opt -lint -disable-output 2>&1 | FileCheck --check-prefix=CHECK2 %s
2
3 target triple = "x86_64-pc-windows-msvc"
4
5 declare void @f()
6
7 ;T1: declare i8* @llvm.eh.exceptionpointer.p0i8(i32)
8 ;T1:
9 ;T1: define void @test1() personality i32 (...)* @__CxxFrameHandler3 {
10 ;T1: call i8* @llvm.eh.exceptionpointer.p0i8(i32 0)
11 ;T1: ret void
12 ;T1: }
13 ;CHECK1: Intrinsic has incorrect argument type!
14 ;CHECK1-NEXT: i8* (i32)* @llvm.eh.exceptionpointer.p0i8
15
16 ;T2: declare i8* @llvm.eh.exceptionpointer.p0i8(token)
17 ;T2:
18 ;T2: define void @test2() personality i32 (...)* @__CxxFrameHandler3 {
19 ;T2: call i8* @llvm.eh.exceptionpointer.p0i8(token undef)
20 ;T2: ret void
21 ;T2: }
22 ;CHECK2: eh.exceptionpointer argument must be a catchpad
23 ;CHECK2-NEXT: call i8* @llvm.eh.exceptionpointer.p0i8(token undef)
24
25 declare i32 @__CxxFrameHandler3(...)
0 ; RUN: opt -lint -disable-output < %s
1
2 ; This test is meant to prove that the verifier does not report errors for correct
3 ; use of the llvm.eh.exceptionpointer intrinsic.
4
5 target triple = "x86_64-pc-windows-msvc"
6
7 declare i8* @llvm.eh.exceptionpointer.p0i8(token)
8 declare i8 addrspace(1)* @llvm.eh.exceptionpointer.p1i8(token)
9
10 declare void @f(...)
11
12 define void @test1() personality i32 (...)* @__CxxFrameHandler3 {
13 entry:
14 invoke void (...) @f(i32 1)
15 to label %exit unwind label %catchpad
16 catchpad:
17 %catch = catchpad [i32 1] to label %do_catch unwind label %catchend
18 do_catch:
19 %exn = call i8* @llvm.eh.exceptionpointer.p0i8(token %catch)
20 call void (...) @f(i8* %exn)
21 catchret %catch to label %exit
22 catchend:
23 catchendpad unwind to caller
24 exit:
25 ret void
26 }
27
28 define void @test2() personality i32 (...)* @ProcessManagedException {
29 entry:
30 invoke void (...) @f(i32 1)
31 to label %exit unwind label %catchpad
32 catchpad:
33 %catch = catchpad [i32 1] to label %do_catch unwind label %catchend
34 do_catch:
35 %exn = call i8 addrspace(1)* @llvm.eh.exceptionpointer.p1i8(token %catch)
36 call void (...) @f(i8 addrspace(1)* %exn)
37 catchret %catch to label %exit
38 catchend:
39 catchendpad unwind to caller
40 exit:
41 ret void
42 }
43
44 declare i32 @__CxxFrameHandler3(...)
45 declare i32 @ProcessManagedException(...)