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

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


Author: lntue
Date: 2024-01-24T20:02:03-05:00
New Revision: e9355b1b3e36616bb86575270ff3a4664d2cf4f7

URL: https://github.com/llvm/llvm-project/commit/e9355b1b3e36616bb86575270ff3a4664d2cf4f7
DIFF: https://github.com/llvm/llvm-project/commit/e9355b1b3e36616bb86575270ff3a4664d2cf4f7.diff

LOG: [libc] Use __SIZEOF_LONG__ to define LONG_WIDTH instead of sizeof(long). (#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.

Added: 
    

Modified: 
    libc/include/llvm-libc-macros/limits-macros.h

Removed: 
    


################################################################################
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