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