[compiler-rt] Disable MSVC-incompatible portions of `disable_container_overflow_checks` for MSVC (PR #191456)

David Justo via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 09:32:54 PDT 2026


https://github.com/davidmrdavid created https://github.com/llvm/llvm-project/pull/191456

**Context:**

The test `disable_container_overflow_checks` recently started running on Windows, as per: https://github.com/llvm/llvm-project/pull/181721/changes

As a result, the MSVC ASan fork of LLVM ASan started executing this test, which has been failing for 2 reasons.

1) MSVC does not support the `__has_feature` syntax.
2) The `__SANITIZER_DISABLE_CONTAINER_OVERFLOW__` macro is not support in MSVC ASan (we have an equivalent in `_DISABLE_STL_ANNOTATION`) because `__SANITIZER_DISABLE_CONTAINER_OVERFLOW__` also invokes MSVC-incompatible syntax.

**This PR** addresses these two failures.

For (1), we replace:

```C++
#if __has_feature(address_sanitizer)
```

for

```C++
// compilers such as MSVC do not support `__has_feature`
#ifndef __has_feature
#define __has_feature(x) 0
#endif

// MSVC defines `__SANITIZE_ADDRESS__`
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
```

and for (2), we disable the tests for `__SANITIZER_DISABLE_CONTAINER_OVERFLOW__` for MSVC.

>From 5f7b147ccde6e61904904f3091fc5f8b973c6e66 Mon Sep 17 00:00:00 2001
From: David Justo <dajusto at microsoft.com>
Date: Thu, 9 Apr 2026 16:48:34 -0700
Subject: [PATCH] disable incompatible portions of
 `disable_container_overflow_checks` in MSVC

---
 .../TestCases/disable_container_overflow_checks.c     | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.c b/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.c
index 470131291e91d..f6354dae24546 100644
--- a/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.c
+++ b/compiler-rt/test/asan/TestCases/disable_container_overflow_checks.c
@@ -9,8 +9,8 @@
 //
 // Illustrate use of -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ flag to suppress
 // overflow checks at compile time.
-// RUN: %clang_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -O %s -o %t-no-overflow
-// RUN: %run %t-no-overflow 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s
+// RUN: %if !MSVC %{ %clang_asan -D__SANITIZER_DISABLE_CONTAINER_OVERFLOW__ -O %s -o %t-no-overflow %}
+// RUN: %if !MSVC %{ %run %t-no-overflow 2>&1 | FileCheck --check-prefix=CHECK-NOCRASH %s %}
 
 #include <assert.h>
 #include <stdio.h>
@@ -19,12 +19,17 @@
 // public definition of __sanitizer_annotate_contiguous_container
 #include "sanitizer/common_interface_defs.h"
 
+// compilers such as MSVC do not support `__has_feature`
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
 static volatile int one = 1;
 
 int TestCrash() {
   long t[100];
   t[60] = 0;
-#if __has_feature(address_sanitizer)
+#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
   __sanitizer_annotate_contiguous_container(&t[0], &t[0] + 100, &t[0] + 100,
                                             &t[0] + 50);
 #endif



More information about the llvm-commits mailing list