From f237129be15cadabf2915d645d50268617946163 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Fri, 14 Feb 2025 14:47:24 +0100 Subject: [PATCH 1/4] Vendor demangle.hpp header from Boost --- include/gridtools/common/demangle.hpp | 118 ++++++++++++++++++++++++++ include/gridtools/stencil/dump.hpp | 4 +- 2 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 include/gridtools/common/demangle.hpp diff --git a/include/gridtools/common/demangle.hpp b/include/gridtools/common/demangle.hpp new file mode 100644 index 000000000..d7bb74dc0 --- /dev/null +++ b/include/gridtools/common/demangle.hpp @@ -0,0 +1,118 @@ +// core::demangle +// +// Copyright 2014 Peter Dimov +// Copyright 2014 Andrey Semashev +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +# pragma once + +#include + +// __has_include is currently supported by GCC and Clang. However GCC 4.9 may have issues and +// returns 1 for 'defined( __has_include )', while '__has_include' is actually not supported: +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63662 +#if defined( __has_include ) && (!defined(__GNUC__) || (__GNUC__ + 0) >= 5) +# if __has_include() +# define GT_HAS_CXXABI_H +# endif +#elif defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) +# define GT_HAS_CXXABI_H +#endif + +#if defined( GT_HAS_CXXABI_H ) +# include +// For some archtectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library +// (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement +// abi::__cxa_demangle(). We detect this implementation by checking the include guard here. +# if defined( __GABIXX_CXXABI_H__ ) +# undef GT_HAS_CXXABI_H +# else +# include +# include +# endif +#endif + +namespace gridtools +{ + +namespace core +{ + +inline char const * demangle_alloc( char const * name ) noexcept; +inline void demangle_free( char const * name ) noexcept; + +class scoped_demangled_name +{ +private: + char const * m_p; + +public: + explicit scoped_demangled_name( char const * name ) noexcept : + m_p( demangle_alloc( name ) ) + { + } + + ~scoped_demangled_name() noexcept + { + demangle_free( m_p ); + } + + char const * get() const noexcept + { + return m_p; + } + + scoped_demangled_name( scoped_demangled_name const& ) = delete; + scoped_demangled_name& operator= ( scoped_demangled_name const& ) = delete; +}; + + +#if defined( GT_HAS_CXXABI_H ) + +inline char const * demangle_alloc( char const * name ) noexcept +{ + int status = 0; + std::size_t size = 0; + return abi::__cxa_demangle( name, NULL, &size, &status ); +} + +inline void demangle_free( char const * name ) noexcept +{ + std::free( const_cast< char* >( name ) ); +} + +inline std::string demangle( char const * name ) +{ + scoped_demangled_name demangled_name( name ); + char const * p = demangled_name.get(); + if( !p ) + p = name; + return p; +} + +#else + +inline char const * demangle_alloc( char const * name ) noexcept +{ + return name; +} + +inline void demangle_free( char const * ) noexcept +{ +} + +inline std::string demangle( char const * name ) +{ + return name; +} + +#endif + +} // namespace core + +} // namespace gridtools + +#undef GT_HAS_CXXABI_H diff --git a/include/gridtools/stencil/dump.hpp b/include/gridtools/stencil/dump.hpp index 618509f2c..a1cb01f1d 100644 --- a/include/gridtools/stencil/dump.hpp +++ b/include/gridtools/stencil/dump.hpp @@ -13,10 +13,10 @@ #include #include -#include #include #include "../common/defs.hpp" +#include "../common/demangle.hpp" #include "../meta.hpp" #include "be_api.hpp" #include "common/caches.hpp" @@ -34,7 +34,7 @@ namespace gridtools { template auto get_type_name() { - return boost::core::demangle(typeid(T).name()); + return gridtools::core::demangle(typeid(T).name()); } inline auto from(core::parallel) { return "parallel"; } From f6ce48c7ec751d249282884e70b13df87e983479 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 19 Feb 2025 13:55:13 +0100 Subject: [PATCH 2/4] Clean up ifdefs in demangle.hpp --- include/gridtools/common/demangle.hpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/include/gridtools/common/demangle.hpp b/include/gridtools/common/demangle.hpp index d7bb74dc0..943983094 100644 --- a/include/gridtools/common/demangle.hpp +++ b/include/gridtools/common/demangle.hpp @@ -1,4 +1,4 @@ -// core::demangle +// Vendored and slightly simplified version of boost::core::demangle // // Copyright 2014 Peter Dimov // Copyright 2014 Andrey Semashev @@ -11,28 +11,12 @@ #include -// __has_include is currently supported by GCC and Clang. However GCC 4.9 may have issues and -// returns 1 for 'defined( __has_include )', while '__has_include' is actually not supported: -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63662 -#if defined( __has_include ) && (!defined(__GNUC__) || (__GNUC__ + 0) >= 5) -# if __has_include() -# define GT_HAS_CXXABI_H -# endif -#elif defined( __GLIBCXX__ ) || defined( __GLIBCPP__ ) -# define GT_HAS_CXXABI_H +#if __has_include() +#define GT_HAS_CXXABI_H #endif -#if defined( GT_HAS_CXXABI_H ) -# include -// For some archtectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library -// (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement -// abi::__cxa_demangle(). We detect this implementation by checking the include guard here. -# if defined( __GABIXX_CXXABI_H__ ) -# undef GT_HAS_CXXABI_H -# else -# include -# include -# endif +#if defined(GT_HAS_CXXABI_H) +#include #endif namespace gridtools From e4c8fedf79fa9512553de0ecdbc1fd5ac0a1a0b1 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 19 Feb 2025 13:55:29 +0100 Subject: [PATCH 3/4] Format demangle.hpp --- include/gridtools/common/demangle.hpp | 92 ++++++++++----------------- 1 file changed, 33 insertions(+), 59 deletions(-) diff --git a/include/gridtools/common/demangle.hpp b/include/gridtools/common/demangle.hpp index 943983094..0853aa038 100644 --- a/include/gridtools/common/demangle.hpp +++ b/include/gridtools/common/demangle.hpp @@ -7,7 +7,7 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt -# pragma once +#pragma once #include @@ -19,83 +19,57 @@ #include #endif -namespace gridtools -{ +namespace gridtools { -namespace core -{ + namespace core { -inline char const * demangle_alloc( char const * name ) noexcept; -inline void demangle_free( char const * name ) noexcept; + inline char const *demangle_alloc(char const *name) noexcept; + inline void demangle_free(char const *name) noexcept; -class scoped_demangled_name -{ -private: - char const * m_p; + class scoped_demangled_name { + private: + char const *m_p; -public: - explicit scoped_demangled_name( char const * name ) noexcept : - m_p( demangle_alloc( name ) ) - { - } + public: + explicit scoped_demangled_name(char const *name) noexcept : m_p(demangle_alloc(name)) {} - ~scoped_demangled_name() noexcept - { - demangle_free( m_p ); - } + ~scoped_demangled_name() noexcept { demangle_free(m_p); } - char const * get() const noexcept - { - return m_p; - } + char const *get() const noexcept { return m_p; } - scoped_demangled_name( scoped_demangled_name const& ) = delete; - scoped_demangled_name& operator= ( scoped_demangled_name const& ) = delete; -}; + scoped_demangled_name(scoped_demangled_name const &) = delete; + scoped_demangled_name &operator=(scoped_demangled_name const &) = delete; + }; +#if defined(GT_HAS_CXXABI_H) -#if defined( GT_HAS_CXXABI_H ) - -inline char const * demangle_alloc( char const * name ) noexcept -{ - int status = 0; - std::size_t size = 0; - return abi::__cxa_demangle( name, NULL, &size, &status ); -} + inline char const *demangle_alloc(char const *name) noexcept { + int status = 0; + std::size_t size = 0; + return abi::__cxa_demangle(name, NULL, &size, &status); + } -inline void demangle_free( char const * name ) noexcept -{ - std::free( const_cast< char* >( name ) ); -} + inline void demangle_free(char const *name) noexcept { std::free(const_cast(name)); } -inline std::string demangle( char const * name ) -{ - scoped_demangled_name demangled_name( name ); - char const * p = demangled_name.get(); - if( !p ) - p = name; - return p; -} + inline std::string demangle(char const *name) { + scoped_demangled_name demangled_name(name); + char const *p = demangled_name.get(); + if (!p) + p = name; + return p; + } #else -inline char const * demangle_alloc( char const * name ) noexcept -{ - return name; -} + inline char const *demangle_alloc(char const *name) noexcept { return name; } -inline void demangle_free( char const * ) noexcept -{ -} + inline void demangle_free(char const *) noexcept {} -inline std::string demangle( char const * name ) -{ - return name; -} + inline std::string demangle(char const *name) { return name; } #endif -} // namespace core + } // namespace core } // namespace gridtools From 430f71d89c000ea0ebcce1f0be38f0ed59899b48 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Wed, 19 Feb 2025 13:57:36 +0100 Subject: [PATCH 4/4] Move demangle helper to gridtools::common namespace --- include/gridtools/common/demangle.hpp | 4 ++-- include/gridtools/stencil/dump.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/gridtools/common/demangle.hpp b/include/gridtools/common/demangle.hpp index 0853aa038..c948ebbd6 100644 --- a/include/gridtools/common/demangle.hpp +++ b/include/gridtools/common/demangle.hpp @@ -21,7 +21,7 @@ namespace gridtools { - namespace core { + namespace common { inline char const *demangle_alloc(char const *name) noexcept; inline void demangle_free(char const *name) noexcept; @@ -69,7 +69,7 @@ namespace gridtools { #endif - } // namespace core + } // namespace common } // namespace gridtools diff --git a/include/gridtools/stencil/dump.hpp b/include/gridtools/stencil/dump.hpp index a1cb01f1d..b9a220761 100644 --- a/include/gridtools/stencil/dump.hpp +++ b/include/gridtools/stencil/dump.hpp @@ -34,7 +34,7 @@ namespace gridtools { template auto get_type_name() { - return gridtools::core::demangle(typeid(T).name()); + return common::demangle(typeid(T).name()); } inline auto from(core::parallel) { return "parallel"; }