Skip to content

[libcxxabi] Use __LDBL_MANT_DIG__ for configuring demangling of long doubles #134976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -5741,14 +5741,12 @@ struct FloatData<double>
template <>
struct FloatData<long double>
{
#if defined(__mips__) && defined(__mips_n64) || defined(__aarch64__) || \
defined(__wasm__) || defined(__riscv) || defined(__loongarch__) || \
defined(__ve__)
static const size_t mangled_size = 32;
#elif defined(__arm__) || defined(__mips__) || defined(__hexagon__)
static const size_t mangled_size = 16;
#else
static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms
#if __LDBL_MANT_DIG__ == 113
static const size_t mangled_size = 32;
#elif __LDBL_MANT_DIG__ == 53
static const size_t mangled_size = 16;
#else // __LDBL_MANT_DIG__ == 64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better to check the mantissa here as well and #error if there is a new size. Otherwise we might be silently wrong on some platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea, will fix.

However - I realized that while we don't support building libcxxabi with compilers that aren't GCC compatible, we also do copy this file into llvm/include/llvm/Demangle/ItaniumDemangle.h, which is built as part of the host build of LLVM - and that can be built with MSVC as well. (And MSVC doesn't define any of the arch defines that we defined before either.)

MSVC only has long double == double for all currently known architectures (and clang-cl matches this), so I can add an || defined(_MSC_VER) for that.

static const size_t mangled_size = 20;
#endif
// `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
// 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.
Expand Down
4 changes: 0 additions & 4 deletions libcxxabi/test/test_demangle.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
// dd8b266ef.
// UNSUPPORTED: using-built-library-before-llvm-20

// Android's long double on x86[-64] is (64/128)-bits instead of Linux's usual
// 80-bit format, and this demangling test is failing on it.
// XFAIL: LIBCXX-ANDROID-FIXME && target={{i686|x86_64}}-{{.+}}-android{{.*}}

// XFAIL: win32-broken-printf-a-precision

#include "support/timer.h"
Expand Down
Loading