Skip to content

Commit 78f74f6

Browse files
authored
[Darwin][ASan][Test] Create a noinlined wrapper function for reliable suppression in test. (llvm#131247)
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. rdar://144800068
1 parent cb64a36 commit 78f74f6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
// RUN: echo "interceptor_via_fun:createCFString" > %t.supp
77
// RUN: %env_asan_opts=suppressions='"%t.supp"' \
88
// RUN: sandbox-exec -p '(version 1)(allow default)(deny process-fork)' \
99
// RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
@@ -13,12 +13,18 @@
1313

1414
#include <CoreFoundation/CoreFoundation.h>
1515

16+
// Disable optimizations to ensure that this function appears on the stack trace so our
17+
// configured suppressions `interceptor_via_fun:createCFString` can take effect.
18+
__attribute__((noinline, disable_tail_calls)) CFStringRef
19+
createCFString(const unsigned char *bytes, CFIndex length) {
20+
return CFStringCreateWithBytes(kCFAllocatorDefault, bytes, length,
21+
kCFStringEncodingUTF8, FALSE);
22+
}
23+
1624
int main() {
1725
char *a = (char *)malloc(6);
1826
strcpy(a, "hello");
19-
CFStringRef str =
20-
CFStringCreateWithBytes(kCFAllocatorDefault, (unsigned char *)a, 10,
21-
kCFStringEncodingUTF8, FALSE); // BOOM
27+
CFStringRef str = createCFString((unsigned char *)a, 10); // BOOM
2228
fprintf(stderr, "Ignored.\n");
2329
free(a);
2430
CFRelease(str);

0 commit comments

Comments
 (0)