[PATCH] D147445: [asan][test] Fix two test cases on Windows

Alvin Wong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 08:11:17 PDT 2023


alvinhochun created this revision.
alvinhochun added reviewers: mstorsjo, vitalybuka, glider, kcc.
Herald added a subscriber: Enna1.
Herald added a project: All.
alvinhochun requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

Fixes global-location-nodebug and heavy_uar_test for both MSVC and MinGW
targets.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147445

Files:
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/heavy_uar_test.cpp


Index: compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
+++ compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
@@ -1,12 +1,11 @@
-// RUN: %clangxx_asan -O0 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
-// XFAIL: target={{.*windows-msvc.*}}
+// Most Windows linkers set stack size default to 1 MB. Bump it up to 8 MB.
+// DEFINE: %{stack} = %if target={{.*-windows-gnu}} %{ -Wl,--stack,8388608 %} \
+// DEFINE:            %if target={{.*-windows-msvc.*}} %{ -Wl,/STACK:8388608 %}
 
-// FIXME: Investigate failure on MinGW. MinGW ASAN produces a different report:
-//        stack-overflow on address
-// XFAIL: target={{.*-windows-gnu}}
+// RUN: %clangxx_asan %{stack} -O0 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan %{stack} -O2 %s -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan %{stack} -O0 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan %{stack} -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
 
 // FIXME: Fix this test under GCC.
 // REQUIRES: Clang
@@ -19,6 +18,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#ifdef _WIN32
+#  include <windows.h>
+#endif
 
 __attribute__((noinline))
 char *pretend_to_do_something(char *x) {
@@ -44,10 +46,10 @@
 }
 
 int main(int argc, char **argv) {
-#ifdef _MSC_VER
-  // FIXME: This test crashes on Windows and raises a dialog. Avoid running it
-  // in addition to XFAILing it.
-  return 42;
+#ifdef _WIN32
+  // Prevent the crash dialog from showing in case something bad like a stack
+  // overflow happens.
+  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
 #endif
 
   int n_iter = argc >= 2 ? atoi(argv[1]) : 1000;
Index: compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
@@ -2,7 +2,7 @@
 /// allow this test to also run on Windows (which can't be done for the
 /// debuginfo variant).
 
-// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t -Wl,-S
+// RUN: %clangxx_asan -O2 %S/global-location.cpp -o %t %if target={{.*-windows-msvc.*}} %{ -Wl,/DEBUG:NONE %} %else %{ -Wl,-S %}
 // RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB-NO-G
 // RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC-NO-G
 // RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC-NO-G
@@ -11,12 +11,9 @@
 /// Solaris ld -S has different semantics.
 // XFAIL: target={{.*solaris.*}}
 
-/// MSVC linker doesn't support `-S`.
-// UNSUPPORTED: target={{.*windows.*}}
-
 // CHECK: AddressSanitizer: global-buffer-overflow
 // CLASS_STATIC-NO-G: 0x{{.*}} is located 4 bytes after global variable '{{.*}}C::array{{.*}}' defined in '{{.*}}global-location.cpp' {{.*}} of size 40
 // GLOB-NO-G: 0x{{.*}} is located 4 bytes after global variable '{{.*}}global{{.*}}' defined in '{{.*}}global-location.cpp' {{.*}} of size 40
-// FUNC_STATIC-NO-G: 0x{{.*}} is located 4 bytes after global variable '{{.*}}main::array{{.*}}' defined in '{{.*}}global-location.cpp' {{.*}} of size 40
+// FUNC_STATIC-NO-G: 0x{{.*}} is located 4 bytes after global variable '{{.*}}main{{.*}}::array{{.*}}' defined in '{{.*}}global-location.cpp' {{.*}} of size 40
 // LITERAL-NO-G: 0x{{.*}} is located 0 bytes after global variable {{.*}} defined in '{{.*}}global-location.cpp' {{.*}} of size 11
 // CHECK: SUMMARY: AddressSanitizer: global-buffer-overflow


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147445.510506.patch
Type: text/x-patch
Size: 4248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230403/e9829f9a/attachment.bin>


More information about the llvm-commits mailing list