[compiler-rt] 5888a47 - [asan][test] Fix tests or mark XFAIL for MinGW target

Alvin Wong via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 1 10:06:43 PDT 2023


Author: Alvin Wong
Date: 2023-04-02T01:06:15+08:00
New Revision: 5888a47914f44ffaf102fcb7afd3500706fe753f

URL: https://github.com/llvm/llvm-project/commit/5888a47914f44ffaf102fcb7afd3500706fe753f
DIFF: https://github.com/llvm/llvm-project/commit/5888a47914f44ffaf102fcb7afd3500706fe753f.diff

LOG: [asan][test] Fix tests or mark XFAIL for MinGW target

After this change, `check-asan-dynamic` should pass on x86_64 MinGW
target, using the llvm-mingw toolchain.

The following is a list of issues fixed:

* `asan_str_test.cpp`: Exclude unintercepted functions on MinGW.
* `asan_test.cpp`: Work around regex limitation of gtest on Windows,
  which only affects MinGW target because `long double` has different
  size to `double`.
* `TestCases/Windows/report_after_syminitialize.cpp`: Added  build
  command specifically for MinGW.
* Other tests: Mark XFAIL for various reasons. Some of them need
  further investigation.

Differential Revision: https://reviews.llvm.org/D147059

Added: 
    

Modified: 
    compiler-rt/lib/asan/tests/asan_str_test.cpp
    compiler-rt/lib/asan/tests/asan_test.cpp
    compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
    compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
    compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp
    compiler-rt/test/asan/TestCases/atexit_stats.cpp
    compiler-rt/test/asan/TestCases/atoll_strict.c
    compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp
    compiler-rt/test/asan/TestCases/global-location.cpp
    compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
    compiler-rt/test/asan/TestCases/init-order-atexit.cpp
    compiler-rt/test/asan/TestCases/printf-2.c
    compiler-rt/test/asan/TestCases/printf-3.c
    compiler-rt/test/asan/TestCases/printf-5.c
    compiler-rt/test/asan/TestCases/strcasestr-1.c
    compiler-rt/test/asan/TestCases/strcasestr-2.c
    compiler-rt/test/asan/TestCases/strcasestr_strict.c
    compiler-rt/test/asan/TestCases/strncasecmp_strict.c
    compiler-rt/test/asan/TestCases/strtoll_strict.c
    compiler-rt/test/asan/TestCases/time_interceptor.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/tests/asan_str_test.cpp b/compiler-rt/lib/asan/tests/asan_str_test.cpp
index 1bf6c3581d3aa..8b1c1dc459d74 100644
--- a/compiler-rt/lib/asan/tests/asan_str_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_str_test.cpp
@@ -110,8 +110,16 @@ TEST(AddressSanitizer, WcsLenTest) {
 }
 #endif
 
+// This test fails on MinGW-w64 because it still ships a static copy of strnlen
+// despite it being available from UCRT.
+#if defined(__MINGW32__)
+#  define MAYBE_StrNLenOOBTest DISABLED_StrNLenOOBTest
+#else
+#  define MAYBE_StrNLenOOBTest StrNLenOOBTest
+#endif
+
 #if SANITIZER_TEST_HAS_STRNLEN
