-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[libc] Update size_t and ssize_t definitions to use __SIZE_TYPE__ and __PTRDIFF_TYPE__ respectively. #143921
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
Conversation
… __PTRDIFF_TYPE__ respectively.
|
@llvm/pr-subscribers-libc Author: None (lntue) ChangesFull diff: https://github.com/llvm/llvm-project/pull/143921.diff 2 Files Affected:
diff --git a/libc/include/llvm-libc-types/size_t.h b/libc/include/llvm-libc-types/size_t.h
index 3b31b0820f237..26ae68abe0ee7 100644
--- a/libc/include/llvm-libc-types/size_t.h
+++ b/libc/include/llvm-libc-types/size_t.h
@@ -9,11 +9,6 @@
#ifndef LLVM_LIBC_TYPES_SIZE_T_H
#define LLVM_LIBC_TYPES_SIZE_T_H
-// Since __need_size_t is defined, we get the definition of size_t from the
-// standalone C header stddef.h. Also, because __need_size_t is defined,
-// including stddef.h will pull only the type size_t and nothing else.
-#define __need_size_t
-#include <stddef.h>
-#undef __need_size_t
+typedef __SIZE_TYPE__ size_t;
#endif // LLVM_LIBC_TYPES_SIZE_T_H
diff --git a/libc/include/llvm-libc-types/ssize_t.h b/libc/include/llvm-libc-types/ssize_t.h
index 41e4b6d2c500a..8f579e2749bac 100644
--- a/libc/include/llvm-libc-types/ssize_t.h
+++ b/libc/include/llvm-libc-types/ssize_t.h
@@ -9,6 +9,6 @@
#ifndef LLVM_LIBC_TYPES_SSIZE_T_H
#define LLVM_LIBC_TYPES_SSIZE_T_H
-typedef __INT64_TYPE__ ssize_t;
+typedef __PTRDIFF_TYPE__ ssize_t;
#endif // LLVM_LIBC_TYPES_SSIZE_T_H
|
| // including stddef.h will pull only the type size_t and nothing else. | ||
| #define __need_size_t | ||
| #include <stddef.h> | ||
| #undef __need_size_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to move away from getting size_t from stddef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's cleaner and both clang and gcc provide this type definition, which is used in the stddef.h to define size_t anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and isn't llvm-libc-types supposed to be the set of headers that don't depend on the "host" libc? that was my reasoning for "this makes sense here"... (it's only very recently that bionic moved to clang <stddef.h> rather than its own, for example.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the llvm-libc-types headers aren't supposed to depend on host libc headers, but stddef is supposed to come from the compiler iirc. That being said I'm not opposed to defining our own, but we will need to clean up all the places where stddef is currently included in /src. We'd need to do that anyways so not too big a deal.
… __PTRDIFF_TYPE__ respectively. (llvm#143921) The current definition of `ssize_t` does not have the same bit width as `size_t` on 32-bit platforms.
… __PTRDIFF_TYPE__ respectively. (llvm#143921) The current definition of `ssize_t` does not have the same bit width as `size_t` on 32-bit platforms.
The current definition of
ssize_tdoes not have the same bit width assize_ton 32-bit platforms.