[libc-commits] [libc] [libc] Return the written character from putc, fputc and putchar on baremetal and gpu (PR #240248)
via libc-commits
libc-commits at lists.llvm.org
Sun Nov 8 19:48:33 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mike Lothian (FireBurn)
<details>
<summary>Changes</summary>
Follow-up to #<!-- -->239980, which changed the generic implementations to return the character written as an unsigned char converted to int, as C requires, and updated the shared tests to expect it. The baremetal and gpu implementations still returned zero.
Each of the six functions now returns `static_cast<int>(uc)` on success. The gpu sources compile; the baremetal ones need that target's configuration to build, which I did not have here, so please let the bots check them.
Assisted-by: Claude
---
Full diff: https://github.com/llvm/llvm-project/pull/240248.diff
6 Files Affected:
- (modified) libc/src/stdio/baremetal/fputc.cpp (+1-1)
- (modified) libc/src/stdio/baremetal/putc.cpp (+1-1)
- (modified) libc/src/stdio/baremetal/putchar.cpp (+1-1)
- (modified) libc/src/stdio/gpu/fputc.cpp (+1-1)
- (modified) libc/src/stdio/gpu/putc.cpp (+1-1)
- (modified) libc/src/stdio/gpu/putchar.cpp (+1-1)
``````````diff
diff --git a/libc/src/stdio/baremetal/fputc.cpp b/libc/src/stdio/baremetal/fputc.cpp
index e179fbd722b681..578f8c577cd10f 100644
--- a/libc/src/stdio/baremetal/fputc.cpp
+++ b/libc/src/stdio/baremetal/fputc.cpp
@@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, fputc, (int c, ::FILE *stream)) {
// The stream should be in an error state in this case.
return EOF;
}
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/putc.cpp b/libc/src/stdio/baremetal/putc.cpp
index 72a425b8719d59..8bbba6ac1b73d9 100644
--- a/libc/src/stdio/baremetal/putc.cpp
+++ b/libc/src/stdio/baremetal/putc.cpp
@@ -28,7 +28,7 @@ LLVM_LIBC_FUNCTION(int, putc, (int c, ::FILE *stream)) {
// The stream should be in an error state in this case.
return EOF;
}
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/putchar.cpp b/libc/src/stdio/baremetal/putchar.cpp
index 9d39fae66e80cb..c7a694ab0738e8 100644
--- a/libc/src/stdio/baremetal/putchar.cpp
+++ b/libc/src/stdio/baremetal/putchar.cpp
@@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, putchar, (int c)) {
// The stream should be in an error state in this case.
return EOF;
}
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/gpu/fputc.cpp b/libc/src/stdio/gpu/fputc.cpp
index 8a8959b04d20db..3a1c168b882898 100644
--- a/libc/src/stdio/gpu/fputc.cpp
+++ b/libc/src/stdio/gpu/fputc.cpp
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(int, fputc, (int c, ::FILE *stream)) {
if (1 != written)
return EOF;
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/gpu/putc.cpp b/libc/src/stdio/gpu/putc.cpp
index da80d6c35a5327..14c9115a44569f 100644
--- a/libc/src/stdio/gpu/putc.cpp
+++ b/libc/src/stdio/gpu/putc.cpp
@@ -22,7 +22,7 @@ LLVM_LIBC_FUNCTION(int, putc, (int c, ::FILE *stream)) {
if (1 != written)
return EOF;
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/gpu/putchar.cpp b/libc/src/stdio/gpu/putchar.cpp
index da2d0a8376192c..c61253a9640191 100644
--- a/libc/src/stdio/gpu/putchar.cpp
+++ b/libc/src/stdio/gpu/putchar.cpp
@@ -21,7 +21,7 @@ LLVM_LIBC_FUNCTION(int, putchar, (int c)) {
if (1 != written)
return EOF;
- return 0;
+ return static_cast<int>(uc);
}
} // namespace LIBC_NAMESPACE_DECL
``````````
</details>
https://github.com/llvm/llvm-project/pull/240248
More information about the libc-commits
mailing list