[libc-commits] [libc] [libc] Add backup definition for LONG_WIDTH in limits-macros.h. (PR #79375)

via libc-commits libc-commits at lists.llvm.org
Wed Jan 24 13:55:02 PST 2024


https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/79375

>From 59211749bfa713d0e3cfcb16f6b0dbda174cd83e Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 24 Jan 2024 16:44:28 -0500
Subject: [PATCH 1/2] [libc] Add backup definition for LONG_WIDTH in
 limits-macros.h.

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

diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
index fc21d1318a081b2..1926bc25bcfa1dc 100644
--- a/libc/include/llvm-libc-macros/limits-macros.h
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -69,8 +69,8 @@
 #define LONG_WIDTH __LONG_WIDTH__
 #elif defined(__WORDSIZE)
 #define LONG_WIDTH __WORDSIZE
-#else
-#error "Unknown WORDSIZE to define LONG_WIDTH."
+#else // use sizeof(long) * CHAR_BIT as backup.
+#define LONG_WIDTH (sizeof(long) * CHAR_BIT)
 #endif // __LONG_WIDTH__
 #endif // LONG_WIDTH
 

>From 04434deaa4d4c9492049c947e9a7eaf08d756baa Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue at google.com>
Date: Wed, 24 Jan 2024 16:54:32 -0500
Subject: [PATCH 2/2] Add comment why the backup is needed.

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

diff --git a/libc/include/llvm-libc-macros/limits-macros.h b/libc/include/llvm-libc-macros/limits-macros.h
index 1926bc25bcfa1dc..3ccfbff79932904 100644
--- a/libc/include/llvm-libc-macros/limits-macros.h
+++ b/libc/include/llvm-libc-macros/limits-macros.h
@@ -69,7 +69,8 @@
 #define LONG_WIDTH __LONG_WIDTH__
 #elif defined(__WORDSIZE)
 #define LONG_WIDTH __WORDSIZE
-#else // use sizeof(long) * CHAR_BIT as backup.
+#else
+// 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