-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc][bazel] Add (v)asprintf targets and tests #159476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michaelrj-google
merged 2 commits into
llvm:main
from
michaelrj-google:libcAsprintfBazel
Sep 18, 2025
Merged
[libc][bazel] Add (v)asprintf targets and tests #159476
michaelrj-google
merged 2 commits into
llvm:main
from
michaelrj-google:libcAsprintfBazel
Sep 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add bazel targets and tests for asprintf and vasprintf. Also clean up a few things I noticed in the process.
@llvm/pr-subscribers-libc Author: Michael Jones (michaelrj-google) ChangesAdd bazel targets and tests for asprintf and vasprintf. Also clean up a Full diff: https://github.com/llvm/llvm-project/pull/159476.diff 6 Files Affected:
diff --git a/libc/src/stdio/printf_core/vasprintf_internal.h b/libc/src/stdio/printf_core/vasprintf_internal.h
index 9d46617da7751..283d8df2810fb 100644
--- a/libc/src/stdio/printf_core/vasprintf_internal.h
+++ b/libc/src/stdio/printf_core/vasprintf_internal.h
@@ -10,7 +10,6 @@
#include "hdr/func/malloc.h"
#include "hdr/func/realloc.h"
#include "src/__support/arg_list.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"
diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index 4aa8b95880018..eec108bc12ca5 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -270,7 +270,6 @@ add_libc_test(
libc.src.stdio.vasprintf
libc.src.string.memset
libc.include.stdlib
- libc.src.stdio.sprintf
)
if(LLVM_LIBC_FULL_BUILD)
diff --git a/libc/test/src/stdio/asprintf_test.cpp b/libc/test/src/stdio/asprintf_test.cpp
index 9292cebb80e24..f6a478be9d1b6 100644
--- a/libc/test/src/stdio/asprintf_test.cpp
+++ b/libc/test/src/stdio/asprintf_test.cpp
@@ -76,6 +76,7 @@ TEST(LlvmLibcASPrintfTest, LargeStringNoConv) {
TEST(LlvmLibcASPrintfTest, ManyReAlloc) {
char *buff = nullptr;
char long_str[1001];
+ //TODO: simplify test to match with vasprintf_test
auto expected_num_chars =
LIBC_NAMESPACE::sprintf(long_str, "%200s%200s%200s", "a", "b", "c");
long_str[expected_num_chars] = '\0';
diff --git a/libc/test/src/stdio/vasprintf_test.cpp b/libc/test/src/stdio/vasprintf_test.cpp
index 2eb1be3d7a9bf..72d7165aa800a 100644
--- a/libc/test/src/stdio/vasprintf_test.cpp
+++ b/libc/test/src/stdio/vasprintf_test.cpp
@@ -6,7 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#include "src/stdio/sprintf.h"
#include "src/stdio/vasprintf.h"
#include "src/string/memset.h"
#include "test/UnitTest/Test.h"
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index d9b1bb5635aaf..79ea0e181f453 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -6113,6 +6113,31 @@ libc_support_library(
],
)
+libc_support_library(
+ name = "vasprintf_internal",
+ hdrs = ["src/stdio/printf_core/vasprintf_internal.h"],
+ deps = [
+ ":__support_arg_list",
+ ":__support_macros_attributes",
+ ":func_free",
+ ":func_malloc",
+ ":func_realloc",
+ ":printf_main",
+ ":printf_writer",
+ ":types_FILE",
+ ],
+)
+
+libc_function(
+ name = "asprintf",
+ srcs = ["src/stdio/asprintf.cpp"],
+ hdrs = ["src/stdio/asprintf.h"],
+ deps = [
+ ":__support_arg_list",
+ ":vasprintf_internal",
+ ],
+)
+
libc_function(
name = "sprintf",
srcs = ["src/stdio/sprintf.cpp"],
@@ -6164,6 +6189,16 @@ libc_function(
],
)
+libc_function(
+ name = "vasprintf",
+ srcs = ["src/stdio/vasprintf.cpp"],
+ hdrs = ["src/stdio/vasprintf.h"],
+ deps = [
+ ":__support_arg_list",
+ ":vasprintf_internal",
+ ],
+)
+
libc_function(
name = "vsprintf",
srcs = ["src/stdio/vsprintf.cpp"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
index 505b73fd77111..d06fe7bab72e7 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
@@ -47,6 +47,16 @@ libc_test(
],
)
+libc_test(
+ name = "asprintf_test",
+ srcs = ["asprintf_test.cpp"],
+ deps = [
+ "//libc:asprintf",
+ "//libc:memset",
+ "//libc:sprintf",
+ ],
+)
+
libc_test(
name = "sprintf_test",
srcs = ["sprintf_test.cpp"],
@@ -81,6 +91,15 @@ libc_test(
],
)
+libc_test(
+ name = "vasprintf_test",
+ srcs = ["vasprintf_test.cpp"],
+ deps = [
+ "//libc:memset",
+ "//libc:vasprintf",
+ ],
+)
+
libc_test(
name = "vsprintf_test",
srcs = ["vsprintf_test.cpp"],
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
vonosmas
approved these changes
Sep 18, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add bazel targets and tests for asprintf and vasprintf. Also clean up a
few things I noticed in the process.