Skip to content

Conversation

@Kewen12
Copy link
Contributor

@Kewen12 Kewen12 commented Nov 5, 2025

@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2025

@llvm/pr-subscribers-libc

Author: Kewen Meng (Kewen12)

Changes

Revert d8e5698 and 15b19c7 to unblock bot.

bot: https://lab.llvm.org/buildbot/#/builders/10/builds/16691


Patch is 59.86 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/166498.diff

39 Files Affected:

  • (modified) libc/src/stdio/CMakeLists.txt (-24)
  • (modified) libc/src/stdio/asprintf.cpp (+2-16)
  • (modified) libc/src/stdio/baremetal/CMakeLists.txt (-8)
  • (modified) libc/src/stdio/baremetal/printf.cpp (+4-19)
  • (modified) libc/src/stdio/baremetal/vprintf.cpp (+4-19)
  • (modified) libc/src/stdio/generic/CMakeLists.txt (-4)
  • (modified) libc/src/stdio/generic/fprintf.cpp (+2-15)
  • (modified) libc/src/stdio/generic/printf.cpp (+2-15)
  • (modified) libc/src/stdio/generic/vfprintf.cpp (+2-15)
  • (modified) libc/src/stdio/generic/vprintf.cpp (+2-15)
  • (modified) libc/src/stdio/printf_core/CMakeLists.txt (-25)
  • (modified) libc/src/stdio/printf_core/core_structs.h (+8-11)
  • (removed) libc/src/stdio/printf_core/error_mapper.h (-21)
  • (removed) libc/src/stdio/printf_core/generic/CMakeLists.txt (-8)
  • (removed) libc/src/stdio/printf_core/generic/error_mapper.h (-49)
  • (removed) libc/src/stdio/printf_core/linux/CMakeLists.txt (-8)
  • (removed) libc/src/stdio/printf_core/linux/error_mapper.h (-54)
  • (modified) libc/src/stdio/printf_core/printf_main.h (+4-5)
  • (modified) libc/src/stdio/printf_core/vasprintf_internal.h (+9-11)
  • (modified) libc/src/stdio/printf_core/vfprintf_internal.h (+13-28)
  • (modified) libc/src/stdio/printf_core/write_int_converter.h (+2-2)
  • (modified) libc/src/stdio/printf_core/writer.h (+4-4)
  • (modified) libc/src/stdio/snprintf.cpp (+2-17)
  • (modified) libc/src/stdio/sprintf.cpp (+2-16)
  • (modified) libc/src/stdio/vasprintf.cpp (+1-15)
  • (modified) libc/src/stdio/vsnprintf.cpp (+2-17)
  • (modified) libc/src/stdio/vsprintf.cpp (+2-15)
  • (modified) libc/src/stdlib/CMakeLists.txt (-6)
  • (modified) libc/src/stdlib/strfromd.cpp (+1-10)
  • (modified) libc/src/stdlib/strfromf.cpp (+1-10)
  • (modified) libc/src/stdlib/strfroml.cpp (+1-10)
  • (modified) libc/src/time/strftime_core/strftime_main.h (+1-2)
  • (modified) libc/test/src/stdio/CMakeLists.txt (-2)
  • (modified) libc/test/src/stdio/fprintf_test.cpp (-24)
  • (modified) libc/test/src/stdio/printf_core/converter_test.cpp (+15-15)
  • (modified) libc/test/src/stdio/printf_core/writer_test.cpp (+16-16)
  • (modified) libc/test/src/stdio/snprintf_test.cpp (-15)
  • (modified) libc/test/src/stdio/vfprintf_test.cpp (-5)
  • (modified) libc/test/src/stdlib/StrfromTest.h (+2-17)
