Skip to content

Commit b7f0bb9

Browse files
[libc][bazel] Add (v)asprintf targets and tests (#159476)
1 parent 6523258 commit b7f0bb9

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
@@ -6328,6 +6328,31 @@ libc_support_library(
63286328
],
63296329
)
63306330

6331+
libc_support_library(
6332+
name = "vasprintf_internal",
6333+
hdrs = ["src/stdio/printf_core/vasprintf_internal.h"],
6334+
deps = [
6335+
":__support_arg_list",
6336+
":__support_macros_attributes",
6337+
":func_free",
6338+
":func_malloc",
6339+
":func_realloc",
6340+
":printf_main",
6341+
":printf_writer",
6342+
":types_FILE",
6343+
],
6344+
)
6345+
6346+
libc_function(
6347+
name = "asprintf",
6348+
srcs = ["src/stdio/asprintf.cpp"],
6349+
hdrs = ["src/stdio/asprintf.h"],
6350+
deps = [
6351+
":__support_arg_list",
6352+
":vasprintf_internal",
6353+
],
6354+
)
6355+
63316356
libc_function(
63326357
name = "sprintf",
63336358
srcs = ["src/stdio/sprintf.cpp"],
@@ -6379,6 +6404,16 @@ libc_function(
63796404
],
63806405
)
63816406

6407+
libc_function(
6408+
name = "vasprintf",
6409+
srcs = ["src/stdio/vasprintf.cpp"],
6410+
hdrs = ["src/stdio/vasprintf.h"],
6411+
deps = [
6412+
":__support_arg_list",
6413+
":vasprintf_internal",
6414+
],
6415+
)
6416+
63826417
libc_function(
63836418
name = "vsprintf",
63846419
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)