-TEST(AddressSanitizer, StrNLenOOBTest) {
+TEST(AddressSanitizer, MAYBE_StrNLenOOBTest) {
   size_t size = Ident(123);
   char *str = MallocAndMemsetString(size);
   // Normal strnlen calls.
@@ -132,10 +140,10 @@ TEST(AddressSanitizer, StrNLenOOBTest) {
 
 // This test fails with the WinASan dynamic runtime because we fail to intercept
 // strdup.
-#if defined(_MSC_VER) && defined(_DLL)
-#define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest
+#if (defined(_MSC_VER) && defined(_DLL)) || defined(__MINGW32__)
+#  define MAYBE_StrDupOOBTest DISABLED_StrDupOOBTest
 #else
-#define MAYBE_StrDupOOBTest StrDupOOBTest
+#  define MAYBE_StrDupOOBTest StrDupOOBTest
 #endif
 
 TEST(AddressSanitizer, MAYBE_StrDupOOBTest) {

diff  --git a/compiler-rt/lib/asan/tests/asan_test.cpp b/compiler-rt/lib/asan/tests/asan_test.cpp
index 40b335d134653..827c2ae3a9cdc 100644
--- a/compiler-rt/lib/asan/tests/asan_test.cpp
+++ b/compiler-rt/lib/asan/tests/asan_test.cpp
@@ -203,8 +203,16 @@ TEST(AddressSanitizer, UAF_char) {
 TEST(AddressSanitizer, UAF_long_double) {
   if (sizeof(long double) == sizeof(double)) return;
   long double *p = Ident(new long double[10]);
+#if defined(_WIN32)
+  // https://google.github.io/googletest/advanced.html#regular-expression-syntax
+  // GoogleTest's regular expression engine on Windows does not support `[]`
+  // brackets.
+  EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 10");
+  EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 10");
+#else
   EXPECT_DEATH(Ident(p)[12] = 0, "WRITE of size 1[026]");
   EXPECT_DEATH(Ident(p)[0] = Ident(p)[12], "READ of size 1[026]");
+#endif
   delete [] Ident(p);
 }
 

diff  --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h b/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
index 016ce9e67d9ff..5fd94a0281391 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
@@ -127,8 +127,8 @@ static inline uint32_t my_rand() {
 # define SANITIZER_TEST_HAS_PRINTF_L 0
 #endif
 
-#if !defined(_MSC_VER)
-# define SANITIZER_TEST_HAS_STRNDUP 1
+#if !defined(_WIN32)
+#  define SANITIZER_TEST_HAS_STRNDUP 1
 #else
 # define SANITIZER_TEST_HAS_STRNDUP 0
 #endif

diff  --git a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
index 163247e09bf7d..96262cafffe82 100644
--- a/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
@@ -4,6 +4,10 @@
 // RUN: %env_asan_opts=coverage=1 %run ./test.exe
 //
 // RUN: %sancov print *.sancov | FileCheck %s
+
+// FIXME: Investigate failure on MinGW.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdio.h>
 
 void foo() { fputs("FOO", stderr); }

diff  --git a/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp b/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp
index 81696630bd44f..45bb6f3f5d224 100644
--- a/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/report_after_syminitialize.cpp
@@ -1,4 +1,14 @@
-// RUN: %clangxx_asan -O0 %s -o %t
+// This test works on both MSVC and MinGW targets, but they require 
diff erent
+// build commands. By default we use DWARF debug info on MinGW and dbghelp does
+// not support it, so we need to specify extra flags to get the compiler to
+// generate PDB debug info.
+
+// The first build command is intended for MSVC target, which fails on MinGW.
+// The second build command contains the flags required to get PDB debug info
+// on a MinGW build, which fails on MSVC.
+
+// RUN: %clangxx_asan -O0 %s -o %t \
+// RUN: || %clangxx_asan -gcodeview -gcolumn-info -Wl,--pdb= -O0 %s -o %t -ldbghelp
 // RUN: %env_asan_opts=external_symbolizer_path=non-existent\\\\asdf not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>

diff  --git a/compiler-rt/test/asan/TestCases/atexit_stats.cpp b/compiler-rt/test/asan/TestCases/atexit_stats.cpp
index c8d97da529212..1774385f9e1c4 100644
--- a/compiler-rt/test/asan/TestCases/atexit_stats.cpp
+++ b/compiler-rt/test/asan/TestCases/atexit_stats.cpp
@@ -6,6 +6,9 @@
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // UNSUPPORTED: android
 
+// FIXME: Investigate failure on MinGW.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdlib.h>
 #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
 #include <malloc.h>

diff  --git a/compiler-rt/test/asan/TestCases/atoll_strict.c b/compiler-rt/test/asan/TestCases/atoll_strict.c
index f0cf0c648c845..431ec6b4ba230 100644
--- a/compiler-rt/test/asan/TestCases/atoll_strict.c
+++ b/compiler-rt/test/asan/TestCases/atoll_strict.c
@@ -11,7 +11,7 @@
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
 
 // FIXME: Needs Windows interceptor.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>

diff  --git a/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp b/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp
index 46bb6a282bea1..721eecc6f82a3 100644
--- a/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp
+++ b/compiler-rt/test/asan/TestCases/frexpl_interceptor.cpp
@@ -2,6 +2,10 @@
 
 // Test the frexpl() interceptor.
 
+// FIXME: MinGW-w64 implements `frexpl()` as a static import, so the dynamic
+// interceptor seems to not work.
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <math.h>
 #include <stdio.h>
 #include <stdlib.h>

diff  --git a/compiler-rt/test/asan/TestCases/global-location.cpp b/compiler-rt/test/asan/TestCases/global-location.cpp
index b0e996a282cda..7aa694159d03e 100644
--- a/compiler-rt/test/asan/TestCases/global-location.cpp
+++ b/compiler-rt/test/asan/TestCases/global-location.cpp
@@ -7,6 +7,9 @@
 // COFF doesn't support debuginfo for globals. For the non-debuginfo tests, see global-location-nodebug.cpp.
 // XFAIL: target={{.*windows-msvc.*}}
 
+// FIXME: Investigate failure on MinGW
+// XFAIL: target={{.*-windows-gnu}}
+
 // atos doesn't show source line numbers for global variables.
 // UNSUPPORTED: darwin
 

diff  --git a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp b/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
index f1bd0f07c123e..718f9b9562736 100644
--- a/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
+++ b/compiler-rt/test/asan/TestCases/heavy_uar_test.cpp
@@ -4,6 +4,10 @@
 // RUN: %clangxx_asan -O2 %s -o %t -fsanitize-address-use-after-return=always && not %run %t 2>&1 | FileCheck %s
 // XFAIL: target={{.*windows-msvc.*}}
 
+// FIXME: Investigate failure on MinGW. MinGW ASAN produces a 
diff erent report:
+//        stack-overflow on address
+// XFAIL: target={{.*-windows-gnu}}
+
 // FIXME: Fix this test under GCC.
 // REQUIRES: Clang
 

diff  --git a/compiler-rt/test/asan/TestCases/init-order-atexit.cpp b/compiler-rt/test/asan/TestCases/init-order-atexit.cpp
index 57bddd4638c37..687707667ebd1 100644
--- a/compiler-rt/test/asan/TestCases/init-order-atexit.cpp
+++ b/compiler-rt/test/asan/TestCases/init-order-atexit.cpp
@@ -7,6 +7,9 @@
 // RUN: %clangxx_asan -O0 %s %p/Helpers/init-order-atexit-extra.cpp -o %t
 // RUN: %env_asan_opts=strict_init_order=true not %run %t 2>&1 | FileCheck %s
 
+// FIXME: Investigate failure on MinGW
+// XFAIL: target={{.*-windows-gnu}}
+
 #include <stdio.h>
 #include <stdlib.h>
 

diff  --git a/compiler-rt/test/asan/TestCases/printf-2.c b/compiler-rt/test/asan/TestCases/printf-2.c
index 7fcf43054bb48..3ea263d16051a 100644
--- a/compiler-rt/test/asan/TestCases/printf-2.c
+++ b/compiler-rt/test/asan/TestCases/printf-2.c
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <stdlib.h>

diff  --git a/compiler-rt/test/asan/TestCases/printf-3.c b/compiler-rt/test/asan/TestCases/printf-3.c
index 805210c660b66..a8ce02ebf6788 100644
--- a/compiler-rt/test/asan/TestCases/printf-3.c
+++ b/compiler-rt/test/asan/TestCases/printf-3.c
@@ -4,7 +4,7 @@
 // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 // New Bionic rejects %n
 // https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336

diff  --git a/compiler-rt/test/asan/TestCases/printf-5.c b/compiler-rt/test/asan/TestCases/printf-5.c
index 564de39f0976c..eef5223e4e8da 100644
--- a/compiler-rt/test/asan/TestCases/printf-5.c
+++ b/compiler-rt/test/asan/TestCases/printf-5.c
@@ -5,7 +5,7 @@
 // RUN: %env_asan_opts=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
 // FIXME: printf is not intercepted on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <string.h>

diff  --git a/compiler-rt/test/asan/TestCases/strcasestr-1.c b/compiler-rt/test/asan/TestCases/strcasestr-1.c
index 8be4b75070f07..9fa4a2b31b97f 100644
--- a/compiler-rt/test/asan/TestCases/strcasestr-1.c
+++ b/compiler-rt/test/asan/TestCases/strcasestr-1.c
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false %run %t 2>&1
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>

diff  --git a/compiler-rt/test/asan/TestCases/strcasestr-2.c b/compiler-rt/test/asan/TestCases/strcasestr-2.c
index eabe4020f090e..920d11e275c6a 100644
--- a/compiler-rt/test/asan/TestCases/strcasestr-2.c
+++ b/compiler-rt/test/asan/TestCases/strcasestr-2.c
@@ -6,7 +6,7 @@
 // RUN: %env_asan_opts=intercept_strstr=false:replace_str=false:intercept_strlen=false %run %t 2>&1
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>

diff  --git a/compiler-rt/test/asan/TestCases/strcasestr_strict.c b/compiler-rt/test/asan/TestCases/strcasestr_strict.c
index a6d1087410f8d..16efae72ada4e 100644
--- a/compiler-rt/test/asan/TestCases/strcasestr_strict.c
+++ b/compiler-rt/test/asan/TestCases/strcasestr_strict.c
@@ -4,7 +4,7 @@
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
 
 // There's no interceptor for strcasestr on Windows
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #define _GNU_SOURCE
 #include <assert.h>

diff  --git a/compiler-rt/test/asan/TestCases/strncasecmp_strict.c b/compiler-rt/test/asan/TestCases/strncasecmp_strict.c
index 24261beaaacae..a0bd3382d9420 100644
--- a/compiler-rt/test/asan/TestCases/strncasecmp_strict.c
+++ b/compiler-rt/test/asan/TestCases/strncasecmp_strict.c
@@ -14,7 +14,7 @@
 // RUN: %env_asan_opts=strict_string_checks=false %run %t i 2>&1
 // RUN: %env_asan_opts=strict_string_checks=true not %run %t i 2>&1 | FileCheck %s
 
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>

diff  --git a/compiler-rt/test/asan/TestCases/strtoll_strict.c b/compiler-rt/test/asan/TestCases/strtoll_strict.c
index 88e6651b6ed11..097412e3ab5c2 100644
--- a/compiler-rt/test/asan/TestCases/strtoll_strict.c
+++ b/compiler-rt/test/asan/TestCases/strtoll_strict.c
@@ -24,7 +24,7 @@
 
 // FIXME: Enable strtoll interceptor.
 // REQUIRES: shadow-scale-3
-// XFAIL: target={{.*windows-msvc.*}}
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <assert.h>
 #include <stdlib.h>

diff  --git a/compiler-rt/test/asan/TestCases/time_interceptor.cpp b/compiler-rt/test/asan/TestCases/time_interceptor.cpp
index 47acdd520b563..0c5e3fe3e9b48 100644
--- a/compiler-rt/test/asan/TestCases/time_interceptor.cpp
+++ b/compiler-rt/test/asan/TestCases/time_interceptor.cpp
@@ -2,8 +2,8 @@
 
 // Test the time() interceptor.
 
-// There's no interceptor for time() on Windows yet.
-// XFAIL: target={{.*windows-msvc.*}}
+// FIXME: There's no interceptor for time() on Windows yet.
+// XFAIL: target={{.*windows-(msvc.*|gnu)}}
 
 #include <stdio.h>
 #include <stdlib.h>


        


More information about the llvm-commits mailing list