Skip to content

Commit 42fe5a1

Browse files
barcharcrazjoaosaffran
authored and
joaosaffran
committed
[compiler-rt][windows] Test fixups for MSVC. (llvm#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 e1315af commit 42fe5a1

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// Repro for the issue #64990: Asan with Windows EH generates __asan_xxx runtime calls without required funclet tokens
2-
// RUN: %clang_cl_asan %Od %s -EHsc %Fe%t
2+
// RUN: %clang_cl_asan %Od %if MSVC %{ /Oi %} %s -EHsc %Fe%t
33
// RUN: not %run %t 2>&1 | FileCheck %s
44

55
// UNSUPPORTED: target={{.*-windows-gnu}}
66

7+
#if defined(_MSC_VER) && !defined(__clang__)
8+
# include <string.h>
9+
#endif
10+
711
char buff1[6] = "hello";
812
char buff2[6] = "hello";
913

@@ -12,7 +16,11 @@ int main(int argc, char **argv) {
1216
throw 1;
1317
} catch (...) {
1418
// Make asan generate call to __asan_memcpy inside the EH pad.
19+
#if defined(_MSC_VER) && !defined(__clang__)
20+
memcpy(buff1, buff2 + 3, 6);
21+
#else
1522
__builtin_memcpy(buff1, buff2 + 3, 6);
23+
#endif
1624
}
1725
return 0;
1826
}

compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// different EH personality depending on the -GS setting, so test both -GS+ and
33
// -GS-.
44
//
5-
// RUN: cl -c %s -Fo%t.obj -DCOMPILE_SEH
6-
// RUN: %clangxx_asan -o %t.exe %s %t.obj
5+
// RUN: cl /EHa %MD -c %s -Fo%t.obj -DCOMPILE_SEH
6+
// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN
77
// RUN: %run %t.exe
88
//
9-
// RUN: cl -GS- -c %s -Fo%t.obj -DCOMPILE_SEH
10-
// RUN: %clangxx_asan -o %t.exe %s %t.obj
9+
// RUN: cl /EHa %MD -GS- -c %s -Fo%t.obj -DCOMPILE_SEH
10+
// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN
1111
// RUN: %run %t.exe
1212
//
13-
// RUN: %clang_cl_asan %s -DCOMPILE_SEH -Fe%t.exe
13+
// RUN: %clang_cl_asan /EHa %MD %s -DCOMPILE_SEH -Fe%t.exe -DCOMPILE_MAIN
1414
// RUN: %run %t.exe
1515

1616
#include <windows.h>
@@ -42,7 +42,7 @@ void ThrowAndCatch() {
4242
}
4343
#endif
4444

