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 i8* 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(i64* noundef getelementptr inbounds ([32 x i64], [32 x i64]* @jbuf, i64 0, i64 0))
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  %0 = getelementptr inbounds [4096 x i8], [4096 x i8]* %buf, i64 0, i64 0
24  call void @llvm.lifetime.start.p0i8(i64 4096, i8* nonnull %0) #10
25  store i8* %0, i8** @stackbuf, align 8
26  ; may_jump may call longjmp, going back to the switch (and then the return),
27  ; bypassing the lifetime.end. This is why we need to untag on the return,
28  ; rather than the lifetime.end.
29  call void @may_jump()
30  call void @llvm.lifetime.end.p0i8(i64 4096, i8* nonnull %0) #10
31  br label %return
32
33; CHECK-LABEL: return:
34; CHECK: call void @llvm.aarch64.settag
35return:                                           ; preds = %entry, %while.body, %sw.bb1
36  %retval.0 = phi i1 [ true, %while.body ], [ true, %sw.bb1 ], [ false, %entry ]
37  ret i1 %retval.0
38}
39
40declare i32 @setjmp(i64* noundef) returns_twice
41
42declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
43declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
44
45