Skip to content

Commit c4ebffa

Browse files
committed
Driver: add stack protector tests for riscv
Add tests ensuring that the driver correctly handles stack protector guard options for risc-v. Signed-off-by: Keith Packard <[email protected]>
1 parent 156b989 commit c4ebffa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// RUN: %clang_cc1 -mstack-protector-guard=sysreg -triple aarch64-linux-gnu \
1010
// RUN: -mstack-protector-guard-offset=1024 -mstack-protector-guard-reg=sp_el0 \
1111
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=AARCH64
12+
// RUN: %clang_cc1 -mstack-protector-guard=tls -triple riscv64-unknown-elf \
13+
// RUN: -mstack-protector-guard-offset=44 -mstack-protector-guard-reg=tp \
14+
// RUN: -emit-llvm %s -o - | FileCheck %s --check-prefix=RISCV
1215
void foo(int*);
1316
void bar(int x) {
1417
int baz[x];
@@ -23,3 +26,9 @@ void bar(int x) {
2326
// AARCH64: [[ATTR1]] = !{i32 1, !"stack-protector-guard", !"sysreg"}
2427
// AARCH64: [[ATTR2]] = !{i32 1, !"stack-protector-guard-reg", !"sp_el0"}
2528
// AARCH64: [[ATTR3]] = !{i32 1, !"stack-protector-guard-offset", i32 1024}
29+
30+
// RISCV: !llvm.module.flags = !{{{.*}}[[ATTR1:![0-9]+]], [[ATTR2:![0-9]+]], [[ATTR3:![0-9]+]], [[ATTR4:![0-9]+]]}
31+
// RISCV: [[ATTR1]] = !{i32 1, !"stack-protector-guard", !"tls"}
32+
// RISCV: [[ATTR2]] = !{i32 1, !"stack-protector-guard-reg", !"tp"}
33+
// RISCV: [[ATTR3]] = !{i32 1, !"stack-protector-guard-offset", i32 44}
34+

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,15 @@
8585
// CHECK-AARCH64: "-cc1" {{.*}}"-mstack-protector-guard=sysreg" "-mstack-protector-guard-offset=0" "-mstack-protector-guard-reg=sp_el0"
8686
// INVALID-VALUE-AARCH64: error: invalid value 'tls' in 'mstack-protector-guard=', expected one of: sysreg global
8787
// INVALID-REG-AARCH64: error: invalid value 'foo' in 'mstack-protector-guard-reg='
88+
89+
// RUN: not %clang -target riscv64-unknown-elf -mstack-protector-guard=tls %s 2>&1 | \
90+
// RUN: FileCheck -check-prefix=MISSING-OFFSET %s
91+
92+
// RUN: not %clang -target riscv64-unknown-elf -mstack-protector-guard=sysreg %s 2>&1 | \
93+
// RUN: FileCheck -check-prefix=INVALID-VALUE2 %s
94+
95+
// RUN: not %clang -target riscv64-unknown-elf -mstack-protector-guard=tls \
96+
// RUN: -mstack-protector-guard-offset=20 -mstack-protector-guard-reg=sp %s 2>&1 | \
97+
// RUN: FileCheck -check-prefix=INVALID-REG-RISCV %s
98+
99+
// INVALID-REG-RISCV: error: invalid value 'sp' in 'mstack-protector-guard-reg=', expected one of: tp

0 commit comments

Comments
 (0)