[libc-commits] [libc] aa4a752 - [libc] Return the written character from putc, fputc and putchar on baremetal and gpu (#240248)

via libc-commits libc-commits at lists.llvm.org
Sun Nov 8 20:02:20 PST 2026


Author: Mike Lothian
Date: 2026-11-08T20:02:15-08:00
New Revision: aa4a7528844912195afb373dbb12c2ff72a3a0fe

URL: https://github.com/llvm/llvm-project/commit/aa4a7528844912195afb373dbb12c2ff72a3a0fe
DIFF: https://github.com/llvm/llvm-project/commit/aa4a7528844912195afb373dbb12c2ff72a3a0fe.diff

LOG: [libc] Return the written character from putc, fputc and putchar on baremetal and gpu (#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.

Assisted-by: Claude

Added: 
    

Modified: 
    libc/src/stdio/baremetal/fputc.cpp
    libc/src/stdio/baremetal/putc.cpp
    libc/src/stdio/baremetal/putchar.cpp
    libc/src/stdio/gpu/fputc.cpp
    libc/src/stdio/gpu/putc.cpp
    libc/src/stdio/gpu/putchar.cpp

Removed: 
    


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