Skip to content

Commit 0a1374f

Browse files
committed
[libcxxabi] Use __LDBL_MANT_DIG__ for configuring demangling of long doubles
This avoids needing to hardcode the mapping between architectures and their sizes of long doubles. This fixes a case in test_demangle.pass.cpp, that previously failed like this: .---command stdout------------ | Testing 29859 symbols. | _ZN5test01hIfEEvRAcvjplstT_Le4001a000000000000000E_c should be invalid but is not | Got: 0, void test0::h<float>(char (&) [(unsigned int)(sizeof (float) + 0x0.07ff98f7ep-1022L)]) `----------------------------- .---command stderr------------ | Assertion failed: !passed && "demangle did not fail", file libcxxabi/test/test_demangle.pass.cpp, line 30338 `----------------------------- This testcase is defined within // Is long double fp80? (Only x87 extended double has 64-bit mantissa) #define LDBL_FP80 (__LDBL_MANT_DIG__ == 64) ... #if !LDBL_FP80 ... #endif The case failed, by unexpectedly passing, when the demangler was capable of demangling an 80 bit long double, while the compiler actually is configured for a different size for that type.
1 parent ff13349 commit 0a1374f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

libcxxabi/src/demangle/ItaniumDemangle.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5739,14 +5739,13 @@ struct FloatData<double>
57395739
template <>
57405740
struct FloatData<long double>
57415741
{
5742-
#if defined(__mips__) && defined(__mips_n64) || defined(__aarch64__) || \
5743-
defined(__wasm__) || defined(__riscv) || defined(__loongarch__) || \
5744-
defined(__ve__)
5745-
static const size_t mangled_size = 32;
5746-
#elif defined(__arm__) || defined(__mips__) || defined(__hexagon__)
5747-
static const size_t mangled_size = 16;
5748-
#else
5749-
static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms
5742+
#if __LDBL_MANT_DIG__ == 113
5743+
static const size_t mangled_size = 32;
5744+
#elif __LDBL_MANT_DIG__ == 53
5745+
static const size_t mangled_size = 16;
5746+
#else // __LDBL_MANT_DIG__ == 64
5747+
static const size_t mangled_size =
5748+
20; // May need to be adjusted to 16 or 24 on other platforms
57505749
#endif
57515750
// `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes.
57525751
// 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits.

0 commit comments

Comments
 (0)