[clang] Add option -fstdlib-hardening= (PR #78763)
Louis Dionne via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 25 05:47:18 PST 2024
================
@@ -851,6 +851,28 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Twine(getClangFullCPPVersion()) + "\"");
// Initialize language-specific preprocessor defines.
+ if (LangOpts.getStdlibHardeningMode()) {
+ const char *StdlibHardeningStr;
+
+ switch (LangOpts.getStdlibHardeningMode()) {
+ case clang::LangOptions::STDLIB_HARDENING_MODE_NOT_SPECIFIED:
+ llvm_unreachable("Unexpected libc++ hardening mode value");
+ case clang::LangOptions::STDLIB_HARDENING_MODE_NONE:
+ StdlibHardeningStr = "_STDLIB_HARDENING_MODE_NONE";
----------------
ldionne wrote:
The macros used by libc++ are `_LIBCPP_HARDENING_MODE`, `_LIBCPP_HARDENING_MODE_NONE` & al. While the naming of the clang option should use the "any standard library" terminology, the actual macros we set must be the libc++ ones. If libstdc++ had something similar in the future, we would switch to:
```c++
if (LangOpts.getStdlibHardeningMode()) {
if (stdlib is libc++) {
set-macros-for-libcxx;
} else {
set-macros-for-libstdcxx;
}
}
```
https://github.com/llvm/llvm-project/pull/78763
More information about the cfe-commits
mailing list