Skip to content

Commit 2e8a2f7

Browse files
committed
[NFC][BoundsSafety][LLDB] Refactor the soft trap runtime tests
This refactors the soft trap runtime test so the soft trap runtime implementation exists in its own file. This has several advantages: * It let's the runtime be built without debug info which will be the common case uses hit * It prevents the risk of infinite recursion because it isn't safe to build the soft trap runtime with -fbounds-safety soft trap mode enabled.
1 parent 065da0a commit 2e8a2f7

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bounds_safety_soft_traps.h>
2+
#include <ptrcheck.h>
3+
#include <stdio.h>
4+
5+
#if __CLANG_BOUNDS_SAFETY_SOFT_TRAP_API_VERSION > 0
6+
#error API version changed
7+
#endif
8+
9+
#if __has_ptrcheck
10+
#error Do not compile the runtime with -fbounds-safety enabled due to potential for infinite recursion
11+
#endif
12+
13+
14+
15+
void __bounds_safety_soft_trap_s(const char *reason) {
16+
printf("BoundsSafety check FAILED: message:\"%s\"\n", reason? reason: "");
17+
}
18+
19+
void __bounds_safety_soft_trap(void) {
20+
printf("BoundsSafety check FAILED\n");
21+
}

lldb/test/Shell/BoundsSafety/Inputs/boundsSafetySoftTraps.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
#include <stdio.h>
2-
#include <bounds_safety_soft_traps.h>
3-
4-
#if __CLANG_BOUNDS_SAFETY_SOFT_TRAP_API_VERSION > 0
5-
#error API version changed
6-
#endif
7-
8-
void __bounds_safety_soft_trap_s(const char *reason) {
9-
printf("BoundsSafety check FAILED: message:\"%s\"\n", reason? reason: "");
10-
}
11-
12-
void __bounds_safety_soft_trap(void) {
13-
printf("BoundsSafety check FAILED\n");
14-
}
152

163
int bad_read(int index) {
174
int array[] = {0, 1, 2};

lldb/test/Shell/BoundsSafety/boundssafety_soft_trap_call_minimal.test

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# UNSUPPORTED: system-windows
2-
# RUN: %clang_host -fbounds-safety -fbounds-safety-soft-traps=call-minimal -g -O0 %S/Inputs/boundsSafetySoftTraps.c -o %t.out
2+
# RUN: %clang_host -c -fbounds-safety -fbounds-safety-soft-traps=call-minimal -g -O0 %S/Inputs/boundsSafetySoftTraps.c -o %t.o
3+
# RUN: %clang_host -c -O0 %S/Inputs/boundsSafetyMockSoftTrapRuntime.c -o %t.softtrap_runtime.o
4+
# RUN: %clang_host %t.o %t.softtrap_runtime.o -o %t.out
35
# RUN: %lldb -b -s %s %t.out | FileCheck %s
46
b __bounds_safety_soft_trap
57
run
@@ -10,9 +12,9 @@ run
1012

1113
# Check that reason for bounds check failing can be seen in the stacktrace
1214
bt
13-
# CHECK: * frame #{{.*}}`__bounds_safety_soft_trap{{[ ]+}}
15+
# CHECK: * frame #{{.*}}`__bounds_safety_soft_trap{{$}}
1416
# CHECK-NEXT: frame #{{.*}}`__clang_trap_msg$Bounds check failed$indexing above upper bound in 'array[index]'
15-
# CHECK-NEXT: frame #2{{.*}}`bad_read(index=10) at boundsSafetySoftTraps.c:18
17+
# CHECK-NEXT: frame #2{{.*}}`bad_read(index=10) at boundsSafetySoftTraps.c:5
1618

1719
# Resume execution
1820
c

lldb/test/Shell/BoundsSafety/boundssafety_soft_trap_call_with_str.test

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# UNSUPPORTED: system-windows
2-
# RUN: %clang_host -fbounds-safety -fbounds-safety-soft-traps=call-with-str -g -O0 %S/Inputs/boundsSafetySoftTraps.c -o %t.out
2+
# RUN: %clang_host -c -fbounds-safety -fbounds-safety-soft-traps=call-with-str -g -O0 %S/Inputs/boundsSafetySoftTraps.c -o %t.o
3+
# Note: Building the runtime without debug info is intentional because this is the common case
4+
# RUN: %clang_host -c -O0 %S/Inputs/boundsSafetyMockSoftTrapRuntime.c -o %t.softtrap_runtime.o
5+
# RUN: %clang_host %t.o %t.softtrap_runtime.o -o %t.out
36
# RUN: %lldb -b -s %s %t.out | FileCheck %s
47
b __bounds_safety_soft_trap_s
58
run
@@ -10,9 +13,9 @@ run
1013

1114
# Check that reason for bounds check failing can be seen in the stacktrace
1215
bt
13-
# CHECK: * frame #{{.*}}`__bounds_safety_soft_trap_s(reason="indexing above upper bound in 'array[index]'")
16+
# CHECK: * frame #{{.*}}`__bounds_safety_soft_trap_s
1417
# CHECK-NEXT: frame #{{.*}}`__clang_trap_msg$Bounds check failed$indexing above upper bound in 'array[index]'
15-
# CHECK-NEXT: frame #2{{.*}}`bad_read(index=10) at boundsSafetySoftTraps.c:18
18+
# CHECK-NEXT: frame #{{.*}}`bad_read(index=10) at boundsSafetySoftTraps.c:5
1619

1720
# Resume execution
1821
c

0 commit comments

Comments
 (0)