[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 00:48:15 PDT 2026
Maetveis wrote:
> > Would be okay with a patch that removes the LIBCXX_HARDENING_MODE=auto handling, essentially removing the implied LLVM_ENABLE_ASSERTIONS=ON -> LIBCXX_HARDENING_MODE=extensive link?
>
> ABSOLUTELY NOT. LLVM_ENABLE_ASSERTIONS=ON has to imply using LIBCXX_HARDENING_MODE=extensive with libcxx header. That matches the behavior of using libstdc++ and is essential for catching mis-use of std containers.
Let me try to clarify my intent: currently `LLVM_ENABLE_ASSERTIONS` in the parent build does the following 2 things
1. Adds the macro `_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE` to all C++ compilations **in the main build**. This is to catch mis-use of std containers as you mention, it's completely analogous to `_GLIBCXX_ASSERTIONS` for libstdc++.
2. Defines the cmake variable `LIBCXX_HARDENING_MODE` in the parent build. The variable will be forwarded to the runtime build because it starts with `LIBCXX`: https://github.com/llvm/llvm-project/blob/33cbf6811bad57d89c4088f80633d21ee5b42dbc/llvm/runtimes/CMakeLists.txt#L259-L263 https://github.com/llvm/llvm-project/blob/33cbf6811bad57d89c4088f80633d21ee5b42dbc/llvm/runtimes/CMakeLists.txt#L698-L701 https://github.com/llvm/llvm-project/blob/33cbf6811bad57d89c4088f80633d21ee5b42dbc/llvm/runtimes/CMakeLists.txt#L361-L365
What I am proposing in this comment is to remove number 2., but keep number 1.
> If you really want to improve the build, you need to separate the configuration for the user of libcxx header and the configuration for building libcxx when everything is configured together.
This is already the case even prior to this PR. The `_LIBCPP_HARDENING_MODE` macro definition from the parent cmake invocation does NOT reach the runtime build. Additionally `LLVM_ENABLE_ASSERTIONS` is NOT forwarded to the runtime configuration, so while `HandleLLVMOptions.cmake` is invoked there again this code is not reached.
https://github.com/llvm/llvm-project/pull/229359
More information about the libcxx-commits
mailing list