Skip to content

Commit 373cca4

Browse files
committed
[compiler-rt][asan][tests] Reland: Stabilize wchar tests on Darwin/Android (llvm#161624)
1 parent 0ef67e7 commit 373cca4

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2-
// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3-
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4-
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
1+
// RUN: %clangxx_asan -O0 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2+
// RUN: %clangxx_asan -O1 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3+
// RUN: %clangxx_asan -O2 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4+
// RUN: %clangxx_asan -O3 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
55

66
#include <stdio.h>
77
#include <wchar.h>
88

99
int main() {
10-
wchar_t *start = L"X means ";
11-
wchar_t *append = L"dog";
10+
const wchar_t *start = L"X means ";
11+
const wchar_t *append = L"dog";
1212
wchar_t goodDst[12];
1313
wcscpy(goodDst, start);
1414
wcscat(goodDst, append);
1515

1616
wchar_t badDst[9];
1717
wcscpy(badDst, start);
18-
printf("Good so far.\n");
18+
fprintf(stderr, "Good so far.\n");
1919
// CHECK: Good so far.
20-
fflush(stdout);
20+
fflush(stderr);
2121
wcscat(badDst, append); // Boom!
2222
// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
23-
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR:0x[0-9a-f]+]] thread T0
24-
// CHECK: #0 [[ADDR:0x[0-9a-f]+]] in wcscat{{.*}}sanitizer_common_interceptors.inc:{{[0-9]+}}
23+
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
24+
// CHECK: #0 {{0x[0-9a-f]+}} in wcscat
2525
printf("Should have failed with ASAN error.\n");
2626
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2-
// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3-
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4-
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
1+
// RUN: %clangxx_asan -O0 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2+
// RUN: %clangxx_asan -O1 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3+
// RUN: %clangxx_asan -O2 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4+
// RUN: %clangxx_asan -O3 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
55

66
#include <stdio.h>
77
#include <wchar.h>
88

99
int main() {
10-
wchar_t *src = L"X means dog";
10+
const wchar_t *src = L"X means dog";
1111
wchar_t goodDst[12];
1212
wcscpy(goodDst, src);
1313

1414
wchar_t badDst[7];
15-
printf("Good so far.\n");
15+
fprintf(stderr, "Good so far.\n");
1616
// CHECK: Good so far.
17-
fflush(stdout);
17+
fflush(stderr);
1818
wcscpy(badDst, src); // Boom!
19-
// CHECK:ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
20-
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR:0x[0-9a-f]+]] thread T0
21-
// CHECK: #0 [[ADDR:0x[0-9a-f]+]] in wcscpy{{.*}}asan_interceptors.cpp:{{[0-9]+}}
19+
// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
20+
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
21+
// CHECK: #0 {{0x[0-9a-f]+}} in wcscpy
2222
printf("Should have failed with ASAN error.\n");
2323
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2-
// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3-
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4-
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
1+
// RUN: %clangxx_asan -O0 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2+
// RUN: %clangxx_asan -O1 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3+
// RUN: %clangxx_asan -O2 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4+
// RUN: %clangxx_asan -O3 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
55

66
#include <stdio.h>
77
#include <wchar.h>
88

99
int main() {
10-
wchar_t *start = L"X means ";
11-
wchar_t *append = L"dog";
10+
const wchar_t *start = L"X means ";
11+
const wchar_t *append = L"dog";
1212
wchar_t goodDst[15];
1313
wcscpy(goodDst, start);
1414
wcsncat(goodDst, append, 5);
1515

1616
wchar_t badDst[11];
1717
wcscpy(badDst, start);
1818
wcsncat(badDst, append, 1);
19-
printf("Good so far.\n");
19+
fprintf(stderr, "Good so far.\n");
2020
// CHECK: Good so far.
21-
fflush(stdout);
21+
fflush(stderr);
2222
wcsncat(badDst, append, 3); // Boom!
2323
// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
24-
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR:0x[0-9a-f]+]] thread T0
25-
// CHECK: #0 [[ADDR:0x[0-9a-f]+]] in wcsncat{{.*}}sanitizer_common_interceptors.inc:{{[0-9]+}}
24+
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
25+
// CHECK: #0 {{0x[0-9a-f]+}} in wcsncat
2626
printf("Should have failed with ASAN error.\n");
2727
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2-
// RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3-
// RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4-
// RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
1+
// RUN: %clangxx_asan -O0 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
2+
// RUN: %clangxx_asan -O1 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
3+
// RUN: %clangxx_asan -O2 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
4+
// RUN: %clangxx_asan -O3 %s -o %t && not %env_asan_opts=log_to_stderr=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
55

66
#include <stdio.h>
77
#include <wchar.h>
88

99
int main() {
10-
wchar_t *src = L"X means dog";
10+
const wchar_t *src = L"X means dog";
1111
wchar_t goodDst[12];
1212
wcsncpy(goodDst, src, 12);
1313

1414
wchar_t badDst[7];
1515
wcsncpy(badDst, src, 7); // This should still work.
16-
printf("Good so far.\n");
16+
fprintf(stderr, "Good so far.\n");
1717
// CHECK: Good so far.
18-
fflush(stdout);
18+
fflush(stderr);
1919

2020
wcsncpy(badDst, src, 15); // Boom!
21-
// CHECK:ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
22-
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR:0x[0-9a-f]+]] thread T0
23-
// CHECK: #0 [[ADDR:0x[0-9a-f]+]] in wcsncpy{{.*}}asan_interceptors.cpp:{{[0-9]+}}
21+
// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] at pc {{0x[0-9a-f]+}} bp {{0x[0-9a-f]+}} sp {{0x[0-9a-f]+}}
22+
// CHECK: WRITE of size {{[0-9]+}} at [[ADDR]] thread T0
23+
// CHECK: #0 {{0x[0-9a-f]+}} in wcsncpy
2424
printf("Should have failed with ASAN error.\n");
2525
}

0 commit comments

Comments
 (0)