File: memtag_lto.c

package info (click to toggle)
llvm-toolchain-11 1%3A11.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 995,808 kB
  • sloc: cpp: 4,767,656; ansic: 760,916; asm: 477,436; python: 170,940; objc: 69,804; lisp: 29,914; sh: 23,855; f90: 18,173; pascal: 7,551; perl: 7,471; ml: 5,603; awk: 3,489; makefile: 2,573; xml: 915; cs: 573; fortran: 503; javascript: 452
file content (139 lines) | stat: -rw-r--r-- 7,331 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// REQUIRES: aarch64-registered-target

// No MTE, so no StackSafety.

// RUN: rm -f %t*

// -O1, no tagging
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s
// RUN: %clang    -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s

// Full LTO
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.lto1.bc
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.lto2.bc
// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.lto1.bc,fn,plx \
// RUN:  -r %t.lto1.bc,use,lx \
// RUN:  -r %t.lto1.bc,use_local,plx \
// RUN:  -r %t.lto1.bc,w, \
// RUN:  -r %t.lto2.bc,use,plx \
// RUN:  -r %t.lto2.bc,z, 2>&1 | FileCheck %s --allow-empty

// Full LTO, new PM
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=full -o %t.ltonewpm1.bc
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
// RUN: llvm-lto2 run -use-new-pm -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.ltonewpm1.bc,fn,plx \
// RUN:  -r %t.ltonewpm1.bc,use,lx \
// RUN:  -r %t.ltonewpm1.bc,use_local,plx \
// RUN:  -r %t.ltonewpm1.bc,w, \
// RUN:  -r %t.ltonewpm2.bc,use,plx \
// RUN:  -r %t.ltonewpm2.bc,z, 2>&1 | FileCheck %s --allow-empty

// Thin LTO
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinlto1.bc
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinlto2.bc
// RUN: llvm-lto2 run -o %t.thinlto %t.thinlto1.bc %t.thinlto2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.thinlto1.bc,fn,plx \
// RUN:  -r %t.thinlto1.bc,use,lx \
// RUN:  -r %t.thinlto1.bc,use_local,plx \
// RUN:  -r %t.thinlto1.bc,w, \
// RUN:  -r %t.thinlto2.bc,use,plx \
// RUN:  -r %t.thinlto2.bc,z, 2>&1 | FileCheck %s --allow-empty

// Thin LTO, new PM
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c %s -flto=thin -o %t.thinltonewpm1.bc
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
// RUN: llvm-lto2 run -use-new-pm -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.thinltonewpm1.bc,fn,plx \
// RUN:  -r %t.thinltonewpm1.bc,use,lx \
// RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
// RUN:  -r %t.thinltonewpm1.bc,w, \
// RUN:  -r %t.thinltonewpm2.bc,use,plx \
// RUN:  -r %t.thinltonewpm2.bc,z, 2>&1 | FileCheck %s --allow-empty

// Now with MTE.
// RUN: rm -f %t*

// -O0: both are unsafe.
// RUN: %clang -fno-experimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s
// RUN: %clang    -fexperimental-new-pass-manager -O0 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print %s -S -o - 2>&1 | FileCheck %s

// No LTO: just one is safe.
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print %s -S -o /dev/null 2>&1 | FileCheck %s -check-prefixes=SSI,XUNSAFE,YSAFE
// RUN: %clang    -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -mllvm -stack-safety-print %s -S -o /dev/null 2>&1 | FileCheck %s -check-prefixes=SSI,XUNSAFE,YSAFE

// Full LTO: both are safe.
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=full -o %t.lto1.bc
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=full -o %t.lto2.bc
// RUN: llvm-lto2 run -o %t.lto %t.lto1.bc %t.lto2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.lto1.bc,fn,plx \
// RUN:  -r %t.lto1.bc,use,lx \
// RUN:  -r %t.lto1.bc,use_local,plx \
// RUN:  -r %t.lto1.bc,w, \
// RUN:  -r %t.lto2.bc,use,plx \
// RUN:  -r %t.lto2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE

// Full LTO, new PM: both are safe.
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=full -o %t.ltonewpm1.bc
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=full -o %t.ltonewpm2.bc
// RUN: llvm-lto2 run -use-new-pm -o %t.ltonewpm %t.ltonewpm1.bc %t.ltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.ltonewpm1.bc,fn,plx \
// RUN:  -r %t.ltonewpm1.bc,use,lx \
// RUN:  -r %t.ltonewpm1.bc,use_local,plx \
// RUN:  -r %t.ltonewpm1.bc,w, \
// RUN:  -r %t.ltonewpm2.bc,use,plx \
// RUN:  -r %t.ltonewpm2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE

// Thin LTO: both are safe.
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=thin -o %t.thinlto1.bc
// RUN: %clang -fno-experimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=thin -o %t.thinlto2.bc
// RUN: llvm-lto2 run -o %t.thinlto %t.thinlto1.bc %t.thinlto2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.thinlto1.bc,fn,plx \
// RUN:  -r %t.thinlto1.bc,use,lx \
// RUN:  -r %t.thinlto1.bc,use_local,plx \
// RUN:  -r %t.thinlto1.bc,w, \
// RUN:  -r %t.thinlto2.bc,use,plx \
// RUN:  -r %t.thinlto2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE

// Thin LTO, new PM: both are safe.
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c %s -flto=thin -o %t.thinltonewpm1.bc
// RUN: %clang -fexperimental-new-pass-manager -O1 -target aarch64-unknown-linux -march=armv8+memtag -fsanitize=memtag -c -DBUILD2 %s -flto=thin -o %t.thinltonewpm2.bc
// RUN: llvm-lto2 run -use-new-pm -o %t.thinltonewpm %t.thinltonewpm1.bc %t.thinltonewpm2.bc -save-temps -stack-safety-print -thinlto-threads 1 -O1 \
// RUN:  -r %t.thinltonewpm1.bc,fn,plx \
// RUN:  -r %t.thinltonewpm1.bc,use,lx \
// RUN:  -r %t.thinltonewpm1.bc,use_local,plx \
// RUN:  -r %t.thinltonewpm1.bc,w, \
// RUN:  -r %t.thinltonewpm2.bc,use,plx \
// RUN:  -r %t.thinltonewpm2.bc,z, 2>&1 | FileCheck %s -check-prefixes=SSI,XSAFE,YSAFE

void use(int *p);

#ifdef BUILD2

int z;
__attribute__((noinline)) void use(int *p) { *p = z; }

#else

char w;
__attribute__((noinline)) void use_local(char *p) { *p = w; }

// SSI-LABEL: @fn
// SSI-LABEL: allocas uses:
int fn() {
  // XUNSAFE-DAG: [4]: full-set
  // XSAFE-DAG: [4]: [0,4)
  int x;
  use(&x);

  // YUNSAFE-DAG: [1]: full-set
  // YSAFE-DAG: [1]: [0,1)
  char y;
  use_local(&y);
  return x + y;
}

// CHECK-NOT: allocas uses:

#endif