Skip to content

Commit 73114e4

Browse files
authored
[compiler-rt][windows] Test fixups for MSVC. (#109887)
- add XFAIL/UNSUPPORTED annotations for tests run wtih real MSVC - macroify usages of clang-specific attributes in asan tests - Add substitution for /Oy-/-fno-omit-frame-pointer This makes the dll_intercept_memset test work with mingw These are most of the changes that are required to get things running with MSVC, however there are some remaining build-flag tweaks. Nothing in here should be a functional change.
1 parent 839002d commit 73114e4

File tree

82 files changed

+295
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+295
-133
lines changed

compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// RUN: %env_asan_opts=coverage=1 %run ./test.exe
55
//
66
// RUN: %sancov print *.sancov | FileCheck %s
7+
// XFAIL: msvc
78

89
#include <stdio.h>
910

compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=READ
33
// RUN: not %run %t write 2>&1 | FileCheck %s --check-prefix=WRITE
44

5-
#include <windows.h>
5+
#include "../defines.h"
66
#include <stdio.h>
7+
#include <windows.h>
78

89
static volatile int sink;
9-
__attribute__((noinline)) void Read(int *ptr) { sink = *ptr; }
10-
__attribute__((noinline)) void Write(int *ptr) { *ptr = 0; }
10+
ATTRIBUTE_NOINLINE void Read(int *ptr) { sink = *ptr; }
11+
ATTRIBUTE_NOINLINE void Write(int *ptr) { *ptr = 0; }
1112
int main(int argc, char **argv) {
1213
// Writes to shadow are detected as reads from shadow gap (because of how the
1314
// shadow mapping works). This is kinda hard to fix. Test a random address in

compiler-rt/test/asan/TestCases/Windows/dll_host.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// UNSUPPORTED: target={{.*-windows-gnu}}
2+
// XFAIL: msvc
23

34
// This is a host program for DLL tests.
45
//

compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
2-
// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll
2+
// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll
33
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
44

55
// Test that it works correctly even with ICF enabled.
6-
// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll \
6+
// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll \
77
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections,--icf=all %} \
88
// RUN: %else %{ -link /OPT:REF /OPT:ICF %}
99
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
@@ -23,12 +23,12 @@ int test_function() {
2323
// CHECK: Initial test OK
2424

2525
memcpy(buff2, buff1, 6);
26-
// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
27-
// CHECK: WRITE of size 6 at [[ADDR]] thread T0
28-
// CHECK-NEXT: __asan_{{.*}}memcpy
29-
// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cpp:[[@LINE-4]]
30-
// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
31-
// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cpp
32-
// CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable
26+
// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
27+
// CHECK: WRITE of size 6 at [[ADDR]] thread T0
28+
// CHECK-NEXT: __asan_{{.*}}{{(memcpy|memmove)}}
29+
// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cpp:[[@LINE-4]]
30+
// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
31+
// CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy.cpp
32+
// CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable
3333
return 0;
3434
}

compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
2-
// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll
1+
// RUN: %clang_cl_asan %Od %Oy- %p/dll_host.cpp %Fe%t
2+
// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %Oy- %LD %Od %s %Fe%t.dll
33
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
44

55
// Test that it works correctly even with ICF enabled.
6-
// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll \
6+
// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %Oy- %LD %Od %s %Fe%t.dll \
77
// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections,--icf=all %} \
88
// RUN: %else %{ -link /OPT:REF /OPT:ICF %}
99
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s

compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
33
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
44

5-
__attribute__((noinline))
5+
#include "../defines.h"
6+
7+
ATTRIBUTE_NOINLINE
68
static void NullDeref(int *ptr) {
79
// CHECK: ERROR: AddressSanitizer: access-violation on unknown address
810
// CHECK: {{0x0*000.. .*pc 0x.*}}

compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
33
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
44

5+
#include "../defines.h"
6+
57
struct C {
68
int x;
79
~C() {}
810
};
911

10-
int __attribute__((noinline, optnone)) hide(int x) { return x; }
12+
int ATTRIBUTE_NOINLINE
13+
#if defined(__clang__) || !defined(_MSC_VER)
14+
__attribute__((optnone))
15+
#endif
16+
hide(int x) {
17+
return x;
18+
}
1119

1220
extern "C" __declspec(dllexport)
1321
int test_function() {

compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll -fsanitize-address-use-after-return=always
55
// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
66

7+
// UNSUPPORTED: msvc
8+
79
#include <malloc.h>
810

911
char *x;

compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(void) {
1313
// CHECK: AddressSanitizer: global-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
1414
// CHECK: READ of size 1 at [[ADDR]] thread T0
1515
// CHECK-NEXT: {{#0 .* main .*global_const_string_oob.cpp:}}[[@LINE-5]]
16-
// CHECK: [[ADDR]] is located 5 bytes after global variable [[STR:.*]] defined in {{'.*global_const_string_oob.cpp' .*}} of size 11
16+
// CHECK: [[ADDR]] is located 5 bytes after global variable [[STR:.*]] defined in {{'.*global_const_string_oob.cpp.*}} of size 11
1717
// CHECK: [[STR]] is ascii string 'foobarspam'
1818
return 0;
1919
}

compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %clang_cl_asan %Od %s %Fe%t
22
// RUN: %env_asan_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck %s
3+
// msvc doesn't have a __builtin_trap equivalent
4+
// XFAIL: msvc
35

46
// Test the error output from an illegal instruction.
57

0 commit comments

Comments
 (0)