[libc] add guard for file pieces of printf

In the printf_core CMake, the file pieces are defined as object
libraries that depend on the File data structure. If these are added
unconditionally they'll try to evaluate that dependancy even when there
is no File available. This patch adds a guard to prevent that error.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D131921
This commit is contained in:
Michael Jones 2022-08-15 14:25:38 -07:00
parent 444b4fda17
commit 438d1f18a5
2 changed files with 19 additions and 13 deletions

View File

@ -31,17 +31,6 @@ add_object_library(
.core_structs
)
add_object_library(
file_writer
SRCS
file_writer.cpp
HDRS
file_writer.h
DEPENDS
libc.src.__support.File.file
.core_structs
)
add_object_library(
writer
SRCS
@ -91,6 +80,23 @@ add_object_library(
libc.src.__support.arg_list
)
if(NOT (TARGET libc.src.__support.File.file))
# Not all platforms have a file implementation. If file is unvailable,
# then we must skip all file based printf sections.
return()
endif()
add_object_library(
file_writer
SRCS
file_writer.cpp
HDRS
file_writer.h
DEPENDS
libc.src.__support.File.file
.core_structs
)
add_object_library(
vfprintf_internal
SRCS

View File

@ -191,7 +191,7 @@ TEST(LlvmLibcPrintfParserTest, EvalOneArgWithShortLengthModifier) {
TEST(LlvmLibcPrintfParserTest, EvalOneArgWithLongLengthModifier) {
__llvm_libc::printf_core::FormatSection format_arr[10];
const char *str = "%lld";
int arg1 = 12345;
long long arg1 = 12345;
evaluate(format_arr, str, arg1);
__llvm_libc::printf_core::FormatSection expected;
@ -208,7 +208,7 @@ TEST(LlvmLibcPrintfParserTest, EvalOneArgWithLongLengthModifier) {
TEST(LlvmLibcPrintfParserTest, EvalOneArgWithAllOptions) {
__llvm_libc::printf_core::FormatSection format_arr[10];
const char *str = "% -056.78jd";
int arg1 = 12345;
intmax_t arg1 = 12345;
evaluate(format_arr, str, arg1);
__llvm_libc::printf_core::FormatSection expected;