Skip to content

Commit f3f7543

Browse files
committed
[Darwin][ASan][Test] Create a noinlined wrapper function for reliable suppression in test.
CFStringCreateWithBytes may not always appear on stack due to optimizations. Create a wrapper function for the purposes of testing suppression files that will always appear on stack for test stability. Also necessary to disable leaks to pass on Apple Silicon. rdar://144800068
1 parent 8437b7f commit f3f7543

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

compiler-rt/test/asan/TestCases/Darwin/suppressions-sandbox.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
44

55
// Check that suppressing a function name works within a no-fork sandbox
6-
// RUN: echo "interceptor_via_fun:CFStringCreateWithBytes" > %t.supp
7-
// RUN: %env_asan_opts=suppressions='"%t.supp"' \
6+
// RUN: echo "interceptor_via_fun:createCFString" > %t.supp
7+
// RUN: %env_asan_opts=suppressions='"%t.supp"':verbosity=1:detect_leaks=0 \
88
// RUN: sandbox-exec -p '(version 1)(allow default)(deny process-fork)' \
99
// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
1010

@@ -13,12 +13,17 @@
1313

1414
#include <CoreFoundation/CoreFoundation.h>
1515

16+
// Use a noinline + disable_tail_calls wrapper function to suppress to stabilize test.
17+
__attribute__((noinline, disable_tail_calls)) CFStringRef
18+
createCFString(const unsigned char *bytes, CFIndex length) {
19+
return CFStringCreateWithBytes(kCFAllocatorDefault, bytes, length,
20+
kCFStringEncodingUTF8, FALSE);
21+
}
22+
1623
int main() {
1724
char *a = (char *)malloc(6);
1825
strcpy(a, "hello");
19-
CFStringRef str =
20-
CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)a, 10,
21-
kCFStringEncodingUTF8, FALSE); // BOOM
26+
CFStringRef str = createCFString((unsigned char *)a, 10); // BOOM
2227
fprintf(stderr, "Ignored.\n");
2328
free(a);
2429
CFRelease(str);

0 commit comments

Comments
 (0)