Skip to content

Conversation

@lntue
Copy link
Contributor

@lntue lntue commented Jun 12, 2025

The current definition of ssize_t does not have the same bit width as size_t on 32-bit platforms.

@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2025

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

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

2 Files Affected:

  • (modified) libc/include/llvm-libc-types/size_t.h (+1-6)
  • (modified) libc/include/llvm-libc-types/ssize_t.h (+1-1)
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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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.

@lntue lntue merged commit 82f1967 into llvm:main Jun 12, 2025
15 checks passed
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
… __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.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
… __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.
@lntue lntue deleted the size branch July 18, 2025 15:22
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