diff --git a/libc/src/stdio/CMakeLists.txt b/libc/src/stdio/CMakeLists.txt
index c75c8b11be2b5..b0a6ef1e291b5 100644
--- a/libc/src/stdio/CMakeLists.txt
+++ b/libc/src/stdio/CMakeLists.txt
@@ -125,10 +125,6 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -140,10 +136,6 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -154,10 +146,6 @@ add_entrypoint_object(
     asprintf.h
   DEPENDS
     libc.src.stdio.printf_core.vasprintf_internal
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -169,10 +157,6 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -184,10 +168,6 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -198,10 +178,6 @@ add_entrypoint_object(
     vasprintf.h
   DEPENDS
     libc.src.stdio.printf_core.vasprintf_internal
-    libc.src.stdio.printf_core.core_structs
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_subdirectory(printf_core)
diff --git a/libc/src/stdio/asprintf.cpp b/libc/src/stdio/asprintf.cpp
index 0991dfca6a059..f8cfb74ce48ea 100644
--- a/libc/src/stdio/asprintf.cpp
+++ b/libc/src/stdio/asprintf.cpp
@@ -7,12 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/stdio/asprintf.h"
-#include "src/__support/CPP/limits.h"
 #include "src/__support/arg_list.h"
-#include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/vasprintf_internal.h"
 
 namespace LIBC_NAMESPACE_DECL {
@@ -26,18 +22,8 @@ LLVM_LIBC_FUNCTION(int, asprintf,
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
   va_end(vlist);
-  auto ret_val = printf_core::vasprintf_internal(buffer, format, args);
-  if (!ret_val.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(ret_val.error());
-    return -1;
-  }
-  if (ret_val.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(ret_val.value());
+  int ret = printf_core::vasprintf_internal(buffer, format, args);
+  return ret;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/CMakeLists.txt b/libc/src/stdio/baremetal/CMakeLists.txt
index bfeff0e2b5880..548938f885c94 100644
--- a/libc/src/stdio/baremetal/CMakeLists.txt
+++ b/libc/src/stdio/baremetal/CMakeLists.txt
@@ -29,12 +29,8 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.stdio.printf_core.core_structs
     libc.src.__support.arg_list
     libc.src.__support.OSUtil.osutil
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
@@ -91,12 +87,8 @@ add_entrypoint_object(
   DEPENDS
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
-    libc.src.stdio.printf_core.error_mapper
-    libc.src.stdio.printf_core.core_structs
     libc.src.__support.arg_list
     libc.src.__support.OSUtil.osutil
-    libc.src.__support.libc_errno
-    libc.src.__support.CPP.limits
 )
 
 add_entrypoint_object(
diff --git a/libc/src/stdio/baremetal/printf.cpp b/libc/src/stdio/baremetal/printf.cpp
index 5a9b19ff20471..7253c6549a4e4 100644
--- a/libc/src/stdio/baremetal/printf.cpp
+++ b/libc/src/stdio/baremetal/printf.cpp
@@ -7,13 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/stdio/printf.h"
-#include "src/__support/CPP/limits.h"
 #include "src/__support/OSUtil/io.h"
 #include "src/__support/arg_list.h"
-#include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
 #include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
 
@@ -45,25 +42,13 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
       buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
   printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
 
-  auto retval = printf_core::printf_main(&writer, format, args);
-  if (!retval.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(retval.error());
-    return -1;
-  }
+  int retval = printf_core::printf_main(&writer, format, args);
 
   int flushval = wb.overflow_write("");
-  if (flushval != printf_core::WRITE_OK) {
-    libc_errno = printf_core::internal_error_to_errno(-flushval);
-    return -1;
-  }
+  if (flushval != printf_core::WRITE_OK)
+    retval = flushval;
 
-  if (retval.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(retval.value());
+  return retval;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/baremetal/vprintf.cpp b/libc/src/stdio/baremetal/vprintf.cpp
index c172b368d15f3..ab02533f14911 100644
--- a/libc/src/stdio/baremetal/vprintf.cpp
+++ b/libc/src/stdio/baremetal/vprintf.cpp
@@ -7,13 +7,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/stdio/vprintf.h"
-#include "src/__support/CPP/limits.h"
 #include "src/__support/OSUtil/io.h"
 #include "src/__support/arg_list.h"
-#include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
 #include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/printf_main.h"
 #include "src/stdio/printf_core/writer.h"
 
@@ -43,25 +40,13 @@ LLVM_LIBC_FUNCTION(int, vprintf,
       buffer, BUFF_SIZE, &stdout_write_hook, nullptr);
   printf_core::Writer<printf_core::WriteMode::FLUSH_TO_STREAM> writer(wb);
 
-  auto retval = printf_core::printf_main(&writer, format, args);
-  if (!retval.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(retval.error());
-    return -1;
-  }
+  int retval = printf_core::printf_main(&writer, format, args);
 
   int flushval = wb.overflow_write("");
-  if (flushval != printf_core::WRITE_OK) {
-    libc_errno = printf_core::internal_error_to_errno(-flushval);
-    return -1;
-  }
+  if (flushval != printf_core::WRITE_OK)
+    retval = flushval;
 
-  if (retval.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(retval.value());
+  return retval;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/generic/CMakeLists.txt b/libc/src/stdio/generic/CMakeLists.txt
index 71055edea3d9e..6361822b61999 100644
--- a/libc/src/stdio/generic/CMakeLists.txt
+++ b/libc/src/stdio/generic/CMakeLists.txt
@@ -393,11 +393,7 @@ add_generic_entrypoint_object(
 list(APPEND fprintf_deps
       libc.hdr.types.FILE
       libc.src.__support.arg_list
-      libc.src.__support.CPP.limits
-      libc.src.__support.libc_errno
       libc.src.stdio.printf_core.vfprintf_internal
-      libc.src.stdio.printf_core.core_structs
-      libc.src.stdio.printf_core.error_mapper
 )
 
 if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/src/stdio/generic/fprintf.cpp b/libc/src/stdio/generic/fprintf.cpp
index b2033901557a0..087aeadfc52c5 100644
--- a/libc/src/stdio/generic/fprintf.cpp
+++ b/libc/src/stdio/generic/fprintf.cpp
@@ -8,12 +8,9 @@
 
 #include "src/stdio/fprintf.h"
 
-#include "src/__support/CPP/limits.h"
 #include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
 #include "src/__support/macros/config.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/vfprintf_internal.h"
 
 #include "hdr/types/FILE.h"
@@ -30,18 +27,8 @@ LLVM_LIBC_FUNCTION(int, fprintf,
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
   va_end(vlist);
-  auto ret_val = printf_core::vfprintf_internal(stream, format, args);
-  if (!ret_val.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(ret_val.error());
-    return -1;
-  }
-  if (ret_val.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(ret_val.value());
+  int ret_val = printf_core::vfprintf_internal(stream, format, args);
+  return ret_val;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/generic/printf.cpp b/libc/src/stdio/generic/printf.cpp
index 8d159d5c70870..bb7c7c86f843f 100644
--- a/libc/src/stdio/generic/printf.cpp
+++ b/libc/src/stdio/generic/printf.cpp
@@ -8,12 +8,9 @@
 
 #include "src/stdio/printf.h"
 
-#include "src/__support/CPP/limits.h"
 #include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
 #include "src/__support/macros/config.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/vfprintf_internal.h"
 
 #include "hdr/types/FILE.h"
@@ -34,19 +31,9 @@ LLVM_LIBC_FUNCTION(int, printf, (const char *__restrict format, ...)) {
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
   va_end(vlist);
-  auto ret_val = printf_core::vfprintf_internal(
+  int ret_val = printf_core::vfprintf_internal(
       reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
-  if (!ret_val.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(ret_val.error());
-    return -1;
-  }
-  if (ret_val.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(ret_val.value());
+  return ret_val;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/generic/vfprintf.cpp b/libc/src/stdio/generic/vfprintf.cpp
index a26f082ed9347..01f4265f118a6 100644
--- a/libc/src/stdio/generic/vfprintf.cpp
+++ b/libc/src/stdio/generic/vfprintf.cpp
@@ -8,12 +8,9 @@
 
 #include "src/stdio/vfprintf.h"
 
-#include "src/__support/CPP/limits.h"
 #include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
 #include "src/__support/macros/config.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/vfprintf_internal.h"
 
 #include "hdr/types/FILE.h"
@@ -27,18 +24,8 @@ LLVM_LIBC_FUNCTION(int, vfprintf,
   internal::ArgList args(vlist); // This holder class allows for easier copying
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
-  auto ret_val = printf_core::vfprintf_internal(stream, format, args);
-  if (!ret_val.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(ret_val.error());
-    return -1;
-  }
-  if (ret_val.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(ret_val.value());
+  int ret_val = printf_core::vfprintf_internal(stream, format, args);
+  return ret_val;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/generic/vprintf.cpp b/libc/src/stdio/generic/vprintf.cpp
index ae2160219f2bb..08d71515646ed 100644
--- a/libc/src/stdio/generic/vprintf.cpp
+++ b/libc/src/stdio/generic/vprintf.cpp
@@ -8,12 +8,9 @@
 
 #include "src/stdio/vprintf.h"
 
-#include "src/__support/CPP/limits.h"
 #include "src/__support/File/file.h"
 #include "src/__support/arg_list.h"
 #include "src/__support/macros/config.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
 #include "src/stdio/printf_core/vfprintf_internal.h"
 
 #include "hdr/types/FILE.h"
@@ -32,19 +29,9 @@ LLVM_LIBC_FUNCTION(int, vprintf,
   internal::ArgList args(vlist); // This holder class allows for easier copying
                                  // and pointer semantics, as well as handling
                                  // destruction automatically.
-  auto ret_val = printf_core::vfprintf_internal(
+  int ret_val = printf_core::vfprintf_internal(
       reinterpret_cast<::FILE *>(PRINTF_STDOUT), format, args);
-  if (!ret_val.has_value()) {
-    libc_errno = printf_core::internal_error_to_errno(ret_val.error());
-    return -1;
-  }
-  if (ret_val.value() > static_cast<size_t>(cpp::numeric_limits<int>::max())) {
-    libc_errno =
-        printf_core::internal_error_to_errno(-printf_core::OVERFLOW_ERROR);
-    return -1;
-  }
-
-  return static_cast<int>(ret_val.value());
+  return ret_val;
 }
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 624129b2b36e7..ee66145e60156 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -32,17 +32,6 @@ if(printf_config_copts)
   list(PREPEND printf_config_copts "COMPILE_OPTIONS")
 endif()
 
-if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
-  add_subdirectory(${LIBC_TARGET_OS})
-else()
-  add_subdirectory(generic)
-endif()
-
-set(target_error_mapper libc.src.stdio.printf_core.${LIBC_TARGET_OS}.error_mapper)
-if(NOT TARGET ${target_error_mapper})
-    set(target_error_mapper libc.src.stdio.printf_core.generic.error_mapper)
-endif()
-
 add_header_library(
   printf_config
   HDRS
@@ -58,7 +47,6 @@ add_header_library(
     libc.include.inttypes
     libc.src.__support.CPP.string_view
     libc.src.__support.FPUtil.fp_bits
-    libc.hdr.errno_macros
 )
 
 add_header_library(
@@ -137,7 +125,6 @@ add_header_library(
     .writer
     .core_structs
     libc.src.__support.arg_list
-    libc.src.__support.error_or
 )
 
 add_header_library(
@@ -149,20 +136,10 @@ add_header_library(
     libc.hdr.func.free
     libc.hdr.func.realloc
     libc.src.__support.arg_list
-    libc.src.__support.error_or
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
 )
 
-add_header_library(
-  error_mapper
-  HDRS
-    error_mapper.h
-  DEPENDS
-    ${target_error_mapper}
-    libc.src.__support.macros.properties.architectures
-)
-
 if(NOT (TARGET libc.src.__support.File.file) AND LLVM_LIBC_FULL_BUILD)
   # Not all platforms have a file implementation. If file is unvailable, and a
   # full build is requested, then we must skip all file based printf sections.
@@ -175,10 +152,8 @@ add_header_library(
     vfprintf_internal.h
   DEPENDS
     libc.src.__support.File.file
-    libc.src.__support.error_or
     libc.src.__support.arg_list
     libc.src.stdio.printf_core.printf_main
     libc.src.stdio.printf_core.writer
   ${use_system_file}
 )
-
diff --git a/libc/src/stdio/printf_core/core_structs.h b/libc/src/stdio/printf_core/core_structs.h
index 0d41f2244d8da..e27f77b6b594a 100644
--- a/libc/src/stdio/printf_core/core_structs.h
+++ b/libc/src/stdio/printf_core/core_structs.h
@@ -132,17 +132,14 @@ template <typename T> LIBC_INLINE constexpr TypeDesc type_desc_from_type() {
 
 // This is the value to be returned by conversions when no error has occurred.
 constexpr int WRITE_OK = 0;
-// These are the error return values used by the printf engine when an
-// error has occurred. They are all large negative, distinct values starting
-// from -1000 to not overlap with system errors.
-constexpr int FILE_WRITE_ERROR = -1001;
-constexpr int FILE_STATUS_ERROR = -1002;
-constexpr int NULLPTR_WRITE_ERROR = -1003;
-constexpr int INT_CONVERSION_ERROR = -1004;
-constexpr int FIXED_POINT_CONVERSION_ERROR = -1005;
-constexpr int ALLOCATION_ERROR = -1006;
-constexpr int OVERFLOW_ERROR = -1007;
-
+// These are the printf return values for when an error has occurred. They are
+// all negative, and should be distinct.
+constexpr int FILE_WRITE_ERROR = -1;
+constexpr int FILE_STATUS_ERROR = -2;
+constexpr int NULLPTR_WRITE_ERROR = -3;
+constexpr int INT_CONVERSION_ERROR = -4;
+constexpr int FIXED_POINT_CONVERSION_ERROR = -5;
+constexpr int ALLOCATION_ERROR = -6;
 } // namespace printf_core
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/stdio/printf_core/error_mapper.h b/libc/src/stdio/printf_core/error_mapper.h
deleted file mode 100644
index 23030930133a1..0000000000000
--- a/libc/src/stdio/printf_core/error_mapper.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//===-- Error mapper for printf ---------------------------------*- 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_ERROR_MAPPER_H
-#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_ERROR_MAPPER_H
-
-#include "src/__support/macros/properties/architectures.h"
-
-// Maps internal errors to the available errnos on the platform.
-#if defined(__linux__)
-#include "linux/error_mapper.h"
-#else
-#include "generic/error_mapper.h"
-#endif
-
-#endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_ERROR_MAPPER_H
diff --git a/libc/src/stdio/printf_core/generic/CMakeLists.txt b/libc/src/stdio/printf_core/generic/CMakeLists.txt
deleted file mode 100644
index 2f0143d992e31..0000000000000
--- a/libc/src/stdio/printf_core/generic/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-add_header_library(
-  error_mapper
-  HDRS
-    error_mapper.h
-  DEPENDS
-    libc.src.stdio.printf_core.core_structs
-    libc.hdr.errno_macros
-)
diff --git a/libc/src/stdio/printf_core/generic/error_mapper.h b/libc/src/stdio/printf_core/generic/error_mapper.h
deleted file mode 100644
index d8cdd2cc2dbaa..0000000000000
--- a/libc/src/stdio/printf_core/generic/error_mapper.h
+++ /dev/null
@@ -1,49 +0,0 @@
-//===-- Generic implementation of error mapper ------------------*- 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_GENERIC_ERROR_MAPPER_H
-#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_GENERIC_ERROR_MAPPER_H
-
-#include "hdr/errno_macros.h"
-#include "src/stdio/printf_core/core_structs.h"
-#include "src/stdio/printf_core/error_mapper.h"
-
-namespace LIBC_NAMESPACE_DECL {
-namespace printf_core {
-
-LIBC_INLINE static int internal_error_to_errno(int internal_error) {
-  // System error occured, return error as is.
-  if (internal_error < 1001 && internal_error > 0) {
-    return internal_error;
-  }
-
-  // Map...
[truncated]

@Kewen12 Kewen12 merged commit c5aaee0 into llvm:main Nov 5, 2025
20 of 21 checks passed
@Kewen12 Kewen12 deleted the revert branch November 5, 2025 03:44
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.

2 participants