[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:40 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (lntue)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/79391.diff


1 Files Affected:

- (modified) libc/include/llvm-libc-macros/limits-macros.h (+3-2) 


``````````diff
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
 

``````````

</details>


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


More information about the libc-commits mailing list