[compiler-rt] 26c57df - [asan][test] Fix two test cases on Windows
Alvin Wong via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 10 08:21:44 PDT 2023
Author: Alvin Wong
Date: 2023-04-10T23:21:16+08:00
New Revision: 26c57df8aa3b3a134bbda3a4e3ab34625ffc7510
URL: https://github.com/llvm/llvm-project/commit/26c57df8aa3b3a134bbda3a4e3ab34625ffc7510
DIFF: https://github.com/llvm/llvm-project/commit/26c57df8aa3b3a134bbda3a4e3ab34625ffc7510.diff
LOG: [asan][test] Fix two test cases on Windows
Fixes global-location-nodebug and heavy_uar_test for both MSVC and MinGW
targets.
Differential Revision: https://reviews.llvm.org/D147445
Added:
Modified:
compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/asan/TestCases/global-location-nodebug.cpp b/compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
index b498394795c27..edbff7c303107 100644
--- a/compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
+++ b/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
diff erent 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
diff --git a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp b/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
index 718f9b9562736..661867260d260 100644
--- a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
+++ b/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
diff erent 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 @@ void RecursiveFunctionWithStackFrame(int depth) {
}
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;
More information about the llvm-commits
mailing list