xref: /llvm-project/llvm/test/CodeGen/AArch64/stack-tagging-setjmp.ll (revision 5ddce70ef0e5a641d7fea95e31fc5e2439cb98cb)
1; RUN: opt -S -aarch64-stack-tagging %s -o - | FileCheck %s
2target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
3target triple = "aarch64-unknown-linux-android29"
4
5@stackbuf = dso_local local_unnamed_addr global ptr null, align 8
6@jbuf = dso_local global [32 x i64] zeroinitializer, align 8
7
8declare void @may_jump()
9
10define dso_local noundef i1 @_Z6targetv() sanitize_memtag {
11entry:
12  %buf = alloca [4096 x i8], align 1
13  %call = call i32 @setjmp(ptr noundef @jbuf)
14  switch i32 %call, label %while.body [
15    i32 1, label %return
16    i32 2, label %sw.bb1
17  ]
18
19sw.bb1:                                           ; preds = %entry
20  br label %return
21
22while.body:                                       ; preds = %entry
23  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %buf) #10
24  store ptr %buf, ptr @stackbuf, align 8
25  ; may_jump may call longjmp, going back to the switch (and then the return),
26  ; bypassing the lifetime.end. This is why we need to untag on the return,
27  ; rather than the lifetime.end.
28  call void @may_jump()
29  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %buf) #10
30  br label %return
31
32; CHECK-LABEL: return:
33; CHECK: call void @llvm.aarch64.settag
34return:                                           ; preds = %entry, %while.body, %sw.bb1
35  %retval.0 = phi i1 [ true, %while.body ], [ true, %sw.bb1 ], [ false, %entry ]
36  ret i1 %retval.0
37}
38
39declare i32 @setjmp(ptr noundef) returns_twice
40
41declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
42declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
43
44