summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2024-01-02 02:16:28 +0000
committerEli Schwartz <eschwartz93@gmail.com>2024-01-09 02:02:03 -0500
commit90098473d51e6f059e775f1833b0a2ea91c8f8f9 (patch)
tree0bd27016acb38506e402c633030cce57c97a5c56 /mesonbuild/compilers/cpp.py
parentc41fbf5076a79d5561ea0655d59131f4c34ef535 (diff)
downloadmeson-90098473d51e6f059e775f1833b0a2ea91c8f8f9.tar.gz
compilers: cpp: wire up stdlib assertions
None of the options set here affect ABI and are intended for detecting constraint violations. For GCC, we simply need to set -D_GLIBCXX_ASSERTIONS. For Clang, the situation is far more complicated: * LLVM 18 uses a 'hardened mode' (https://libcxx.llvm.org/Hardening.html). There are several levels of severity available here. I've chosen _LIBCPP_HARDENING_MODE_EXTENSIVE as the strongest-but-one. The strongest one (_DEBUG) doesn't affect ABI still but is reserved for stldebug. * LLVM 15 uses a similar approach to libstdc++ called '_LIBCPP_ENABLE_ASSERTIONS' Note that LLVM 17 while in development had fully deprecated _LIBCPP_ENABLE_ASSERTIONS in favour of hardened, but changed its mind last-minute: https://discourse.llvm.org/t/rfc-hardening-in-libc/73925/4. Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
-rw-r--r--mesonbuild/compilers/cpp.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 226605390..f6a03caf2 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -293,6 +293,20 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
return libs
return []
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ args: T.List[str] = []
+ if disable:
+ return ['-DNDEBUG']
+
+ # Clang supports both libstdc++ and libc++
+ args.append('-D_GLIBCXX_ASSERTIONS=1')
+ if version_compare(self.version, '>=18'):
+ args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE')
+ elif version_compare(self.version, '>=15'):
+ args.append('-D_LIBCPP_ENABLE_ASSERTIONS=1')
+
+ return args
+
class ArmLtdClangCPPCompiler(ClangCPPCompiler):
@@ -462,6 +476,14 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
return libs
return []
+ def get_assert_args(self, disable: bool) -> T.List[str]:
+ if disable:
+ return ['-DNDEBUG']
+
+ # XXX: This needs updating if/when GCC starts to support libc++.
+ # It currently only does so via an experimental configure arg.
+ return ['-D_GLIBCXX_ASSERTIONS=1']
+
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
return ['-fpch-preprocess', '-include', os.path.basename(header)]