From b5d80c4948ef2494a9544cb638ec993a36fe91e1 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Wed, 16 Jul 2025 21:35:48 +0000 Subject: [PATCH] Bug 1974917 - Fix TypeToString to automatically handle named/numbered int types. r=nbp,glandium a=RyanVM `TypeToString` defines instances for all the numbered int types (like `int32_t`); unfortunately this can leave some of the named types (like `int`) out of the sequence depending on how the C headers define the numbered ones. There are additional instances for signed and unsigned long, which are needed on some platforms and would break the build on others; there is an `#ifdef` which attempts to handle that, but the result of all this is that CI can build for 32-bit x86 Linux but it fails when I try locally. This patch simplifies things and removes the `#ifdef` using a similar idea to bug 836438: the unspecialized `TypeToString` calls another function with its own set of specializations, with numbered types in the first layer and named types in the second. --- mfbt/Casting.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mfbt/Casting.h b/mfbt/Casting.h index 35be564da1bd..87cf9c9bd72c 100644 --- a/mfbt/Casting.h +++ b/mfbt/Casting.h @@ -83,7 +83,12 @@ constexpr uint64_t safe_integer_unsigned() { } template -const char* TypeToString(); +const char* TypeToStringFallback(); + +template +inline constexpr const char* TypeToString() { + return TypeToStringFallback(); +} #define T2S(type) \ template <> \ @@ -91,6 +96,12 @@ const char* TypeToString(); return #type; \ } +#define T2SF(type) \ + template <> \ + inline constexpr const char* TypeToStringFallback() { \ + return #type; \ + } + T2S(uint8_t); T2S(uint16_t); T2S(uint32_t); @@ -101,14 +112,15 @@ T2S(int32_t); T2S(int64_t); T2S(char16_t); T2S(char32_t); -#if defined(XP_DARWIN) || defined(XP_WIN) || defined(__wasm__) -T2S(long); -T2S(unsigned long); -#endif +T2SF(int); +T2SF(unsigned int); +T2SF(long); +T2SF(unsigned long); T2S(float); T2S(double); #undef T2S +#undef T2SF template inline void DiagnosticMessage(In aIn, char aDiagnostic[1024]) {