[libcxx-commits] [libcxx] [llvm] [libcxx][CMake] Rework LLVM_ENABLE_ASSERTIONS interaction w. libcxx hardening (PR #229359)

Mészáros Gergely via libcxx-commits libcxx-commits at lists.llvm.org
Thu Oct 8 23:47:10 PDT 2026


Maetveis wrote:

> I see. But why can't you set `LIBCXX_HARDENING_MODE` explicitly when configuring? Are you annoyed with the warning? Maybe just turn that into a message?

Without this PR that will disable the hardening checks (from the headers) in the main build. The code without this PR reads:
```cmake
  # Cautiously enable the extensive hardening mode in libc++.
  if((DEFINED LIBCXX_HARDENING_MODE) AND
     (NOT LIBCXX_HARDENING_MODE STREQUAL "extensive"))
    message(WARNING "LLVM_ENABLE_ASSERTIONS implies LIBCXX_HARDENING_MODE \"extensive\" but is overriden from command line with value \"${LIBCXX_HARDENING_MODE}\".")
  else()
    set(LIBCXX_HARDENING_MODE "extensive")
  endif()

  string(TOUPPER "_LIBCPP_HARDENING_MODE_${LIBCXX_HARDENING_MODE}" LIBCXX_HARDENING_MODE_SPELLING)
  # ...
  add_compile_definitions(_LIBCPP_HARDENING_MODE=${LIBCXX_HARDENING_MODE_SPELLING})
```
I.e. assuming that `LLVM_ENABLE_ASSERTIONS=ON` and `LIBCXX_HARDENING_MODE=none` is explicitly set:
1. We get the warning, it is annoying but not the end of the world
2. The `_LIBCPP_HARDENING_MODE` macro will be defined to the explicitly set value of `LIBCXX_HARDENING_MODE_NONE` meaning LLVM components will be built without hardening.

> I still think there is some benefits behind LLVM_ENABLE_ASSERTION to get maximum error checking for compiler so when you build libcxx together, you get maximum error checking from libcxx runtime as well.

I have no problems with this, I agree.

> And there is a switch to disable that behavior if you don't want to have that by defining `LIBCXX_HARDENING_MODE` directly and you don't need `auto` placeholder at all.

See my point above, that switch doesn't work, it will also disable hardening in the main build which I would like to preserve.

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


More information about the libcxx-commits mailing list