[libc-commits] [libc] [libc] Return the written character from putc, fputc and putchar on baremetal and gpu (PR #240248)
Mike Lothian via libc-commits
libc-commits at lists.llvm.org
Sun Nov 8 19:47:56 PST 2026
https://github.com/FireBurn created https://github.com/llvm/llvm-project/pull/240248
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
>From c0988f51acff260f117a9b9e54016c056f48c281 Mon Sep 17 00:00:00 2001
From: Mike Lothian <mike at fireburn.co.uk>
Date: Mon, 9 Nov 2026 03:47:44 +0000
Subject: [PATCH] [libc] Return the written character from putc, fputc and
putchar on baremetal and gpu
#239980 changed the generic implementations to return the character
written, as C requires, and the shared tests now expect that. The
baremetal and gpu implementations still returned zero.
Assisted-by: Claude
---
libc/src/stdio/baremetal/fputc.cpp | 2 +-
libc/src/stdio/baremetal/putc.cpp | 2 +-
libc/src/stdio/baremetal/putchar.cpp | 2 +-
libc/src/stdio/gpu/fputc.cpp | 2 +-
libc/src/stdio/gpu/putc.cpp | 2 +-
libc/src/stdio/gpu/putchar.cpp | 2 +-
6 files changed, 6 insertions(+), 6 deletions(-)
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
More information about the libc-commits
mailing list