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
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
7 %struct.ABC = type { i32 }
9 $_ZN3ABCD2Ev = comdat any
10 $_ZTS3ABC = comdat any
11 $_ZTI3ABC = comdat any
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
17 define void @Throw() sanitize_address personality ptr @__gxx_personality_v0 {
18 ; CHECK-LABEL: define void @Throw()
20 %x = alloca %struct.ABC, align 4
22 ; Poison memory in prologue: F1F1F1F1F8F3F3F3
23 ; CHECK: store i64 -868082052615769615, ptr %{{[0-9]+}}
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
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
36 %0 = landingpad { ptr, i32 }
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
43 resume { ptr, i32 } %0
44 ; CHECK: store i64 0, ptr %{{[0-9]+}}
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 }
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
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
69 define void @ThrowWin() sanitize_address personality ptr @__CxxFrameHandler3 {
70 ; CHECK-LABEL: define void @ThrowWin()
72 %x = alloca %struct.ABC, align 4
73 %tmp = alloca %struct.ABC, align 4
75 ; Poison memory in prologue: F1F1F1F1F8F304F2
76 ; CHECK: store i64 -935355671561244175, ptr %{{[0-9]+}}
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
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
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
94 cleanupret from %0 unwind to caller
95 ; CHECK: store i64 0, ptr %{{[0-9]+}}
96 ; CHECK-NEXT: cleanupret
103 declare i32 @__gxx_personality_v0(...)
104 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
105 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)
106 declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr
107 declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr
108 declare void @_ZN3ABCD2Ev(ptr %this) unnamed_addr
109 declare void @"\01??1ABC@@QEAA@XZ"(ptr %this)
110 declare void @_CxxThrowException(ptr, ptr)
111 declare i32 @__CxxFrameHandler3(...)