From a5fdd3771f8ec510167d44ef43cda1285ee05610 Mon Sep 17 00:00:00 2001 From: Sam James Date: Tue, 2 Jan 2024 03:03:57 +0000 Subject: compilers: cpp: wire up debugstl for Clang For Clang, we now pass -D_GLIBCXX_DEBUG=1 if debugstl is enabled, and we also pass -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG. Per https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3, we can't use _LIBCPP_DEBUG for older Clang versions as it's unreliable unless libc++ was built with it. We choose MODE_DEBUG for stldebug while building with assertions will do MODE_EXTENSIVE. Signed-off-by: Sam James Signed-off-by: Eli Schwartz --- mesonbuild/compilers/cpp.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'mesonbuild/compilers/cpp.py') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index f6a03caf2..0ff89a3ea 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -242,6 +242,10 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): opts = CPPCompiler.get_options(self) key = OptionKey('key', machine=self.for_machine, lang=self.language) opts.update({ + key.evolve('debugstl'): coredata.UserBooleanOption( + 'STL debug mode', + False, + ), key.evolve('eh'): coredata.UserComboOption( 'C++ exception handling type.', ['none', 'default', 'a', 's', 'sc'], @@ -277,6 +281,15 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): non_msvc_eh_options(options[key.evolve('eh')].value, args) + if options[key.evolve('debugstl')].value: + args.append('-D_GLIBCXX_DEBUG=1') + + # We can't do _LIBCPP_DEBUG because it's unreliable unless libc++ was built with it too: + # https://discourse.llvm.org/t/building-a-program-with-d-libcpp-debug-1-against-a-libc-that-is-not-itself-built-with-that-define/59176/3 + # Note that unlike _GLIBCXX_DEBUG, _MODE_DEBUG doesn't break ABI. It's just slow. + if version_compare(self.version, '>=18'): + args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG') + if not options[key.evolve('rtti')].value: args.append('-fno-rtti') -- cgit v1.2.3