[llvm-branch-commits] [libc] [libc] Modular printf option (float only) (PR #147426)
Alexey Samsonov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Dec 1 16:56:16 PST 2025
================
@@ -0,0 +1,55 @@
+//===-- Implementation of printf_modular 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/__support/OSUtil/io.h"
+#include "src/__support/arg_list.h"
+#include "src/__support/macros/config.h"
+#include "src/stdio/printf.h"
+#include "src/stdio/printf_core/core_structs.h"
+#include "src/stdio/printf_core/printf_main.h"
+#include "src/stdio/printf_core/writer.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace {
+
+LIBC_INLINE int stdout_write_hook(cpp::string_view new_str, void *) {
+ write_to_stdout(new_str);
+ return printf_core::WRITE_OK;
+}
+
+} // namespace
+
+LLVM_LIBC_FUNCTION(int, __printf_modular,
+ (const char *__restrict format, ...)) {
+ va_list vlist;
+ va_start(vlist, format);
+ internal::ArgList args(vlist); // This holder class allows for easier copying
+ // and pointer semantics, as well as handling
+ // destruction automatically.
+ va_end(vlist);
+ static constexpr size_t BUFF_SIZE = 1024;
+ char buffer[BUFF_SIZE];
+
+ printf_core::WriteBuffer<printf_core::WriteMode::FLUSH_TO_STREAM> wb(
----------------
vonosmas wrote:
I will just add as a drive-by comment, that it's a tricky bug lurking here - this should be
`printf_core::Mode<printf_core::WriteMode:: FLUSH_TO_STREAM >::value`. Needless to say, it's
easy to miss and is confusing. PR #169089 should fix it, if it can go in first.
https://github.com/llvm/llvm-project/pull/147426
More information about the llvm-branch-commits
mailing list