xref: /llvm-project/llvm/test/Instrumentation/AddressSanitizer/lifetime-throw.ll (revision 855fe35064674c4601ea9c659a015cacdcec9f63)
1; Test handling of llvm.lifetime intrinsics with C++ exceptions.
2; RUN: opt < %s -passes=asan -asan-use-after-scope -asan-use-after-return=never -S | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7%struct.ABC = type { i32 }
8
9$_ZN3ABCD2Ev = comdat any
10$_ZTS3ABC = comdat any
11$_ZTI3ABC = comdat any
12
13@_ZTVN10__cxxabiv117__class_type_infoE = external global ptr
14@_ZTS3ABC = linkonce_odr constant [5 x i8] c"3ABC\00", comdat
15@_ZTI3ABC = linkonce_odr constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS3ABC }, comdat
16
17define void @Throw() sanitize_address personality ptr @__gxx_personality_v0 {
18; CHECK-LABEL: define void @Throw()
19entry:
20  %x = alloca %struct.ABC, align 4
21
22  ; Poison memory in prologue: F1F1F1F1F8F3F3F3
23  ; CHECK: store i64 -868082052615769615, ptr %{{[0-9]+}}
24
25  call void @llvm.lifetime.start.p0(i64 4, ptr %x)
26  ; CHECK: store i8 4, ptr %{{[0-9]+}}
27  ; CHECK-NEXT: @llvm.lifetime.start
28
29  %exception = call ptr @__cxa_allocate_exception(i64 4)
30  invoke void @__cxa_throw(ptr %exception, ptr @_ZTI3ABC, ptr @_ZN3ABCD2Ev) noreturn
31          to label %unreachable unwind label %lpad
32  ; CHECK: call void @__asan_handle_no_return
33  ; CHECK-NEXT: @__cxa_throw
34
35lpad:
36  %0 = landingpad { ptr, i32 }
37          cleanup
38  call void @_ZN3ABCD2Ev(ptr nonnull %x)
39  call void @llvm.lifetime.end.p0(i64 4, ptr %x)
40  ; CHECK: store i8 -8, ptr %{{[0-9]+}}
41  ; CHECK-NEXT: @llvm.lifetime.end
42
43  resume { ptr, i32 } %0
44  ; CHECK: store i64 0, ptr %{{[0-9]+}}
45  ; CHECK-NEXT: resume
46
47unreachable:
48  unreachable
49}
50
51%rtti.TypeDescriptor9 = type { ptr, ptr, [10 x i8] }
52%eh.CatchableType = type { i32, i32, i32, i32, i32, i32, i32 }
53%eh.CatchableTypeArray.1 = type { i32, [1 x i32] }
54%eh.ThrowInfo = type { i32, i32, i32, i32 }
55
56$"\01??1ABC@@QEAA@XZ" = comdat any
57$"\01??_R0?AUABC@@@8" = comdat any
58$"_CT??_R0?AUABC@@@84" = comdat any
59$"_CTA1?AUABC@@" = comdat any
60$"_TI1?AUABC@@" = comdat any
61
62@"\01??_7type_info@@6B@" = external constant ptr
63@"\01??_R0?AUABC@@@8" = linkonce_odr global %rtti.TypeDescriptor9 { ptr @"\01??_7type_info@@6B@", ptr null, [10 x i8] c".?AUABC@@\00" }, comdat
64@__ImageBase = external constant i8
65@"_CT??_R0?AUABC@@@84" = linkonce_odr unnamed_addr constant %eh.CatchableType { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"\01??_R0?AUABC@@@8" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0, i32 -1, i32 0, i32 4, i32 0 }, section ".xdata", comdat
66@"_CTA1?AUABC@@" = linkonce_odr unnamed_addr constant %eh.CatchableTypeArray.1 { i32 1, [1 x i32] [i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"_CT??_R0?AUABC@@@84" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32)] }, section ".xdata", comdat
67@"_TI1?AUABC@@" = linkonce_odr unnamed_addr constant %eh.ThrowInfo { i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"\01??1ABC@@QEAA@XZ" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32), i32 0, i32 trunc (i64 sub nuw nsw (i64 ptrtoint (ptr @"_CTA1?AUABC@@" to i64), i64 ptrtoint (ptr @__ImageBase to i64)) to i32) }, section ".xdata", comdat
68
69define void @ThrowWin() sanitize_address personality ptr @__CxxFrameHandler3 {
70; CHECK-LABEL: define void @ThrowWin()
71entry:
72  %x = alloca %struct.ABC, align 4
73  %tmp = alloca %struct.ABC, align 4
74
75  ; Poison memory in prologue: F1F1F1F1F8F304F2
76  ; CHECK: store i64 -935355671561244175, ptr %{{[0-9]+}}
77
78  call void @llvm.lifetime.start.p0(i64 4, ptr %x)
79  ; CHECK: store i8 4, ptr %{{[0-9]+}}
80  ; CHECK-NEXT: @llvm.lifetime.start
81
82  invoke void @_CxxThrowException(ptr %tmp, ptr nonnull @"_TI1?AUABC@@") noreturn
83          to label %unreachable unwind label %ehcleanup
84  ; CHECK: call void @__asan_handle_no_return
85  ; CHECK-NEXT: @_CxxThrowException
86
87ehcleanup:
88  %0 = cleanuppad within none []
89  call void @"\01??1ABC@@QEAA@XZ"(ptr nonnull %x) [ "funclet"(token %0) ]
90  call void @llvm.lifetime.end.p0(i64 4, ptr %x)
91  ; CHECK: store i8 -8, ptr %{{[0-9]+}}
92  ; CHECK-NEXT: @llvm.lifetime.end
93
94  cleanupret from %0 unwind to caller
95  ; CHECK: store i64 0, ptr %{{[0-9]+}}
96  ; CHECK-NEXT: cleanupret
97
98unreachable:
99  unreachable
100}
101
102
103declare i32 @__gxx_personality_v0(...)
104declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
105declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
106declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr
107declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr
108declare void @_ZN3ABCD2Ev(ptr %this) unnamed_addr
109declare void @"\01??1ABC@@QEAA@XZ"(ptr %this)
110declare void @_CxxThrowException(ptr, ptr)
111declare i32 @__CxxFrameHandler3(...)
112