[libcxx-commits] [libcxx] [libc++][test] Update `msvc_stdlib_force_include.h` (PR #74266)

via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 3 17:04:16 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libcxx

Author: Stephan T. Lavavej (StephanTLavavej)

<details>
<summary>Changes</summary>

Thanks to @<!-- -->mstorsjo's observation in https://github.com/llvm/llvm-project/pull/74182#issuecomment-1837617934, here's a far less intrusive way to make libc++'s filesystem tests compatible with MSVC's STL.

In `msvc_stdlib_force_include.h` (which, as the filename indicates, is force-included by the MSVC STL test environment, but never included by the libc++ test environment), we need to define 3 more macros:

* [`_CRT_DECLARE_NONSTDC_NAMES`][msvc_docs] activates the POSIX names of `getcwd` etc. As the comment explains, we need this because we test with Clang `-fno-ms-compatibility`, which defines `__STDC__` to `1`, which causes the UCRT headers to disable the POSIX names by default.
* Then we need [`_CRT_NONSTDC_NO_WARNINGS`][msvc_docs] to avoid emitting deprecation warnings about the POSIX names.
* Finally, we need `NOMINMAX` to seal away the ancient evil.

[msvc_docs]: https://learn.microsoft.com/en-us/cpp/c-runtime-library/compatibility?view=msvc-170

Like the other macros, these are defined within `#ifndef _LIBCXX_IN_DEVCRT` because we want them only within libc++'s test suite. (Our own test suite, formerly called "devcrt", reaches into our llvm-project submodule to include this header in a few places, and we don't want these macros defined there.)

While I'm in the neighborhood, I'm also updating a couple of "simulated" macros. This simulates `__has_feature(hwaddress_sanitizer)` as `0`, and `__has_builtin(__builtin_source_location)` as `1`. The latter allows the `source_location` feature-test macro test to pass.

---
Full diff: https://github.com/llvm/llvm-project/pull/74266.diff


1 Files Affected:

- (modified) libcxx/test/support/msvc_stdlib_force_include.h (+18-5) 


``````````diff
diff --git a/libcxx/test/support/msvc_stdlib_force_include.h b/libcxx/test/support/msvc_stdlib_force_include.h
index 3c61f0b880b18..1f5c1269ee00e 100644
--- a/libcxx/test/support/msvc_stdlib_force_include.h
+++ b/libcxx/test/support/msvc_stdlib_force_include.h
@@ -18,6 +18,15 @@
 
     // Avoid assertion dialogs.
     #define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
+
+    // Declare POSIX function names. (By default, Clang -fno-ms-compatibility causes them to be omitted.)
+    #define _CRT_DECLARE_NONSTDC_NAMES 1
+
+    // Silence warnings about POSIX function names.
+    #define _CRT_NONSTDC_NO_WARNINGS 1
+
+    // Avoid Windows.h macroizing min() and max().
+    #define NOMINMAX 1
 #endif // _LIBCXX_IN_DEVCRT
 
 #include <crtdbg.h>
@@ -45,15 +54,19 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
 #if !defined(__clang__)
     // Simulate feature-test macros.
     #define __has_feature(X) _MSVC_HAS_FEATURE_ ## X
-    #define _MSVC_HAS_FEATURE_cxx_exceptions    1
-    #define _MSVC_HAS_FEATURE_cxx_rtti          1
-    #define _MSVC_HAS_FEATURE_address_sanitizer 0
-    #define _MSVC_HAS_FEATURE_memory_sanitizer  0
-    #define _MSVC_HAS_FEATURE_thread_sanitizer  0
+    #define _MSVC_HAS_FEATURE_cxx_exceptions      1
+    #define _MSVC_HAS_FEATURE_cxx_rtti            1
+    #define _MSVC_HAS_FEATURE_address_sanitizer   0
+    #define _MSVC_HAS_FEATURE_hwaddress_sanitizer 0
+    #define _MSVC_HAS_FEATURE_memory_sanitizer    0
+    #define _MSVC_HAS_FEATURE_thread_sanitizer    0
 
     #define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_ ## X
     #define _MSVC_HAS_ATTRIBUTE_vector_size     0
 
+    #define __has_builtin(X) _MSVC_HAS_BUILTIN_ ## X
+    #define _MSVC_HAS_BUILTIN___builtin_source_location 1
+
     // Silence compiler warnings.
     #pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
     #pragma warning(disable: 4324) // structure was padded due to alignment specifier

``````````

</details>


https://github.com/llvm/llvm-project/pull/74266


More information about the libcxx-commits mailing list