45-
#if defined(__clang__)
45+
#if defined(COMPILE_MAIN)
4646
int main() {
4747
char x[32];
4848
fprintf(stderr, "Before: %p poisoned: %d\n", &x,

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// RUN: %clang_cl_asan %Od -DEXE %s %t1.lib %t2.lib %Fe%t
1010
// RUN: not %run %t 2>&1 | FileCheck %s
1111

12+
#include "../defines.h"
1213
#include <malloc.h>
1314
#include <string.h>
1415

@@ -28,7 +29,8 @@ __declspec(dllexport) void foo1() {}
2829
}
2930
#elif defined(DLL2)
3031
extern "C" {
31-
__attribute__((noinline)) static void NullDeref(int *ptr) {
32+
ATTRIBUTE_NOINLINE
33+
static void NullDeref(int *ptr) {
3234
// CHECK: ERROR: AddressSanitizer: access-violation on unknown address
3335
// CHECK: {{0x0*000.. .*pc 0x.*}}
3436
ptr[10]++; // BOOM

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
// RUN: %clang_cl_asan %Od %s %Fe%t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33

4+
#include "../defines.h"
5+
46
struct C {
57
int x;
68
~C() {}
79
};
8-
9-
int __attribute__((noinline, optnone)) hide(int x) { return x; }
10-
10+
#if defined(_MSC_VER) && !defined(__clang__)
11+
# pragma optimize("", off)
12+
#else
13+
__attribute__((optnone))
14+
#endif
15+
int ATTRIBUTE_NOINLINE hide(int x) { return x; }
16+
#if defined(_MSC_VER) && !defined(__clang__)
17+
# pragma optimize("", on)
18+
#endif
1119
int main() {
1220
C *buffer = new C[42];
1321
buffer[hide(-(1 + (int)sizeof(void*) / 4))].x = 42;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// FIXME: On MinGW frame #0 does not include the line number?
55
// XFAIL: target={{.*-windows-gnu}}
6+
// XFAIL: msvc
67

78
// Test the error output from misaligned SSE2 memory access. This is a READ
89
// memory access. Windows appears to always provide an address of -1 for these

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// RUN: %clang_cl_asan %Od %s %Fe%t -fsanitize-address-use-after-return=always
55
// RUN: not %run %t 2>&1 | FileCheck %s
6-
6+
// XFAIL: msvc
77
char *x;
88

99
void foo() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
// RUN: not %run %t.exe 2>&1 | FileCheck %s
99
// REQUIRES: lld-available
1010

11-
#include <stdlib.h>
11+
#include "../defines.h"
1212
#include <stdio.h>
13-
int __attribute__((noinline)) do_uaf(void);
13+
#include <stdlib.h>
14+
int ATTRIBUTE_NOINLINE do_uaf(void);
1415
int main() {
1516
int r = do_uaf();
1617
printf("r: %d\n", r);

compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33
//
4+
// XFAIL: msvc
45

6+
#include "defines.h"
57
#include <assert.h>
68
#include <stdint.h>
79

8-
__attribute__((noinline)) void foo(int index, int len) {
9-
volatile char str[len] __attribute__((aligned(128)));
10+
ATTRIBUTE_NOINLINE void foo(int index, int len) {
11+
volatile char str[len] ATTRIBUTE_ALIGNED(128);
1012
assert(!(reinterpret_cast<uintptr_t>(str) & 127L));
1113
str[index] = '1'; // BOOM
1214
// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]

compiler-rt/test/asan/TestCases/alloca_constant_size.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include <stdio.h>
88
#include <string.h>
99
#include <stdlib.h>
10+
#ifdef _MSC_VER
11+
# include <malloc.h>
12+
#endif
1013

1114
// MSVC provides _alloca instead of alloca.
1215
#if defined(_MSC_VER) && !defined(alloca)

compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
// RUN: not %run %t 2>&1 | FileCheck %s
33
//
44

5+
#include "defines.h"
56
#include <assert.h>
67
#include <stdint.h>
8+
#if defined(_MSC_VER) && !defined(__clang__)
9+
# include <malloc.h>
10+
#endif
711

812
struct A {
913
char a[3];
1014
int b[3];
1115
};
1216

13-
__attribute__((noinline)) void foo(int index, int len) {
14-
volatile struct A str[len] __attribute__((aligned(32)));
17+
ATTRIBUTE_NOINLINE void foo(int index, int len) {
18+
#if !defined(_MSC_VER) || defined(__clang__)
19+
volatile struct A str[len] ATTRIBUTE_ALIGNED(32);
20+
#else
21+
volatile struct A *str = (volatile struct A *)_alloca(len * sizeof(struct A));
22+
#endif
1523
assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
1624
str[index].a[0] = '1'; // BOOM
1725
// CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]

compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: %clangxx_asan -O3 -mllvm -asan-instrument-dynamic-allocas %s -o %t
33
// RUN: %run %t 2>&1
44
//
5+
// MSVC does not support asan-instrament-dynamic-allocas yet
6+
// UNSUPPORTED: msvc
57

68
#include "sanitizer/asan_interface.h"
79
#include <assert.h>

compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
// This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.
77

8+
// MSVC doesn't support VLAs in the first place.
9+
// UNSUPPORTED: msvc
10+
11+
#include "defines.h"
12+
#include "sanitizer/asan_interface.h"
813
#include <assert.h>
914
#include <stdint.h>
1015
#include <stdlib.h>
11-
#include "sanitizer/asan_interface.h"
1216

1317
// MSVC provides _alloca instead of alloca.
1418
#if defined(_MSC_VER) && !defined(alloca)
@@ -21,7 +25,7 @@
2125

2226
void *top, *bot;
2327

24-
__attribute__((noinline)) void foo(int len) {
28+
ATTRIBUTE_NOINLINE void foo(int len) {
2529
char x;
2630
top = &x;
2731
volatile char array[len];

compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33
//
4+
// MSVC doesn't support VLAs
5+
// UNSUPPORTED: msvc
46

57
#include <assert.h>
68
#include <stdint.h>

compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
22
// RUN: not %run %t 2>&1 | FileCheck %s
33
//
4+
// MSVC doesn't support VLAs
5+
// UNSUPPORTED: msvc
46

57
#include <assert.h>
68
#include <stdint.h>

compiler-rt/test/asan/TestCases/alloca_safe_access.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
22
// RUN: %run %t 2>&1
33
//
4+
// MSVC doesn't support VLAs
5+
// UNSUPPORTED: msvc
46

57
#include <assert.h>
68
#include <stdint.h>

0 commit comments

Comments
 (0)