Skip to content

Commit af3f731

Browse files
committed
[clang][PowerPC] Add stack protector tests
Add tests ensuring that the driver correctly handles stack protector guard options. Signed-off-by: Keith Packard <[email protected]>
1 parent 05c0a80 commit af3f731

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

clang/test/CodeGen/stack-protector-guard.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
// RUN: %clang_cc1 -mstack-protector-guard=tls -triple riscv64-unknown-elf \
1313
// RUN: -mstack-protector-guard-offset=44 -mstack-protector-guard-reg=tp \
1414
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=RISCV
15+
// RUN: %clang_cc1 -mstack-protector-guard=tls -triple powerpc64-unknown-elf \
16+
// RUN: -mstack-protector-guard-offset=52 -mstack-protector-guard-reg=r13 \
17+
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=POWERPC64
18+
// RUN: %clang_cc1 -mstack-protector-guard=tls -triple ppc32-unknown-elf \
19+
// RUN: -mstack-protector-guard-offset=16 -mstack-protector-guard-reg=r2 \
20+
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=POWERPC32
1521
void foo(int*);
1622
void bar(int x) {
1723
int baz[x];
@@ -31,3 +37,13 @@ void bar(int x) {
3137
// RISCV: [[ATTR1]] = !{i32 1, !"stack-protector-guard", !"tls"}
3238
// RISCV: [[ATTR2]] = !{i32 1, !"stack-protector-guard-reg", !"tp"}
3339
// RISCV: [[ATTR3]] = !{i32 1, !"stack-protector-guard-offset", i32 44}
40+
41+
// POWERPC64: !llvm.module.flags = !{{{.*}}[[ATTR1:![0-9]+]], [[ATTR2:![0-9]+]], [[ATTR3:![0-9]+]], [[ATTR4:![0-9]+]]}
42+
// POWERPC64: [[ATTR2]] = !{i32 1, !"stack-protector-guard", !"tls"}
43+
// POWERPC64: [[ATTR3]] = !{i32 1, !"stack-protector-guard-reg", !"r13"}
44+
// POWERPC64: [[ATTR4]] = !{i32 1, !"stack-protector-guard-offset", i32 52}
45+
46+
// POWERPC32: !llvm.module.flags = !{{{.*}}[[ATTR1:![0-9]+]], [[ATTR2:![0-9]+]], [[ATTR3:![0-9]+]], [[ATTR4:![0-9]+]]}
47+
// POWERPC32: [[ATTR2]] = !{i32 1, !"stack-protector-guard", !"tls"}
48+
// POWERPC32: [[ATTR3]] = !{i32 1, !"stack-protector-guard-reg", !"r2"}
49+
// POWERPC32: [[ATTR4]] = !{i32 1, !"stack-protector-guard-offset", i32 16}

clang/test/Driver/stack-protector-guard.c

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
// RUN: FileCheck -check-prefix=CHECK-SYM %s
1818

1919
// Invalid arch
20-
// RUN: not %clang -target powerpc64le-linux-gnu -mstack-protector-guard=tls %s 2>&1 | \
20+
// RUN: not %clang -target mipsel-linux-gnu -mstack-protector-guard=tls %s 2>&1 | \
2121
// RUN: FileCheck -check-prefix=INVALID-ARCH %s
2222
// INVALID-ARCH: unsupported option '-mstack-protector-guard=tls' for target
2323

24-
// RUN: not %clang -target powerpc64le-linux-gnu -mstack-protector-guard-reg=fs %s 2>&1 | \
24+
// RUN: not %clang -target mipsel-linux-gnu -mstack-protector-guard-reg=fs %s 2>&1 | \
2525
// RUN: FileCheck -check-prefix=INVALID-ARCH2 %s
2626
// INVALID-ARCH2: unsupported option '-mstack-protector-guard-reg=fs' for target
2727

28-
// RUN: not %clang -target powerpc64le-linux-gnu -mstack-protector-guard-offset=10 %s 2>&1 | \
28+
// RUN: not %clang -target mipsel-linux-gnu -mstack-protector-guard-offset=10 %s 2>&1 | \
2929
// RUN: FileCheck -check-prefix=INVALID-ARCH3 %s
3030
// INVALID-ARCH3: unsupported option '-mstack-protector-guard-offset=10' for target
3131

@@ -104,3 +104,54 @@
104104
// RUN: FileCheck -check-prefix=INVALID-REG-RISCV %s
105105

106106
// INVALID-REG-RISCV: error: invalid value 'sp' in 'mstack-protector-guard-reg=', expected one of: tp
107+
108+
// RUN: %clang -### -target powerpc64-unknown-elf -mstack-protector-guard=tls -mstack-protector-guard-offset=24 -mstack-protector-guard-reg=r13 %s 2>&1 | \
109+
// RUN: FileCheck -v -check-prefix=CHECK-TLS-POWERPC64 %s
110+
// RUN: %clang -### -target powerpc64-unknown-linux-gnu -mstack-protector-guard=global %s 2>&1 | \
111+
// RUN: FileCheck -check-prefix=CHECK-GLOBAL %s
112+
113+
// RUN: not %clang -target powerpc64-unknown-linux-gnu -mstack-protector-guard=tls %s 2>&1 | \
114+
// RUN: FileCheck -check-prefix=MISSING-OFFSET %s
115+
116+
// RUN: not %clang -target powerpc64-unknown-elf -mstack-protector-guard=sysreg %s 2>&1 | \
117+
// RUN: FileCheck -check-prefix=INVALID-VALUE2 %s
118+
119+
// RUN: not %clang -target powerpc64-unknown-elf -mstack-protector-guard=tls \
120+
// RUN: -mstack-protector-guard-offset=20 -mstack-protector-guard-reg=r12 %s 2>&1 | \
121+
// RUN: FileCheck -check-prefix=INVALID-REG-POWERPC64 %s
122+
123+
// CHECK-TLS-POWERPC64: "-cc1" {{.*}}"-mstack-protector-guard=tls" "-mstack-protector-guard-offset=24" "-mstack-protector-guard-reg=r13"
124+
// INVALID-REG-POWERPC64: error: invalid value 'r12' in 'mstack-protector-guard-reg=', expected one of: r13
125+
126+
// RUN: %clang -### -target powerpc64le-unknown-elf -mstack-protector-guard=tls -mstack-protector-guard-offset=24 -mstack-protector-guard-reg=r13 %s 2>&1 | \
127+
// RUN: FileCheck -v -check-prefix=CHECK-TLS-POWERPC64 %s
128+
// RUN: %clang -### -target powerpc64le-unknown-elf -mstack-protector-guard=global %s 2>&1 | \
129+
// RUN: FileCheck -check-prefix=CHECK-GLOBAL %s
130+
131+
// RUN: not %clang -target powerpc64le-unknown-elf -mstack-protector-guard=tls %s 2>&1 | \
132+
// RUN: FileCheck -check-prefix=MISSING-OFFSET %s
133+
134+
// RUN: not %clang -target powerpc64le-unknown-elf -mstack-protector-guard=sysreg %s 2>&1 | \
135+
// RUN: FileCheck -check-prefix=INVALID-VALUE2 %s
136+
137+
// RUN: not %clang -target powerpc64le-unknown-elf -mstack-protector-guard=tls \
138+
// RUN: -mstack-protector-guard-offset=20 -mstack-protector-guard-reg=r12 %s 2>&1 | \
139+
// RUN: FileCheck -check-prefix=INVALID-REG-POWERPC64 %s
140+
141+
// RUN: %clang -### -target ppc32-unknown-elf -mstack-protector-guard=tls -mstack-protector-guard-offset=24 -mstack-protector-guard-reg=r2 %s 2>&1 | \
142+
// RUN: FileCheck -v -check-prefix=CHECK-TLS-POWERPC32 %s
143+
// RUN: %clang -### -target ppc32-unknown-elf -mstack-protector-guard=global %s 2>&1 | \
144+
// RUN: FileCheck -check-prefix=CHECK-GLOBAL %s
145+
146+
// RUN: not %clang -target ppc32-unknown-elf -mstack-protector-guard=tls %s 2>&1 | \
147+
// RUN: FileCheck -check-prefix=MISSING-OFFSET %s
148+
149+
// RUN: not %clang -target ppc32-unknown-elf -mstack-protector-guard=sysreg %s 2>&1 | \
150+
// RUN: FileCheck -check-prefix=INVALID-VALUE2 %s
151+
152+
// RUN: not %clang -target ppc32-unknown-elf -mstack-protector-guard=tls \
153+
// RUN: -mstack-protector-guard-offset=20 -mstack-protector-guard-reg=r3 %s 2>&1 | \
154+
// RUN: FileCheck -check-prefix=INVALID-REG-POWERPC32 %s
155+
156+
// CHECK-TLS-POWERPC32: "-cc1" {{.*}}"-mstack-protector-guard=tls" "-mstack-protector-guard-offset=24" "-mstack-protector-guard-reg=r2"
157+
// INVALID-REG-POWERPC32: error: invalid value 'r3' in 'mstack-protector-guard-reg=', expected one of: r2

0 commit comments

Comments
 (0)