[libc-commits] [libc] 438d1f1 - [libc] add guard for file pieces of printf

Michael Jones via libc-commits libc-commits at lists.llvm.org
Mon Aug 15 15:43:29 PDT 2022


Author: Michael Jones
Date: 2022-08-15T15:43:24-07:00
New Revision: 438d1f18a5b79326eef8ea5455ae1553d2c4d411

URL: https://github.com/llvm/llvm-project/commit/438d1f18a5b79326eef8ea5455ae1553d2c4d411
DIFF: https://github.com/llvm/llvm-project/commit/438d1f18a5b79326eef8ea5455ae1553d2c4d411.diff

LOG: [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

Added: 
    

Modified: 
    libc/src/stdio/printf_core/CMakeLists.txt
    libc/test/src/stdio/printf_core/parser_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 5ab0bc6d29f62..9c7a9fbe9c5ab 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -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

diff  --git a/libc/test/src/stdio/printf_core/parser_test.cpp b/libc/test/src/stdio/printf_core/parser_test.cpp
index c6ec04a0e7d22..c9cc1c2f3c58b 100644
--- a/libc/test/src/stdio/printf_core/parser_test.cpp
+++ b/libc/test/src/stdio/printf_core/parser_test.cpp
@@ -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;


        


More information about the libc-commits mailing list