[libcxx] [llvm] [libc++][hardening] Rework macros for enabling the hardening mode. (PR #70575)

Louis Dionne via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 13:51:04 PDT 2023


================
@@ -6,14 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-// This test verifies that setting the hardened mode to a value other than `0` or `1` triggers a compile-time error.
+// This test verifies that setting the hardening mode to a value that's not part of the predefined constants triggers
+// a compile-time error.
 
-// Other hardening modes would additionally trigger the error that they are mutually exclusive.
-// REQUIRES: libcpp-hardening-mode=unchecked
 // Modules build produces a different error ("Could not build module 'std'").
 // UNSUPPORTED: clang-modules-build
-// ADDITIONAL_COMPILE_FLAGS: -Wno-macro-redefined -D_LIBCPP_ENABLE_HARDENED_MODE=2
+// ADDITIONAL_COMPILE_FLAGS: -Wno-macro-redefined -D_LIBCPP_HARDENING_MODE=42
----------------
ldionne wrote:

This would be amazing since it would test other common potential misuses that we'd want to catch too. You could write this as a `.sh.cpp` test instead:

```
// RUN: %{verify} -D_LIBCPP_HARDENING_MODE=42
// RUN: %{verify} -D_LIBCPP_HARDENING_MODE=0
// RUN: %{verify} -D_LIBCPP_HARDENING_MODE=1
// RUN: %{verify} -D_LIBCPP_HARDENING_MODE

#include <cassert>

// expected-error 4 {{_LIBCPP_HARDENING_MODE must be set to one of the following values: _LIBCPP_HARDENING_MODE_UNCHECKED, _LIBCPP_HARDENING_MODE_HARDENED, _LIBCPP_HARDENING_MODE_DEBUG_LITE, _LIBCPP_HARDENING_MODE_DEBUG}}
```

I think it's not hard to fix the test suite to make that work, I'll have a look momentarily.

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


More information about the llvm-commits mailing list