[libc-commits] [libc] [libc] Use __SIZEOF_LONG__ to define LONG_WIDTH instead of sizeof(long). (PR #79391)

via libc-commits libc-commits at lists.llvm.org
Wed Jan 24 16:01:08 PST 2024


https://github.com/lntue created https://github.com/llvm/llvm-project/pull/79391

The standard requires `limits.h` constants to be used in preprocessors.  So we use `__SIZEOF_LONG__` instead of `sizeof(long)` to define `LONG_WIDTH`.  The macro `__SIZEOF_LONG__` seems to be available on both clang and gcc since at least version 9.

>From 870074fedf35ea9ac77b937178288a0b8446a574 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 24 Jan 2024 18:53:22 -0500
Subject: [PATCH] [libc] Use __SIZEOF_LONG__ to define LONG_WIDTH instead of
 sizeof(long).

---
 libc/include/llvm-libc-macros/limits-macros.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
index 3ccfbff79932904..3b4df58ae4a1430 100644
--- a/libc/include/llvm-libc-macros/limits-macros.h
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -70,8 +70,9 @@
 #elif defined(__WORDSIZE)
 #define LONG_WIDTH __WORDSIZE
 #else
-// Use sizeof(long) * CHAR_BIT as backup. This is needed for clang-13 or before.
-#define LONG_WIDTH (sizeof(long) * CHAR_BIT)
+// Use __SIZEOF_LONG__ * CHAR_BIT as backup.  This is needed for clang-13 or
+// before.
+#define LONG_WIDTH (__SIZEOF_LONG__ * CHAR_BIT)
 #endif // __LONG_WIDTH__
 #endif // LONG_WIDTH
 



More information about the libc-commits mailing list