1; clang -target aarch64-eabi -O2 -march=armv8.5-a+memtag -fsanitize=memtag -S -emit-llvm test.cc 2; void bar() { 3; throw 42; 4; } 5 6; void foo() { 7; int A0; 8; __asm volatile("" : : "r"(&A0)); 9 10; try { 11; bar(); 12; } catch (int exc) { 13; } 14 15; throw 15532; 16; } 17 18; int main() { 19; try { 20; foo(); 21; } catch (int exc) { 22; } 23 24; return 0; 25; } 26 27; RUN: opt -S -aarch64-stack-tagging %s -o - | FileCheck %s 28 29target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" 30target triple = "aarch64-unknown-unknown-eabi" 31 32@_ZTIi = external dso_local constant i8* 33 34; Function Attrs: noreturn sanitize_memtag 35define dso_local void @_Z3barv() local_unnamed_addr #0 { 36entry: 37 %exception = tail call i8* @__cxa_allocate_exception(i64 4) #4 38 %0 = bitcast i8* %exception to i32* 39 store i32 42, i32* %0, align 16, !tbaa !2 40 tail call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 41 unreachable 42} 43 44declare dso_local i8* @__cxa_allocate_exception(i64) local_unnamed_addr 45 46declare dso_local void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr 47 48; Function Attrs: noreturn sanitize_memtag 49define dso_local void @_Z3foov() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 50entry: 51 %A0 = alloca i32, align 4 52 %0 = bitcast i32* %A0 to i8* 53 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4 54 call void asm sideeffect "", "r"(i32* nonnull %A0) #4, !srcloc !6 55 invoke void @_Z3barv() 56 to label %try.cont unwind label %lpad 57 58lpad: ; preds = %entry 59 %1 = landingpad { i8*, i32 } 60 cleanup 61 catch i8* bitcast (i8** @_ZTIi to i8*) 62 %2 = extractvalue { i8*, i32 } %1, 1 63 %3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #4 64 %matches = icmp eq i32 %2, %3 65 br i1 %matches, label %catch, label %ehcleanup 66 67catch: ; preds = %lpad 68 %4 = extractvalue { i8*, i32 } %1, 0 69 %5 = call i8* @__cxa_begin_catch(i8* %4) #4 70 call void @__cxa_end_catch() #4 71 br label %try.cont 72 73try.cont: ; preds = %entry, %catch 74 %exception = call i8* @__cxa_allocate_exception(i64 4) #4 75 %6 = bitcast i8* %exception to i32* 76 store i32 15532, i32* %6, align 16, !tbaa !2 77 call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 78 unreachable 79 80ehcleanup: ; preds = %lpad 81 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #4 82 resume { i8*, i32 } %1 83} 84 85; Function Attrs: argmemonly nounwind willreturn 86declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1 87 88declare dso_local i32 @__gxx_personality_v0(...) 89 90; Function Attrs: nounwind readnone 91declare i32 @llvm.eh.typeid.for(i8*) #2 92 93declare dso_local i8* @__cxa_begin_catch(i8*) local_unnamed_addr 94 95declare dso_local void @__cxa_end_catch() local_unnamed_addr 96 97; Function Attrs: argmemonly nounwind willreturn 98declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1 99 100; Function Attrs: norecurse sanitize_memtag 101define dso_local i32 @main() local_unnamed_addr #3 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 102entry: 103; CHECK-LABEL: entry: 104 %A0.i = alloca i32, align 4 105 %0 = bitcast i32* %A0.i to i8* 106 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %0) #4 107 call void asm sideeffect "", "r"(i32* nonnull %A0.i) #4, !srcloc !6 108; CHECK: call void @llvm.aarch64.settag(i8* %1, i64 16) 109; CHECK-NEXT: call void asm sideeffect 110 %exception.i6 = call i8* @__cxa_allocate_exception(i64 4) #4 111 %1 = bitcast i8* %exception.i6 to i32* 112 store i32 42, i32* %1, align 16, !tbaa !2 113 invoke void @__cxa_throw(i8* %exception.i6, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 114 to label %.noexc7 unwind label %lpad.i 115 116.noexc7: ; preds = %entry 117 unreachable 118 119lpad.i: ; preds = %entry 120 %2 = landingpad { i8*, i32 } 121 cleanup 122 catch i8* bitcast (i8** @_ZTIi to i8*) 123 %3 = extractvalue { i8*, i32 } %2, 1 124 %4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #4 125 %matches.i = icmp eq i32 %3, %4 126 br i1 %matches.i, label %catch.i, label %ehcleanup.i 127 128catch.i: ; preds = %lpad.i 129 %5 = extractvalue { i8*, i32 } %2, 0 130 %6 = call i8* @__cxa_begin_catch(i8* %5) #4 131 call void @__cxa_end_catch() #4 132 %exception.i = call i8* @__cxa_allocate_exception(i64 4) #4 133 %7 = bitcast i8* %exception.i to i32* 134 store i32 15532, i32* %7, align 16, !tbaa !2 135 invoke void @__cxa_throw(i8* %exception.i, i8* bitcast (i8** @_ZTIi to i8*), i8* null) #5 136 to label %.noexc unwind label %lpad 137 138.noexc: ; preds = %catch.i 139 unreachable 140 141ehcleanup.i: ; preds = %lpad.i 142 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %0) #4 143 br label %lpad.body 144 145lpad: ; preds = %catch.i 146 %8 = landingpad { i8*, i32 } 147 catch i8* bitcast (i8** @_ZTIi to i8*) 148 %.pre = extractvalue { i8*, i32 } %8, 1 149 br label %lpad.body 150 151lpad.body: ; preds = %ehcleanup.i, %lpad 152 %.pre-phi = phi i32 [ %3, %ehcleanup.i ], [ %.pre, %lpad ] 153 %eh.lpad-body = phi { i8*, i32 } [ %2, %ehcleanup.i ], [ %8, %lpad ] 154 %matches = icmp eq i32 %.pre-phi, %4 155 br i1 %matches, label %catch, label %eh.resume 156 157catch: ; preds = %lpad.body 158 %9 = extractvalue { i8*, i32 } %eh.lpad-body, 0 159 %10 = call i8* @__cxa_begin_catch(i8* %9) #4 160 call void @__cxa_end_catch() #4 161 ret i32 0 162 163eh.resume: ; preds = %lpad.body 164 resume { i8*, i32 } %eh.lpad-body 165} 166 167attributes #0 = { noreturn sanitize_memtag "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+mte,+neon,+v8.5a" "unsafe-fp-math"="false" "use-soft-float"="false" } 168attributes #1 = { argmemonly nounwind willreturn } 169attributes #2 = { nounwind readnone } 170attributes #3 = { norecurse sanitize_memtag "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+mte,+neon,+v8.5a" "unsafe-fp-math"="false" "use-soft-float"="false" } 171attributes #4 = { nounwind } 172attributes #5 = { noreturn } 173 174!llvm.module.flags = !{!0} 175!llvm.ident = !{!1} 176 177!0 = !{i32 1, !"wchar_size", i32 4} 178!1 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c38188c5fe41751fda095edde1a878b2a051ae58)"} 179!2 = !{!3, !3, i64 0} 180!3 = !{!"int", !4, i64 0} 181!4 = !{!"omnipotent char", !5, i64 0} 182!5 = !{!"Simple C++ TBAA"} 183!6 = !{i32 70} 184