Skip to content

Commit e2058c0

Browse files
[libc][bazel] Add (v)asprintf targets and tests
Add bazel targets and tests for asprintf and vasprintf. Also clean up a few things I noticed in the process.
1 parent 0ab2df2 commit e2058c0

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

libc/src/stdio/printf_core/vasprintf_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "hdr/func/malloc.h"
1111
#include "hdr/func/realloc.h"
1212
#include "src/__support/arg_list.h"
13-
#include "src/stdio/printf.h"
1413
#include "src/stdio/printf_core/core_structs.h"
1514
#include "src/stdio/printf_core/printf_main.h"
1615
#include "src/stdio/printf_core/writer.h"

libc/test/src/stdio/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ add_libc_test(
270270
libc.src.stdio.vasprintf
271271
libc.src.string.memset
272272
libc.include.stdlib
273-
libc.src.stdio.sprintf
274273
)
275274

276275
if(LLVM_LIBC_FULL_BUILD)

libc/test/src/stdio/asprintf_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ TEST(LlvmLibcASPrintfTest, LargeStringNoConv) {
7676
TEST(LlvmLibcASPrintfTest, ManyReAlloc) {
7777
char *buff = nullptr;
7878
char long_str[1001];
79+
//TODO: simplify test to match with vasprintf_test
7980
auto expected_num_chars =
8081
LIBC_NAMESPACE::sprintf(long_str, "%200s%200s%200s", "a", "b", "c");
8182
long_str[expected_num_chars] = '\0';

libc/test/src/stdio/vasprintf_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "src/stdio/sprintf.h"
109
#include "src/stdio/vasprintf.h"
1110
#include "src/string/memset.h"
1211
#include "test/UnitTest/Test.h"

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6113,6 +6113,31 @@ libc_support_library(
61136113
],
61146114
)
61156115

6116+
libc_support_library(
6117+
name = "vasprintf_internal",
6118+
hdrs = ["src/stdio/printf_core/vasprintf_internal.h"],
6119+
deps = [
6120+
":__support_arg_list",
6121+
":__support_macros_attributes",
6122+
":func_free",
6123+
":func_malloc",
6124+
":func_realloc",
6125+
":printf_main",
6126+
":printf_writer",
6127+
":types_FILE",
6128+
],
6129+
)
6130+
6131+
libc_function(
6132+
name = "asprintf",
6133+
srcs = ["src/stdio/asprintf.cpp"],
6134+
hdrs = ["src/stdio/asprintf.h"],
6135+
deps = [
6136+
":__support_arg_list",
6137+
":vasprintf_internal",
6138+
],
6139+
)
6140+
61166141
libc_function(
61176142
name = "sprintf",
61186143
srcs = ["src/stdio/sprintf.cpp"],
@@ -6164,6 +6189,16 @@ libc_function(
61646189
],
61656190
)
61666191

6192+
libc_function(
6193+
name = "vasprintf",
6194+
srcs = ["src/stdio/vasprintf.cpp"],
6195+
hdrs = ["src/stdio/vasprintf.h"],
6196+
deps = [
6197+
":__support_arg_list",
6198+
":vasprintf_internal",
6199+
],
6200+
)
6201+
61676202
libc_function(
61686203
name = "vsprintf",
61696204
srcs = ["src/stdio/vsprintf.cpp"],

utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ libc_test(
4747
],
4848
)
4949

50+
libc_test(
51+
name = "asprintf_test",
52+
srcs = ["asprintf_test.cpp"],
53+
deps = [
54+
"//libc:asprintf",
55+
"//libc:memset",
56+
"//libc:sprintf",
57+
],
58+
)
59+
5060
libc_test(
5161
name = "sprintf_test",
5262
srcs = ["sprintf_test.cpp"],
@@ -81,6 +91,15 @@ libc_test(
8191
],
8292
)
8393

94+
libc_test(
95+
name = "vasprintf_test",
96+
srcs = ["vasprintf_test.cpp"],
97+
deps = [
98+
"//libc:memset",
99+
"//libc:vasprintf",
100+
],
101+
)
102+
84103
libc_test(
85104
name = "vsprintf_test",
86105
srcs = ["vsprintf_test.cpp"],

0 commit comments

Comments
 (0)