[libc-commits] [libc] 9ff444c - Revert "[libc] Add getc, ungetc, fflush to enable libc++ iostream on baremetal" (#181931)
via libc-commits
libc-commits at lists.llvm.org
Tue Feb 17 14:56:33 PST 2026
Author: Paul Kirth
Date: 2026-02-17T22:56:28Z
New Revision: 9ff444c0aa804f1f73822f45311f5a1698d0b7d0
URL: https://github.com/llvm/llvm-project/commit/9ff444c0aa804f1f73822f45311f5a1698d0b7d0
DIFF: https://github.com/llvm/llvm-project/commit/9ff444c0aa804f1f73822f45311f5a1698d0b7d0.diff
LOG: Revert "[libc] Add getc, ungetc, fflush to enable libc++ iostream on baremetal" (#181931)
Reverts llvm/llvm-project#175530
This PR breaks libc header generation on Windows stage2 builds for a to
be determined reason.
Added:
Modified:
libc/config/baremetal/aarch64/entrypoints.txt
libc/config/baremetal/arm/entrypoints.txt
libc/src/stdio/baremetal/CMakeLists.txt
libc/src/stdio/baremetal/file_internal.h
libc/src/stdio/baremetal/getc.cpp
libc/src/stdio/baremetal/vfscanf_internal.h
Removed:
libc/src/stdio/baremetal/fflush.cpp
libc/src/stdio/baremetal/file_internal.cpp
libc/src/stdio/baremetal/ungetc.cpp
################################################################################
diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt
index e0282bcb4fa23..742d96761c415 100644
--- a/libc/config/baremetal/aarch64/entrypoints.txt
+++ b/libc/config/baremetal/aarch64/entrypoints.txt
@@ -126,7 +126,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.asprintf
libc.src.stdio.feof
libc.src.stdio.ferror
- libc.src.stdio.fflush
libc.src.stdio.fgetc
libc.src.stdio.fgets
libc.src.stdio.fprintf
@@ -135,7 +134,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.fread
libc.src.stdio.fscanf
libc.src.stdio.fwrite
- libc.src.stdio.getc
libc.src.stdio.getchar
libc.src.stdio.printf
libc.src.stdio.putc
@@ -154,7 +152,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsnprintf
libc.src.stdio.vsprintf
libc.src.stdio.vsscanf
- libc.src.stdio.ungetc
# stdbit.h entrypoints
libc.src.stdbit.stdc_bit_ceil_uc
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index f7ef4ea09f5b6..95cb0dea8e49e 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -126,7 +126,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.asprintf
libc.src.stdio.feof
libc.src.stdio.ferror
- libc.src.stdio.fflush
libc.src.stdio.fgetc
libc.src.stdio.fgets
libc.src.stdio.fprintf
@@ -135,7 +134,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.fread
libc.src.stdio.fscanf
libc.src.stdio.fwrite
- libc.src.stdio.getc
libc.src.stdio.getchar
libc.src.stdio.printf
libc.src.stdio.putc
@@ -154,7 +152,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.vsnprintf
libc.src.stdio.vsprintf
libc.src.stdio.vsscanf
- libc.src.stdio.ungetc
# stdbit.h entrypoints
libc.src.stdbit.stdc_bit_ceil_uc
diff --git a/libc/src/stdio/baremetal/CMakeLists.txt b/libc/src/stdio/baremetal/CMakeLists.txt
index abe134959e09b..a706accecf152 100644
--- a/libc/src/stdio/baremetal/CMakeLists.txt
+++ b/libc/src/stdio/baremetal/CMakeLists.txt
@@ -1,7 +1,5 @@
-add_object_library(
+add_header_library(
file_internal
- SRCS
- file_internal.cpp
HDRS
file_internal.h
DEPENDS
@@ -33,7 +31,6 @@ add_header_library(
HDRS
vfscanf_internal.h
DEPENDS
- .file_internal
libc.hdr.types.FILE
libc.hdr.stdio_macros
libc.src.__support.arg_list
@@ -79,27 +76,6 @@ add_entrypoint_object(
libc.src.errno.errno
)
-add_entrypoint_object(
- getc
- SRCS
- getc.cpp
- HDRS
- ../getc.h
- DEPENDS
- libc.hdr.types.FILE
- libc.src.stdio.baremetal.fgetc
-)
-
-add_entrypoint_object(
- fflush
- SRCS
- fflush.cpp
- HDRS
- ../fflush.h
- DEPENDS
- .file_internal
-)
-
add_entrypoint_object(
fgets
SRCS
@@ -247,18 +223,6 @@ add_entrypoint_object(
libc.src.errno.errno
)
-add_entrypoint_object(
- ungetc
- SRCS
- ungetc.cpp
- HDRS
- ../ungetc.h
- DEPENDS
- .file_internal
- libc.hdr.stdio_macros
- libc.hdr.types.FILE
-)
-
add_entrypoint_object(
puts
SRCS
diff --git a/libc/src/stdio/baremetal/fflush.cpp b/libc/src/stdio/baremetal/fflush.cpp
deleted file mode 100644
index 4a39c25ae11c9..0000000000000
--- a/libc/src/stdio/baremetal/fflush.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Implementation of fflush for baremetal -----------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/stdio/fflush.h"
-
-#include "src/__support/common.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-// Baremetal uses unbuffered I/O, so there is nothing to flush.
-LLVM_LIBC_FUNCTION(int, fflush, (::FILE * stream)) {
- (void)stream;
- // TODO: Shall we have an embedding API for fflush?
- return 0;
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/file_internal.cpp b/libc/src/stdio/baremetal/file_internal.cpp
deleted file mode 100644
index c12ab1c90d55b..0000000000000
--- a/libc/src/stdio/baremetal/file_internal.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-//===--- Helpers for file I/O on baremetal ----------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/stdio/baremetal/file_internal.h"
-#include "src/__support/CPP/optional.h"
-
-#include "hdr/stdio_macros.h" // for EOF, FILE
-
-namespace LIBC_NAMESPACE_DECL {
-
-// Out of standard streams only stdin supports ungetc,
-// because stdin is readable - ungetc on stdout/stderr is undefined.
-// Only one value is required by the C standard to be stored by ungetc.
-// This minimal implementation only handles stdin and returns error on all
-// other streams.
-// TODO: Shall we have an embedding API for ungetc?
-
-static cpp::optional<unsigned char> ungetc_state_stdin;
-
-bool pop_ungetc_value(::FILE *stream, unsigned char &out) {
- if (stream != stdin)
- return false;
-
- if (!ungetc_state_stdin)
- return false;
-
- out = *ungetc_state_stdin;
- ungetc_state_stdin.reset();
- return true;
-}
-
-int push_ungetc_value(::FILE *stream, int c) {
- if (c == EOF || stream == nullptr)
- return EOF;
-
- if (stream != stdin)
- return EOF;
-
- if (ungetc_state_stdin)
- return EOF;
-
- ungetc_state_stdin =
- cpp::optional<unsigned char>{static_cast<unsigned char>(c)};
- return c;
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/file_internal.h b/libc/src/stdio/baremetal/file_internal.h
index b2a84ce44e2df..292a1e22c954b 100644
--- a/libc/src/stdio/baremetal/file_internal.h
+++ b/libc/src/stdio/baremetal/file_internal.h
@@ -32,35 +32,11 @@ struct FileIOResult {
constexpr operator size_t() { return value; }
};
-// ungetc handling.
-int push_ungetc_value(::FILE *stream, int c);
-bool pop_ungetc_value(::FILE *stream, unsigned char &out);
-
-LIBC_INLINE int ungetc_internal(int c, ::FILE *stream) {
- return push_ungetc_value(stream, c);
-}
-
LIBC_INLINE FileIOResult read_internal(char *buf, size_t size, ::FILE *stream) {
- if (size == 0)
- return 0;
-
- unsigned char ungetc_value = 0;
- size_t ungetc_value_copied = 0;
-
- if (pop_ungetc_value(stream, ungetc_value)) {
- buf[0] = static_cast<char>(ungetc_value);
- ungetc_value_copied = 1;
-
- if (size == 1)
- return 1;
- }
-
- ssize_t ret = __llvm_libc_stdio_read(stream, buf + ungetc_value_copied,
- size - ungetc_value_copied);
+ ssize_t ret = __llvm_libc_stdio_read(stream, buf, size);
if (ret < 0)
- return {ungetc_value_copied, static_cast<int>(-ret)};
-
- return ret + ungetc_value_copied;
+ return {0, static_cast<int>(-ret)};
+ return ret;
}
LIBC_INLINE FileIOResult write_internal(const char *buf, size_t size,
diff --git a/libc/src/stdio/baremetal/getc.cpp b/libc/src/stdio/baremetal/getc.cpp
index b56d23bc4807a..e69de29bb2d1d 100644
--- a/libc/src/stdio/baremetal/getc.cpp
+++ b/libc/src/stdio/baremetal/getc.cpp
@@ -1,31 +0,0 @@
-//===-- Implementation of getc for baremetal -------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/stdio/getc.h"
-
-#include "hdr/stdio_macros.h" // for EOF.
-#include "hdr/types/FILE.h"
-#include "src/__support/common.h"
-#include "src/__support/libc_errno.h"
-#include "src/__support/macros/config.h"
-#include "src/stdio/baremetal/file_internal.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(int, getc, (::FILE * stream)) {
- unsigned char c;
- auto result = read_internal(reinterpret_cast<char *>(&c), 1, stream);
- if (result.has_error())
- libc_errno = result.error;
-
- if (result.value != 1)
- return EOF;
- return c;
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/ungetc.cpp b/libc/src/stdio/baremetal/ungetc.cpp
deleted file mode 100644
index 72a25dbf8fb9f..0000000000000
--- a/libc/src/stdio/baremetal/ungetc.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation of ungetc for baremetal -----------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "src/stdio/ungetc.h"
-
-#include "src/__support/common.h"
-#include "src/stdio/baremetal/file_internal.h"
-
-namespace LIBC_NAMESPACE_DECL {
-
-LLVM_LIBC_FUNCTION(int, ungetc, (int c, ::FILE *stream)) {
- return ungetc_internal(c, stream);
-}
-
-} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/vfscanf_internal.h b/libc/src/stdio/baremetal/vfscanf_internal.h
index 41df455f36e7a..fc90dc3bc044f 100644
--- a/libc/src/stdio/baremetal/vfscanf_internal.h
+++ b/libc/src/stdio/baremetal/vfscanf_internal.h
@@ -18,7 +18,6 @@
#include "src/__support/common.h"
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include "src/stdio/baremetal/file_internal.h"
#include "src/stdio/scanf_core/reader.h"
#include "src/stdio/scanf_core/scanf_main.h"
@@ -34,12 +33,12 @@ class StreamReader : public scanf_core::Reader<StreamReader> {
LIBC_INLINE char getc() {
char c;
- auto result = read_internal(&c, 1, stream);
+ auto result = __llvm_libc_stdio_read(stream, &c, 1);
if (result != 1)
return '\0';
return c;
}
- LIBC_INLINE void ungetc(int c) { (void)ungetc_internal(c, stream); }
+ LIBC_INLINE void ungetc(int) {}
};
} // namespace internal
More information about the libc-commits
mailing list