Skip to content

[compiler-rt][windows] Test fixups for MSVC. #109887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 10, 2025

Conversation

barcharcraz
Copy link
Contributor

  • add XFAIL/UNSUPPORTED annotations for tests run wtih real MSVC
  • macroify usages of clang-specific attributes in asan tests

These are most of the changes that are required to get things running with MSVC, however there are some remaining build-flag tweaks

@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

@llvm/pr-subscribers-platform-windows

Author: Charlie Barto (barcharcraz)

Changes
  • add XFAIL/UNSUPPORTED annotations for tests run wtih real MSVC
  • macroify usages of clang-specific attributes in asan tests

These are most of the changes that are required to get things running with MSVC, however there are some remaining build-flag tweaks


Patch is 58.73 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/109887.diff

81 Files Affected:

  • (modified) compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp (+3-2)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_host.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp (+3-3)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp (+3-1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp (+7-1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp (+2)
  • (modified) compiler-rt/test/asan/TestCases/Windows/issue64990.cpp (+9-1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp (+6-6)
  • (removed) compiler-rt/test/asan/TestCases/Windows/null_deref.cpp (-15)
  • (modified) compiler-rt/test/asan/TestCases/Windows/null_deref_multiple_dlls.cpp (+3-2)
  • (modified) compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp (+8-2)
  • (modified) compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/stack_use_after_return.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/Windows/unsymbolized.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp (+4-2)
  • (modified) compiler-rt/test/asan/TestCases/alloca_constant_size.cpp (+3)
  • (modified) compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp (+10-2)
  • (modified) compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp (+3-1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_safe_access.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/alloca_vla_interact.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/contiguous_container.cpp (+3-2)
  • (modified) compiler-rt/test/asan/TestCases/coverage-trace-pc.cpp (+5-2)
  • (modified) compiler-rt/test/asan/TestCases/debug_locate.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/debug_stacks.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/deep_tail_call.cpp (+5-4)
  • (modified) compiler-rt/test/asan/TestCases/default_ignorelist.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/default_options.cpp (+3-1)
  • (added) compiler-rt/test/asan/TestCases/defines.h (+32)
  • (modified) compiler-rt/test/asan/TestCases/error_report_callback.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/exitcode.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/force_inline_opt0.cpp (+6-3)
  • (modified) compiler-rt/test/asan/TestCases/global-location-nodebug.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/global-underflow.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/halt_on_error-1.c (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/heavy_uar_test.cpp (+4-3)
  • (modified) compiler-rt/test/asan/TestCases/ignorelist.cpp (+4-1)
  • (modified) compiler-rt/test/asan/TestCases/ill.cpp (+5-1)
  • (modified) compiler-rt/test/asan/TestCases/initialization-bug.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/inline.cpp (+5-1)
  • (modified) compiler-rt/test/asan/TestCases/intercept-rethrow-exception.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/interception_failure_test.cpp (+4)
  • (modified) compiler-rt/test/asan/TestCases/interface_test.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-errors.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs-subtract-errors.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/invalid-pointer-pairs.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/large_func_test.cpp (+4-3)
  • (modified) compiler-rt/test/asan/TestCases/null_deref.cpp (+3-1)
  • (modified) compiler-rt/test/asan/TestCases/pass-struct-byval.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/report_error_summary.cpp (+2)
  • (modified) compiler-rt/test/asan/TestCases/speculative_load.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/stack-buffer-overflow-with-position.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/stack-oob-frames.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/strcat-overlap.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/strcpy-overlap.cpp (+3-2)
  • (modified) compiler-rt/test/asan/TestCases/strncat-overlap.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/strncpy-overflow.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/strncpy-overlap.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/throw_call_test.cpp (+4-2)
  • (modified) compiler-rt/test/asan/TestCases/throw_catch.cpp (+5-4)
  • (modified) compiler-rt/test/asan/TestCases/throw_invoke_test.cpp (+2-2)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-capture.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-dtor-order.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-inlined.cpp (+5-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop-bug.cpp (+1-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop-removed.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-loop.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-temp.cpp (+4-2)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-temp2.cpp (+5-2)
  • (modified) compiler-rt/test/asan/TestCases/use-after-scope-types.cpp (+2-1)
  • (modified) compiler-rt/test/asan/TestCases/vla_chrome_testcase.cpp (+3-1)
  • (modified) compiler-rt/test/asan/TestCases/vla_condition_overflow.cpp (+3-1)
  • (modified) compiler-rt/test/asan/TestCases/vla_loop_overfow.cpp (+1)
  • (modified) compiler-rt/test/asan/TestCases/zero_page_pc.cpp (+4)
diff --git a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
index 71291e8a531583..528d60e7666bc4 100644
--- a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
@@ -4,6 +4,7 @@
 // RUN: %env_asan_opts=coverage=1 %run ./test.exe
 //
 // RUN: %sancov print *.sancov | FileCheck %s
+// XFAIL: MSVC
 
 #include <stdio.h>
 
diff --git a/compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp b/compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp
index 74200cca1521b3..2567faea9fc7a6 100644
--- a/compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/crash_read_write.cpp
@@ -2,12 +2,13 @@
 // RUN: not %run %t       2>&1 | FileCheck %s --check-prefix=READ
 // RUN: not %run %t write 2>&1 | FileCheck %s --check-prefix=WRITE
 
+#include "../defines.h"
 #include <windows.h>
 #include <stdio.h>
 
 static volatile int sink;
-__attribute__((noinline)) void Read(int *ptr) { sink = *ptr; }
-__attribute__((noinline)) void Write(int *ptr) { *ptr = 0; }
+ATTRIBUTE_NOINLINE void Read(int *ptr) { sink = *ptr; }
+ATTRIBUTE_NOINLINE void Write(int *ptr) { *ptr = 0; }
 int main(int argc, char **argv) {
   // Writes to shadow are detected as reads from shadow gap (because of how the
   // shadow mapping works). This is kinda hard to fix. Test a random address in
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_host.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_host.cpp
index 85b7967e86b510..773482783823ff 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_host.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_host.cpp
@@ -1,4 +1,5 @@
 // UNSUPPORTED: target={{.*-windows-gnu}}
+// XFAIL: msvc
 
 // This is a host program for DLL tests.
 //
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp
index 0a96752f9d0bfc..55f8a895e41cd3 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memcpy.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
-// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll
+// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 // Test that it works correctly even with ICF enabled.
-// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll \
+// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} %LD %Od %s %Fe%t.dll \
 // RUN:   %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections,--icf=all %} \
 // RUN:   %else %{ -link /OPT:REF /OPT:ICF %}
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
@@ -25,7 +25,7 @@ int test_function() {
   memcpy(buff2, buff1, 6);
 // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 6 at [[ADDR]] thread T0
-// CHECK-NEXT:  __asan_{{.*}}memcpy
+// CHECK-NEXT:  __asan_{{.*}}{{(memcpy|memmove)}}
 // CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cpp:[[@LINE-4]]
 // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
 // CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cpp
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp
index 27b343f439cb55..9f57cf03929a34 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_intercept_memset.cpp
@@ -1,9 +1,9 @@
-// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
-// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll
+// RUN: %clang_cl_asan %Od /Oy- %p/dll_host.cpp %Fe%t
+// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} /Oy- %LD %Od %s %Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 // Test that it works correctly even with ICF enabled.
-// RUN: %clang_cl_asan -Wno-fortify-source %LD %Od %s %Fe%t.dll \
+// RUN: %clang_cl_asan %if !MSVC %{ -Wno-fortify-source %} /Oy- %LD %Od %s %Fe%t.dll \
 // RUN:   %if target={{.*-windows-gnu}} %{ -Wl,--gc-sections,--icf=all %} \
 // RUN:   %else %{ -link /OPT:REF /OPT:ICF %}
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp
index b65926941cd786..d0d9a8ff0f5163 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_null_deref.cpp
@@ -2,7 +2,9 @@
 // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
-__attribute__((noinline))
+#include "../defines.h"
+
+ATTRIBUTE_NOINLINE
 static void NullDeref(int *ptr) {
   // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
   // CHECK:   {{0x0*000.. .*pc 0x.*}}
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp
index ca6b256654a236..df580ff10381bb 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cpp
@@ -2,12 +2,18 @@
 // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
+#include "../defines.h"
+
 struct C {
   int x;
   ~C() {}
 };
 
-int __attribute__((noinline, optnone)) hide(int x) { return x; }
+int ATTRIBUTE_NOINLINE
+#if __clang__ || !defined(_MSC_VER)
+__attribute__((optnone))
+#endif
+hide(int x) { return x; }
 
 extern "C" __declspec(dllexport)
 int test_function() {
diff --git a/compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp b/compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp
index be237044bb340d..1b0204ba0b0d49 100644
--- a/compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp
@@ -3,6 +3,7 @@
 // RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s
 // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll -fsanitize-address-use-after-return=always
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+// UNSUPPORTED: MSVC
 
 #include <malloc.h>
 
diff --git a/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp
index 97886097736443..9615ccfc2aa0eb 100644
--- a/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/global_const_string_oob.cpp
@@ -13,7 +13,7 @@ int main(void) {
   // CHECK: AddressSanitizer: global-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
   // CHECK: READ of size 1 at [[ADDR]] thread T0
   // CHECK-NEXT:   {{#0 .* main .*global_const_string_oob.cpp:}}[[@LINE-5]]
-  // CHECK: [[ADDR]] is located 5 bytes after global variable [[STR:.*]] defined in {{'.*global_const_string_oob.cpp' .*}} of size 11
+  // CHECK: [[ADDR]] is located 5 bytes after global variable [[STR:.*]] defined in {{'.*global_const_string_oob.cpp.*}} of size 11
   // CHECK:   [[STR]] is ascii string 'foobarspam'
   return 0;
 }
diff --git a/compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp b/compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp
index 9b902c7536ca91..61a2b9042d611c 100644
--- a/compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/illegal_instruction.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cl_asan %Od %s %Fe%t
 // RUN: %env_asan_opts=handle_sigill=1 not %run %t 2>&1 | FileCheck %s
+// msvc doesn't have a __builtin_trap equivalent
+// XFAIL: MSVC
 
 // Test the error output from an illegal instruction.
 
diff --git a/compiler-rt/test/asan/TestCases/Windows/issue64990.cpp b/compiler-rt/test/asan/TestCases/Windows/issue64990.cpp
index b1b6e42148cb68..5f851decfea100 100644
--- a/compiler-rt/test/asan/TestCases/Windows/issue64990.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/issue64990.cpp
@@ -1,9 +1,13 @@
 // Repro for the issue #64990: Asan with Windows EH generates __asan_xxx runtime calls without required funclet tokens
-// RUN: %clang_cl_asan %Od %s -EHsc %Fe%t
+// RUN: %clang_cl_asan %Od %if MSVC %{ /Oi %} %s -EHsc %Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 // UNSUPPORTED: target={{.*-windows-gnu}}
 
+#if _MSC_VER && !defined(__clang__)
+#include <string.h>
+#endif
+
 char buff1[6] = "hello";
 char buff2[6] = "hello";
 
@@ -12,7 +16,11 @@ int main(int argc, char **argv) {
     throw 1;
   } catch (...) {
     // Make asan generate call to __asan_memcpy inside the EH pad.
+#if _MSC_VER && !defined(__clang__)
+    memcpy(buff1, buff2 + 3, 6);
+#else
     __builtin_memcpy(buff1, buff2 + 3, 6);
+#endif
   }
   return 0;
 }
diff --git a/compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp b/compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp
index 4cb0c55bc77302..f3c7e1a33a568f 100644
--- a/compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/msvc/seh.cpp
@@ -2,15 +2,15 @@
 // different EH personality depending on the -GS setting, so test both -GS+ and
 // -GS-.
 //
-// RUN: cl -c %s -Fo%t.obj -DCOMPILE_SEH
-// RUN: %clangxx_asan -o %t.exe %s %t.obj
+// RUN: cl /EHa %MD -c %s -Fo%t.obj -DCOMPILE_SEH
+// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN
 // RUN: %run %t.exe
 //
-// RUN: cl -GS- -c %s -Fo%t.obj -DCOMPILE_SEH
-// RUN: %clangxx_asan -o %t.exe %s %t.obj
+// RUN: cl /EHa %MD -GS- -c %s -Fo%t.obj -DCOMPILE_SEH
+// RUN: %clangxx_asan -o %t.exe %s %t.obj -DCOMPILE_MAIN
 // RUN: %run %t.exe
 //
-// RUN: %clang_cl_asan %s -DCOMPILE_SEH -Fe%t.exe
+// RUN: %clang_cl_asan /EHa %MD %s -DCOMPILE_SEH -Fe%t.exe -DCOMPILE_MAIN
 // RUN: %run %t.exe
 
 #include <windows.h>
@@ -42,7 +42,7 @@ void ThrowAndCatch() {
 }
 #endif
 
-#if defined(__clang__)
+#if defined(COMPILE_MAIN)
 int main() {
   char x[32];
   fprintf(stderr, "Before: %p poisoned: %d\n", &x,
diff --git a/compiler-rt/test/asan/TestCases/Windows/null_deref.cpp b/compiler-rt/test/asan/TestCases/Windows/null_deref.cpp
deleted file mode 100644
index 6582bac9e69e30..00000000000000
--- a/compiler-rt/test/asan/TestCases/Windows/null_deref.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// FIXME: merge this with the common null_deref test when we can run common
-// tests on Windows.
-
-__attribute__((noinline))
-static void NullDeref(int *ptr) {
-  // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
-  // CHECK:   {{0x0*000.. .*pc 0x.*}}
-  ptr[10]++;  // BOOM
-}
-int main() {
-  NullDeref((int*)0);
-  // CHECK: {{    #1 0x.* in main.*null_deref.cpp:}}[[@LINE-1]]:3
-  // CHECK: AddressSanitizer can not provide additional info.
-}
diff --git a/compiler-rt/test/asan/TestCases/Windows/null_deref_multiple_dlls.cpp b/compiler-rt/test/asan/TestCases/Windows/null_deref_multiple_dlls.cpp
index ea5140a13dc883..8de681ce03e7e8 100644
--- a/compiler-rt/test/asan/TestCases/Windows/null_deref_multiple_dlls.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/null_deref_multiple_dlls.cpp
@@ -9,6 +9,7 @@
 // RUN: %clang_cl_asan %Od -DEXE %s %t1.lib %t2.lib %Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
+#include "../defines.h"
 #include <malloc.h>
 #include <string.h>
 
@@ -27,8 +28,8 @@ extern "C" {
 __declspec(dllexport) void foo1() {}
 }
 #elif defined(DLL2)
-extern "C" {
-__attribute__((noinline)) static void NullDeref(int *ptr) {
+ATTRIBUTE_NOINLINE
+static void NullDeref(int *ptr) {
   // CHECK: ERROR: AddressSanitizer: access-violation on unknown address
   // CHECK:   {{0x0*000.. .*pc 0x.*}}
   ptr[10]++; // BOOM
diff --git a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp
index cad28ae8ace213..6cf7d1159c27bd 100644
--- a/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cpp
@@ -1,12 +1,18 @@
 // RUN: %clang_cl_asan %Od %s %Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
+#include "../defines.h"
+
 struct C {
   int x;
   ~C() {}
 };
-
-int __attribute__((noinline, optnone)) hide(int x) { return x; }
+#if defined(_MSC_VER) && !defined(__clang__)
+#pragma optimize("", off)
+#else
+__attribute__((optnone))
+#endif
+int ATTRIBUTE_NOINLINE hide(int x) { return x; }
 
 int main() {
   C *buffer = new C[42];
diff --git a/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp b/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp
index 1424ee88129f6b..426e4bb363b2f7 100644
--- a/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/sse_misalignment.cpp
@@ -3,6 +3,7 @@
 
 // FIXME: On MinGW frame #0 does not include the line number?
 // XFAIL: target={{.*-windows-gnu}}
+// XFAIL: MSVC
 
 // Test the error output from misaligned SSE2 memory access. This is a READ
 // memory access. Windows appears to always provide an address of -1 for these
diff --git a/compiler-rt/test/asan/TestCases/Windows/stack_use_after_return.cpp b/compiler-rt/test/asan/TestCases/Windows/stack_use_after_return.cpp
index 9385e36a37b678..d6a6b70a208ac6 100644
--- a/compiler-rt/test/asan/TestCases/Windows/stack_use_after_return.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/stack_use_after_return.cpp
@@ -3,7 +3,7 @@
 
 // RUN: %clang_cl_asan %Od %s %Fe%t -fsanitize-address-use-after-return=always
 // RUN: not %run %t 2>&1 | FileCheck %s
-
+// XFAIL: MSVC
 char *x;
 
 void foo() {
diff --git a/compiler-rt/test/asan/TestCases/Windows/unsymbolized.cpp b/compiler-rt/test/asan/TestCases/Windows/unsymbolized.cpp
index 00428b809fccd7..ba8cd16ee8ca9b 100644
--- a/compiler-rt/test/asan/TestCases/Windows/unsymbolized.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/unsymbolized.cpp
@@ -8,9 +8,10 @@
 // RUN: not %run %t.exe 2>&1 | FileCheck %s
 // REQUIRES: lld-available
 
+#include "../defines.h"
 #include <stdlib.h>
 #include <stdio.h>
-int __attribute__((noinline)) do_uaf(void);
+int ATTRIBUTE_NOINLINE do_uaf(void);
 int main() {
   int r = do_uaf();
   printf("r: %d\n", r);
diff --git a/compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp b/compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp
index a451e873f2e42d..9ede7055ec50bc 100644
--- a/compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_big_alignment.cpp
@@ -1,12 +1,14 @@
 // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 //
+// XFAIL: MSVC
 
+#include "defines.h"
 #include <assert.h>
 #include <stdint.h>
 
-__attribute__((noinline)) void foo(int index, int len) {
-  volatile char str[len] __attribute__((aligned(128)));
+ATTRIBUTE_NOINLINE void foo(int index, int len) {
+  volatile char str[len] ATTRIBUTE_ALIGNED(128);
   assert(!(reinterpret_cast<uintptr_t>(str) & 127L));
   str[index] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
diff --git a/compiler-rt/test/asan/TestCases/alloca_constant_size.cpp b/compiler-rt/test/asan/TestCases/alloca_constant_size.cpp
index 8910ea9f8d8e23..52e17d4ad11ca1 100644
--- a/compiler-rt/test/asan/TestCases/alloca_constant_size.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_constant_size.cpp
@@ -7,6 +7,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#if _MSC_VER
+#include <malloc.h>
+#endif
 
 // MSVC provides _alloca instead of alloca.
 #if defined(_MSC_VER) && !defined(alloca)
diff --git a/compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp b/compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp
index 8b207aa07f2eb4..d6d983dccc2c27 100644
--- a/compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_detect_custom_size_.cpp
@@ -2,16 +2,24 @@
 // RUN: not %run %t 2>&1 | FileCheck %s
 //
 
+#include "defines.h"
 #include <assert.h>
 #include <stdint.h>
+#if defined(_MSC_VER) && !defined(__clang__)
+#include <malloc.h>
+#endif
 
 struct A {
   char a[3];
   int b[3];
 };
 
-__attribute__((noinline)) void foo(int index, int len) {
-  volatile struct A str[len] __attribute__((aligned(32)));
+ATTRIBUTE_NOINLINE void foo(int index, int len) {
+#if !defined(_MSC_VER) || defined(__clang__)
+  volatile struct A str[len] ATTRIBUTE_ALIGNED(32);
+#else
+  volatile struct A *str = (volatile struct A*)_alloca(len * sizeof(struct A));
+#endif
   assert(!(reinterpret_cast<uintptr_t>(str) & 31L));
   str[index].a[0] = '1'; // BOOM
 // CHECK: ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
diff --git a/compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp b/compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp
index 912c8b0abaabd0..f4e03e25dfd2a3 100644
--- a/compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cpp
@@ -2,6 +2,7 @@
 // RUN: %clangxx_asan -O3 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: %run %t 2>&1
 //
+// UNSUPPORTED: MSVC
 
 #include "sanitizer/asan_interface.h"
 #include <assert.h>
diff --git a/compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp b/compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp
index 0967b34dc7dbfe..82683934770f9a 100644
--- a/compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_loop_unpoisoning.cpp
@@ -4,7 +4,9 @@
 // REQUIRES: stable-runtime
 
 // This testcase checks that allocas and VLAs inside loop are correctly unpoisoned.
+// UNSUPPORTED: MSVC
 
+#include "defines.h"
 #include <assert.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -21,7 +23,7 @@
 
 void *top, *bot;
 
-__attribute__((noinline)) void foo(int len) {
+ATTRIBUTE_NOINLINE void foo(int len) {
   char x;
   top = &x;
   volatile char array[len];
diff --git a/compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp b/compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp
index 25c6d75be7a538..48d7e93111ec94 100644
--- a/compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_overflow_partial.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 //
+// UNSUPPORTED: MSVC
 
 #include <assert.h>
 #include <stdint.h>
diff --git a/compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp b/compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp
index 7ec4b86cdc715e..a46c7ee1901a70 100644
--- a/compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_overflow_right.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 //
+// UNSUPPORTED: MSVC
 
 #include <assert.h>
 #include <stdint.h>
diff --git a/compiler-rt/test/asan/TestCases/alloca_safe_access.cpp b/compiler-rt/test/asan/TestCases/alloca_safe_access.cpp
index 98e31769812bf9..8bd941bb94674b 100644
--- a/compiler-rt/test/asan/TestCases/alloca_safe_access.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_safe_access.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: %run %t 2>&1
 //
+// UNSUPPORTED: MSVC
 
 #include <assert.h>
 #include <stdint.h>
diff --git a/compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp b/compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp
index 52cd781c4bb880..d540be76c0d27b 100644
--- a/compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp
+++ b/compiler-rt/test/asan/TestCases/alloca_underflow_left.cpp
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O0 -mllvm -asan-instrument-dynamic-allocas %s -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 //
+// UNSUPPORTED: MSVC
 
 #include <assert.h>
 #include <stdint.h>
diff --git a/compiler-rt/test/asan/TestCases/alloca_vla_interact.cpp b/compiler-rt/test/asan/Tes...
[truncated]

Copy link

github-actions bot commented Sep 25, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@mstorsjo mstorsjo requested a review from vitalybuka September 25, 2024 08:03
Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a cursory review and pointed out a couple of issues I found, but I'd appreciate @vitalybuka's opinions too.

Regarding keeping these tests working in mingw configurations, I set up a github actions workflow that you can try out to run these tests - see the second commit at https://github.com/mstorsjo/llvm-project/commits/gha-mingw-compiler-rt. I tested your PR on top of it, with the following results: https://github.com/mstorsjo/llvm-project/actions/runs/11029615284/job/30632424312

(Ideally we'd have things like this integrated into regular precommit CI testing. I haven't tested running tests with clang-cl in similar configurations on github actions though.)

Finally, a small nit - the PR subject could use some tag to indicate that this is related to compiler-rt, to make it clearer once looking at the final commit as part of the whole commit log.

@barcharcraz barcharcraz changed the title Test fixups for MSVC. [compiler-rt][windows] Test fixups for MSVC. Oct 1, 2024
Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comments

set of PRs could be nicer

@barcharcraz
Copy link
Contributor Author

LGTM with comments

set of PRs could be nicer

By "set of PRs" do you mean splitting this into multiple PRs or posting the follow-ups immediately?

add XFAIL/UNSUPPORTED annotations for tests run wtih real MSVC
macroify usages of clang-specific attributes in asan tests
@barcharcraz barcharcraz force-pushed the dev/chbarto/msvc_test_fixups branch from 0274a10 to 6dfde42 Compare January 27, 2025 22:48
@vitalybuka
Copy link
Collaborator

LGTM with comments
set of PRs could be nicer

By "set of PRs" do you mean splitting this into multiple PRs or posting the follow-ups immediately?

Both: Splitting, and landing, and followups in new PRs

And make sure to "re-request" review if you expect reviewer attention.

This makes the dll_intercept_memset test work with mingw
These were mangled in the process of pulling them out of the msvc fork

- null_deref_multiple_dlls.cpp -- extern "C" { got removed
- throw_invoke_test.cpp -- #include "defines.h" is needed for
  ATTRIBUTE_NOINLINE, this test is unsupported on msvc so this was not
  caught
This is compatible with the "real" gnu toolchain
@barcharcraz barcharcraz force-pushed the dev/chbarto/msvc_test_fixups branch from 6dfde42 to e57c791 Compare February 10, 2025 18:45
@barcharcraz barcharcraz merged commit 73114e4 into llvm:main Feb 10, 2025
5 of 6 checks passed
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
- 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.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
- 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.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants