[llvm] [llvm][CMake] Respect LIBCXX_HARDENING_MODE on command-line (PR #68541)

Ben Barham via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 8 15:05:47 PST 2024


================
@@ -85,8 +85,13 @@ if( LLVM_ENABLE_ASSERTIONS )
   endif()
   # Enable assertions in libstdc++.
   add_compile_definitions(_GLIBCXX_ASSERTIONS)
-  # Enable the hardened mode in libc++.
-  add_compile_definitions(_LIBCPP_ENABLE_HARDENED_MODE)
----------------
bnbarham wrote:

This was enabling hardening mode for the entire build, but `LIBCXX_HARDENING_MODE` is used only within `libcxx`. The impact of this is that assertions within the libc++ are no longer enabled in assertions builds for the rest of the compiler code if it isn't using the just-compiled libc++ (which I assume isn't particularly uncommon).

What was the issue you were seeing that caused this change?

I'm also not sure `_LIBCPP_ENABLE_HARDENED_MODE` is what we should have been using anyway. It *was* `_LIBCPP_ENABLE_ASSERTIONS` but that changed in `https://reviews.llvm.org/D156377` with the comment
> The behavior is unchanged because using _LIBCPP_ENABLE_ASSERTIONS now enables the hardened mode instead.

But that's not necessarily true if the user is using a system libc++ (which I would assume is the normal case for someone developing on LLVM). I don't see any warning for if `_LIBCPP_ENABLE_ASSERTIONS` is set now, so maybe this should just be changed back to `_LIBCPP_ENABLE_ASSERTIONS` (though looks like that will be deprecated in LLVM 19)?

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


More information about the llvm-commits mailing list