xref: /llvm-project/clang/test/Driver/memtag-stack_lto.c (revision 0f0623ab87e9041fe0df1e788958330a2787a494)
1 // REQUIRES: aarch64-registered-target
2 
3 // No MTE, so no StackSafety.
4 
5 // RUN: rm -f %t*
6 
7 // -O1, no tagging
8 // RUN: %clang -O1 --target=aarch64-unknown-linux -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s
9 
10 // Full LTO
11 // RUN: %clang -O1 --target=aarch64-unknown-linux -c %s -flto=full -o %t.ltonewpm1.bc
12 // RUN: %clang -O1 --target=aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
13 // RUN: llvm-lto2 run -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
14 // RUN:  -r %t.ltonewpm1.bc,fn,plx \
15 // RUN:  -r %t.ltonewpm1.bc,use,lx \
16 // RUN:  -r %t.ltonewpm1.bc,use_local,plx \
17 // RUN:  -r %t.ltonewpm1.bc,w, \
18 // RUN:  -r %t.ltonewpm2.bc,use,plx \
19 // RUN:  -r %t.ltonewpm2.bc,z, 2>&1 | FileCheck %s --allow-empty
20 
21 // Thin LTO, new PM
22 // RUN: %clang -O1 --target=aarch64-unknown-linux -c %s -flto=thin -o %t.thinltonewpm1.bc
23 // RUN: %clang -O1 --target=aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
24 // RUN: llvm-lto2 run -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
25 // RUN:  -r %t.thinltonewpm1.bc,fn,plx \
26 // RUN:  -r %t.thinltonewpm1.bc,use,lx \
27 // RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
28 // RUN:  -r %t.thinltonewpm1.bc,w, \
29 // RUN:  -r %t.thinltonewpm2.bc,use,plx \
30 // RUN:  -r %t.thinltonewpm2.bc,z, 2>&1 | FileCheck %s --allow-empty
31 
32 // Now with MTE.
33 // RUN: rm -f %t*
34 
35 // -O0: both are unsafe.
36 // RUN: %clang -O0 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s
37 
38 // No LTO: just one is safe.
39 // RUN: %clang -O1 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -mllvm -stack-safety-print %s -S -o /dev/null 2>&1 | FileCheck %s -check-prefixes=SSI,XUNSAFE,YSAFE
40 
41 // Full LTO: both are safe.
42 // RUN: %clang -O1 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -c %s -flto=full -o %t.ltonewpm1.bc
43 // RUN: %clang -O1 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
44 // RUN: llvm-lto2 run -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
45 // RUN:  -r %t.ltonewpm1.bc,fn,plx \
46 // RUN:  -r %t.ltonewpm1.bc,use,lx \
47 // RUN:  -r %t.ltonewpm1.bc,use_local,plx \
48 // RUN:  -r %t.ltonewpm1.bc,w, \
49 // RUN:  -r %t.ltonewpm2.bc,use,plx \
50 // RUN:  -r %t.ltonewpm2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE
51 
52 // Thin LTO: both are safe.
53 // RUN: %clang -O1 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -c %s -flto=thin -o %t.thinltonewpm1.bc
54 // RUN: %clang -O1 --target=aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag-stack -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
55 // RUN: llvm-lto2 run -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
56 // RUN:  -r %t.thinltonewpm1.bc,fn,plx \
57 // RUN:  -r %t.thinltonewpm1.bc,use,lx \
58 // RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
59 // RUN:  -r %t.thinltonewpm1.bc,w, \
60 // RUN:  -r %t.thinltonewpm2.bc,use,plx \
61 // RUN:  -r %t.thinltonewpm2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE
62 
63 void use(int *p);
64 
65 #ifdef BUILD2
66 
67 int z;
use(int * p)68 __attribute__((noinline)) void use(int *p) { *p = z; }
69 
70 #else
71 
72 char w;
use_local(char * p)73 __attribute__((noinline)) void use_local(char *p) { *p = w; }
74 
75 // SSI-LABEL: @fn
76 // SSI-LABEL: allocas uses:
fn()77 int fn() {
78   // XUNSAFE-DAG: [4]: full-set
79   // XSAFE-DAG: [4]: [0,4)
80   int x;
81   use(&x);
82 
83   // YUNSAFE-DAG: [1]: full-set
84   // YSAFE-DAG: [1]: [0,1)
85   char y;
86   use_local(&y);
87   return x + y;
88 }
89 
90 // CHECK-NOT: allocas uses:
91 
92 #endif
93