Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

lntue
Copy link
Contributor

@lntue lntue commented Jan 25, 2024

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.

@llvmbot llvmbot added the libc label Jan 25, 2024
@llvmbot
Copy link

llvmbot commented Jan 25, 2024

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

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

@lntue lntue merged commit e9355b1 into llvm:main Jan 25, 2024
5 checks passed
@lntue lntue deleted the limit branch January 25, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants