From 6cf4d4d85ba1cb9416b1d0128199729dc7086b64 Mon Sep 17 00:00:00 2001 From: lntue Date: Tue, 1 Oct 2024 11:48:07 -0400 Subject: [PATCH] [libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067) https://github.com/llvm/llvm-project/issues/60481 --- libc/hdr/CMakeLists.txt | 4 ++ libc/hdr/stdio_macros.h | 2 +- libc/hdr/stdio_overlay.h | 47 +++++++++++++ libc/hdr/types/CMakeLists.txt | 6 ++ libc/hdr/types/FILE.h | 2 +- libc/hdr/types/cookie_io_functions_t.h | 2 +- libc/hdr/types/off_t.h | 2 +- libc/include/llvm-libc-macros/stdio-macros.h | 36 ++++++++++ libc/src/__support/File/linux/CMakeLists.txt | 1 - libc/src/stdio/asprintf.h | 2 - libc/src/stdio/gpu/CMakeLists.txt | 66 +++++++++---------- libc/src/stdio/gpu/file.h | 3 +- libc/src/stdio/gpu/fprintf.cpp | 3 +- libc/src/stdio/gpu/getchar.cpp | 5 +- libc/src/stdio/gpu/printf.cpp | 2 +- libc/src/stdio/gpu/putchar.cpp | 5 +- libc/src/stdio/gpu/puts.cpp | 5 +- libc/src/stdio/gpu/vfprintf.cpp | 3 +- libc/src/stdio/gpu/vfprintf_utils.h | 3 +- libc/src/stdio/gpu/vprintf.cpp | 2 - libc/src/stdio/linux/CMakeLists.txt | 2 - libc/src/stdio/printf_core/CMakeLists.txt | 1 - libc/src/stdio/vsscanf.cpp | 2 +- libc/test/src/__support/File/file_test.cpp | 1 - .../src/__support/File/platform_file_test.cpp | 2 +- libc/test/src/fcntl/fcntl_test.cpp | 2 +- libc/test/src/math/smoke/RIntTest.h | 1 - libc/test/src/stdio/fgetc_test.cpp | 2 +- libc/test/src/stdio/fgetc_unlocked_test.cpp | 2 +- libc/test/src/stdio/fgets_test.cpp | 1 - libc/test/src/stdio/fileop_test.cpp | 2 +- libc/test/src/stdio/fopencookie_test.cpp | 2 +- libc/test/src/stdio/fprintf_test.cpp | 2 - libc/test/src/stdio/fscanf_test.cpp | 2 - libc/test/src/stdio/ftell_test.cpp | 3 +- libc/test/src/stdio/putc_test.cpp | 2 - libc/test/src/stdio/setbuf_test.cpp | 3 +- libc/test/src/stdio/setvbuf_test.cpp | 2 +- libc/test/src/stdio/sscanf_test.cpp | 8 +-- libc/test/src/stdio/ungetc_test.cpp | 6 +- libc/test/src/stdio/unlocked_fileop_test.cpp | 1 - libc/test/src/stdio/vfprintf_test.cpp | 2 - libc/test/src/stdio/vfscanf_test.cpp | 2 - libc/test/src/unistd/getopt_test.cpp | 2 - libc/test/src/wchar/wctob_test.cpp | 4 +- 45 files changed, 154 insertions(+), 106 deletions(-) create mode 100644 libc/hdr/stdio_overlay.h diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt index 5e3122f59de9ed6..13dc892978bb87a 100644 --- a/libc/hdr/CMakeLists.txt +++ b/libc/hdr/CMakeLists.txt @@ -78,10 +78,14 @@ add_proxy_header_library( libc.include.signal ) +add_header_library(stdio_overlay HDRS stdio_overlay.h) + add_proxy_header_library( stdio_macros HDRS stdio_macros.h + DEPENDS + .stdio_overlay FULL_BUILD_DEPENDS libc.include.stdio libc.include.llvm-libc-macros.stdio_macros diff --git a/libc/hdr/stdio_macros.h b/libc/hdr/stdio_macros.h index a212846dd8f4111..a4d6a972ec9ac98 100644 --- a/libc/hdr/stdio_macros.h +++ b/libc/hdr/stdio_macros.h @@ -16,7 +16,7 @@ #else // Overlay mode -#include +#include "stdio_overlay.h" #endif // LLVM_LIBC_FULL_BUILD diff --git a/libc/hdr/stdio_overlay.h b/libc/hdr/stdio_overlay.h new file mode 100644 index 000000000000000..cec55abfde7bf61 --- /dev/null +++ b/libc/hdr/stdio_overlay.h @@ -0,0 +1,47 @@ +//===-- Including stdio.h in overlay mode ---------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_HDR_STDIO_OVERLAY_H +#define LLVM_LIBC_HDR_STDIO_OVERLAY_H + +#ifdef LIBC_FULL_BUILD +#error "This header should only be included in overlay mode" +#endif + +// Overlay mode + +// glibc header might provide extern inline definitions for few +// functions, causing external alias errors. They are guarded by +// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES` +// macro by defining `__NO_INLINE__` before including . +// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled +// with `_FORTIFY_SOURCE`. + +#ifdef _FORTIFY_SOURCE +#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE +#undef _FORTIFY_SOURCE +#endif + +#ifndef __NO_INLINE__ +#define __NO_INLINE__ 1 +#define LIBC_SET_NO_INLINE +#endif + +#include + +#ifdef LIBC_OLD_FORTIFY_SOURCE +#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE +#undef LIBC_OLD_FORTIFY_SOURCE +#endif + +#ifdef LIBC_SET_NO_INLINE +#undef __NO_INLINE__ +#undef LIBC_SET_NO_INLINE +#endif + +#endif // LLVM_LIBC_HDR_STDIO_OVERLAY_H diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt index b4de39621416f73..fab5245816bbe19 100644 --- a/libc/hdr/types/CMakeLists.txt +++ b/libc/hdr/types/CMakeLists.txt @@ -140,6 +140,8 @@ add_proxy_header_library( FILE HDRS FILE.h + DEPENDS + libc.hdr.stdio_overlay FULL_BUILD_DEPENDS libc.include.llvm-libc-types.FILE libc.include.stdio @@ -149,6 +151,8 @@ add_proxy_header_library( off_t HDRS off_t.h + DEPENDS + libc.hdr.stdio_overlay FULL_BUILD_DEPENDS libc.include.llvm-libc-types.off_t libc.include.stdio @@ -158,6 +162,8 @@ add_proxy_header_library( cookie_io_functions_t HDRS cookie_io_functions_t.h + DEPENDS + libc.hdr.stdio_overlay FULL_BUILD_DEPENDS libc.include.llvm-libc-types.cookie_io_functions_t libc.include.stdio diff --git a/libc/hdr/types/FILE.h b/libc/hdr/types/FILE.h index 60e95f07e37f914..ecb52b7102cb0ed 100644 --- a/libc/hdr/types/FILE.h +++ b/libc/hdr/types/FILE.h @@ -15,7 +15,7 @@ #else // Overlay mode -#include +#include "hdr/stdio_overlay.h" #endif // LLVM_LIBC_FULL_BUILD diff --git a/libc/hdr/types/cookie_io_functions_t.h b/libc/hdr/types/cookie_io_functions_t.h index d8fe7731a84bda7..7323a05001c4077 100644 --- a/libc/hdr/types/cookie_io_functions_t.h +++ b/libc/hdr/types/cookie_io_functions_t.h @@ -15,7 +15,7 @@ #else // Overlay mode -#include +#include "hdr/stdio_overlay.h" #endif // LLVM_LIBC_FULL_BUILD diff --git a/libc/hdr/types/off_t.h b/libc/hdr/types/off_t.h index abc3aa659365f7a..52337e5b63e2dcb 100644 --- a/libc/hdr/types/off_t.h +++ b/libc/hdr/types/off_t.h @@ -15,7 +15,7 @@ #else // Overlay mode -#include +#include "hdr/stdio_overlay.h" #endif // LLVM_LIBC_FULL_BUILD diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h index 69fb71ad3f65159..96f0e6933ade688 100644 --- a/libc/include/llvm-libc-macros/stdio-macros.h +++ b/libc/include/llvm-libc-macros/stdio-macros.h @@ -9,6 +9,30 @@ #ifndef LLVM_LIBC_MACROS_STDIO_MACROS_H #define LLVM_LIBC_MACROS_STDIO_MACROS_H +#include "../llvm-libc-types/FILE.h" + +#ifdef __cplusplus +extern "C" FILE *stdin; +extern "C" FILE *stdout; +extern "C" FILE *stderr; +#else +extern FILE *stdin; +extern FILE *stdout; +extern FILE *stderr; +#endif + +#ifndef stdin +#define stdin stdin +#endif + +#ifndef stdout +#define stdout stdout +#endif + +#ifndef stderr +#define stderr stderr +#endif + #ifndef EOF #define EOF (-1) #endif @@ -19,4 +43,16 @@ #define _IOLBF 1 #define _IOFBF 0 +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + #endif // LLVM_LIBC_MACROS_STDIO_MACROS_H diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt index 5556b812596f834..5abbf11b3671cd2 100644 --- a/libc/src/__support/File/linux/CMakeLists.txt +++ b/libc/src/__support/File/linux/CMakeLists.txt @@ -8,7 +8,6 @@ add_object_library( lseekImpl.h DEPENDS libc.include.fcntl - libc.include.stdio libc.include.sys_syscall libc.include.sys_stat libc.src.__support.CPP.new diff --git a/libc/src/stdio/asprintf.h b/libc/src/stdio/asprintf.h index fd2b908db171df9..0c0d5a350829e77 100644 --- a/libc/src/stdio/asprintf.h +++ b/libc/src/stdio/asprintf.h @@ -10,8 +10,6 @@ #define LLVM_LIBC_SRC_STDIO_ASPRINTF_H #include "src/__support/macros/config.h" -#include -#include namespace LIBC_NAMESPACE { diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt index 9cac42ed71fb767..c4ad333e251639d 100644 --- a/libc/src/stdio/gpu/CMakeLists.txt +++ b/libc/src/stdio/gpu/CMakeLists.txt @@ -1,9 +1,40 @@ +add_entrypoint_object( + stdin + SRCS + stdin.cpp + HDRS + ../stdin.h + DEPENDS + libc.hdr.types.FILE +) + +add_entrypoint_object( + stdout + SRCS + stdout.cpp + HDRS + ../stdout.h + DEPENDS + libc.hdr.types.FILE +) + +add_entrypoint_object( + stderr + SRCS + stderr.cpp + HDRS + ../stderr.h + DEPENDS + libc.hdr.types.FILE +) + add_header_library( gpu_file HDRS file.h DEPENDS libc.hdr.types.FILE + libc.hdr.stdio_macros libc.src.__support.RPC.rpc_client libc.src.__support.common .stdin @@ -123,7 +154,6 @@ add_entrypoint_object( ../puts.h DEPENDS libc.hdr.types.FILE - libc.include.stdio # needed for stdin .gpu_file ) @@ -168,7 +198,6 @@ add_entrypoint_object( ../putc.h DEPENDS libc.hdr.types.FILE - libc.include.stdio # needed for stdin .gpu_file ) @@ -180,7 +209,6 @@ add_entrypoint_object( ../putchar.h DEPENDS libc.hdr.types.FILE - libc.include.stdio # needed for stdin .gpu_file ) @@ -203,7 +231,6 @@ add_entrypoint_object( ../getc.h DEPENDS libc.hdr.types.FILE - libc.include.stdio # needed for stdin .gpu_file ) @@ -215,7 +242,6 @@ add_entrypoint_object( ../getchar.h DEPENDS libc.hdr.types.FILE - libc.include.stdio # needed for stdin .gpu_file ) @@ -304,33 +330,3 @@ add_entrypoint_object( libc.hdr.types.FILE .gpu_file ) - -add_entrypoint_object( - stdin - SRCS - stdin.cpp - HDRS - ../stdin.h - DEPENDS - libc.hdr.types.FILE -) - -add_entrypoint_object( - stdout - SRCS - stdout.cpp - HDRS - ../stdout.h - DEPENDS - libc.hdr.types.FILE -) - -add_entrypoint_object( - stderr - SRCS - stderr.cpp - HDRS - ../stderr.h - DEPENDS - libc.hdr.types.FILE -) diff --git a/libc/src/stdio/gpu/file.h b/libc/src/stdio/gpu/file.h index 5de76842d7beabb..0856a3430803ae7 100644 --- a/libc/src/stdio/gpu/file.h +++ b/libc/src/stdio/gpu/file.h @@ -10,10 +10,9 @@ #include "src/__support/macros/config.h" #include "src/string/string_utils.h" +#include "hdr/stdio_macros.h" // For stdin/out/err #include "hdr/types/FILE.h" -#include //needed for stdin/out/err - namespace LIBC_NAMESPACE_DECL { namespace file { diff --git a/libc/src/stdio/gpu/fprintf.cpp b/libc/src/stdio/gpu/fprintf.cpp index 42d6ad008777346..6222589cc4bab96 100644 --- a/libc/src/stdio/gpu/fprintf.cpp +++ b/libc/src/stdio/gpu/fprintf.cpp @@ -8,12 +8,13 @@ #include "src/stdio/fprintf.h" +#include "hdr/types/FILE.h" #include "src/__support/CPP/string_view.h" #include "src/__support/arg_list.h" #include "src/errno/libc_errno.h" #include "src/stdio/gpu/vfprintf_utils.h" -#include +#include namespace LIBC_NAMESPACE { diff --git a/libc/src/stdio/gpu/getchar.cpp b/libc/src/stdio/gpu/getchar.cpp index 048cf23b0d64a52..d99b97b5c5a0082 100644 --- a/libc/src/stdio/gpu/getchar.cpp +++ b/libc/src/stdio/gpu/getchar.cpp @@ -10,10 +10,7 @@ #include "file.h" #include "src/__support/macros/config.h" -#include "hdr/stdio_macros.h" // for EOF. -#include "hdr/types/FILE.h" - -#include //needed for stdin +#include "hdr/stdio_macros.h" // for EOF and stdin. namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/stdio/gpu/printf.cpp b/libc/src/stdio/gpu/printf.cpp index 63af6fffeea73c5..d9903193ef1658b 100644 --- a/libc/src/stdio/gpu/printf.cpp +++ b/libc/src/stdio/gpu/printf.cpp @@ -13,7 +13,7 @@ #include "src/errno/libc_errno.h" #include "src/stdio/gpu/vfprintf_utils.h" -#include +#include namespace LIBC_NAMESPACE { diff --git a/libc/src/stdio/gpu/putchar.cpp b/libc/src/stdio/gpu/putchar.cpp index d03a3fe68daf7a3..c49b02e2f1f10f1 100644 --- a/libc/src/stdio/gpu/putchar.cpp +++ b/libc/src/stdio/gpu/putchar.cpp @@ -10,10 +10,7 @@ #include "file.h" #include "src/__support/macros/config.h" -#include "hdr/stdio_macros.h" // for EOF. -#include "hdr/types/FILE.h" - -#include //needed for stdout +#include "hdr/stdio_macros.h" // for EOF and stdout. namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/stdio/gpu/puts.cpp b/libc/src/stdio/gpu/puts.cpp index af84432d1ef8c7a..20f7a889a378a18 100644 --- a/libc/src/stdio/gpu/puts.cpp +++ b/libc/src/stdio/gpu/puts.cpp @@ -12,10 +12,7 @@ #include "src/errno/libc_errno.h" #include "src/stdio/gpu/file.h" -#include "hdr/stdio_macros.h" // for EOF. -#include "hdr/types/FILE.h" - -#include //needed for stdout +#include "hdr/stdio_macros.h" // for EOF and stdout. namespace LIBC_NAMESPACE_DECL { diff --git a/libc/src/stdio/gpu/vfprintf.cpp b/libc/src/stdio/gpu/vfprintf.cpp index f314f6872ad0e43..961cfa48579e0af 100644 --- a/libc/src/stdio/gpu/vfprintf.cpp +++ b/libc/src/stdio/gpu/vfprintf.cpp @@ -8,13 +8,12 @@ #include "src/stdio/vfprintf.h" +#include "hdr/types/FILE.h" #include "src/__support/CPP/string_view.h" #include "src/__support/arg_list.h" #include "src/errno/libc_errno.h" #include "src/stdio/gpu/vfprintf_utils.h" -#include - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, vfprintf, diff --git a/libc/src/stdio/gpu/vfprintf_utils.h b/libc/src/stdio/gpu/vfprintf_utils.h index f364646fcea58f0..7c012d139ba5dcb 100644 --- a/libc/src/stdio/gpu/vfprintf_utils.h +++ b/libc/src/stdio/gpu/vfprintf_utils.h @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// +#include "hdr/types/FILE.h" #include "src/__support/RPC/rpc_client.h" #include "src/__support/arg_list.h" #include "src/stdio/gpu/file.h" #include "src/string/string_utils.h" -#include - namespace LIBC_NAMESPACE { template diff --git a/libc/src/stdio/gpu/vprintf.cpp b/libc/src/stdio/gpu/vprintf.cpp index 1356aceeb51c52e..2bb74d7f017b594 100644 --- a/libc/src/stdio/gpu/vprintf.cpp +++ b/libc/src/stdio/gpu/vprintf.cpp @@ -13,8 +13,6 @@ #include "src/errno/libc_errno.h" #include "src/stdio/gpu/vfprintf_utils.h" -#include - namespace LIBC_NAMESPACE { LLVM_LIBC_FUNCTION(int, vprintf, diff --git a/libc/src/stdio/linux/CMakeLists.txt b/libc/src/stdio/linux/CMakeLists.txt index fa36732a159be12..d6241e1ca0439d8 100644 --- a/libc/src/stdio/linux/CMakeLists.txt +++ b/libc/src/stdio/linux/CMakeLists.txt @@ -6,7 +6,6 @@ add_entrypoint_object( ../remove.h DEPENDS libc.include.fcntl - libc.include.stdio libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil @@ -32,7 +31,6 @@ add_entrypoint_object( HDRS ../fdopen.h DEPENDS - libc.include.stdio libc.src.__support.File.file libc.src.__support.File.platform_file ) diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt index 1095f01d71f24ed..542327ad5a49a9b 100644 --- a/libc/src/stdio/printf_core/CMakeLists.txt +++ b/libc/src/stdio/printf_core/CMakeLists.txt @@ -141,7 +141,6 @@ add_header_library( HDRS vfprintf_internal.h DEPENDS - libc.include.stdio libc.src.__support.File.file libc.src.__support.arg_list libc.src.stdio.printf_core.printf_main diff --git a/libc/src/stdio/vsscanf.cpp b/libc/src/stdio/vsscanf.cpp index fcf0b88885f17be..f3f56bce64292b5 100644 --- a/libc/src/stdio/vsscanf.cpp +++ b/libc/src/stdio/vsscanf.cpp @@ -8,13 +8,13 @@ #include "src/stdio/vsscanf.h" +#include "hdr/stdio_macros.h" #include "src/__support/CPP/limits.h" #include "src/__support/arg_list.h" #include "src/stdio/scanf_core/reader.h" #include "src/stdio/scanf_core/scanf_main.h" #include -#include namespace LIBC_NAMESPACE_DECL { diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp index 2f68c3faa0ad087..5977ea7c8e0b57e 100644 --- a/libc/test/src/__support/File/file_test.cpp +++ b/libc/test/src/__support/File/file_test.cpp @@ -12,7 +12,6 @@ #include "test/UnitTest/MemoryMatcher.h" #include "test/UnitTest/Test.h" -#include #include using ModeFlags = LIBC_NAMESPACE::File::ModeFlags; diff --git a/libc/test/src/__support/File/platform_file_test.cpp b/libc/test/src/__support/File/platform_file_test.cpp index 8aa07219a6527b2..6b2be2a1493299e 100644 --- a/libc/test/src/__support/File/platform_file_test.cpp +++ b/libc/test/src/__support/File/platform_file_test.cpp @@ -9,7 +9,7 @@ #include "src/__support/File/file.h" #include "test/UnitTest/Test.h" -#include // For SEEK_* macros +#include "hdr/stdio_macros.h" // For SEEK_* macros using File = LIBC_NAMESPACE::File; constexpr char TEXT[] = "Hello, File"; diff --git a/libc/test/src/fcntl/fcntl_test.cpp b/libc/test/src/fcntl/fcntl_test.cpp index ffbb3ec337ed4dd..1a21afe51085b15 100644 --- a/libc/test/src/fcntl/fcntl_test.cpp +++ b/libc/test/src/fcntl/fcntl_test.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "hdr/fcntl_macros.h" +#include "hdr/stdio_macros.h" #include "hdr/types/struct_flock.h" #include "src/errno/libc_errno.h" #include "src/fcntl/fcntl.h" @@ -16,7 +17,6 @@ #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" -#include #include // For S_IRWXU TEST(LlvmLibcFcntlTest, FcntlDupfd) { diff --git a/libc/test/src/math/smoke/RIntTest.h b/libc/test/src/math/smoke/RIntTest.h index 1412c3f27a2d5f3..fb2c89c4980b484 100644 --- a/libc/test/src/math/smoke/RIntTest.h +++ b/libc/test/src/math/smoke/RIntTest.h @@ -17,7 +17,6 @@ #include "hdr/fenv_macros.h" #include "hdr/math_macros.h" -#include static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO, FE_TONEAREST}; diff --git a/libc/test/src/stdio/fgetc_test.cpp b/libc/test/src/stdio/fgetc_test.cpp index 989bb312afadf43..2cc8436bd66f286 100644 --- a/libc/test/src/stdio/fgetc_test.cpp +++ b/libc/test/src/stdio/fgetc_test.cpp @@ -16,8 +16,8 @@ #include "src/stdio/getc.h" #include "test/UnitTest/Test.h" +#include "hdr/stdio_macros.h" #include "src/errno/libc_errno.h" -#include class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test { public: diff --git a/libc/test/src/stdio/fgetc_unlocked_test.cpp b/libc/test/src/stdio/fgetc_unlocked_test.cpp index 48d7a043cad7c3f..46cf12c2c253be9 100644 --- a/libc/test/src/stdio/fgetc_unlocked_test.cpp +++ b/libc/test/src/stdio/fgetc_unlocked_test.cpp @@ -19,8 +19,8 @@ #include "src/stdio/getc_unlocked.h" #include "test/UnitTest/Test.h" +#include "hdr/stdio_macros.h" #include "src/errno/libc_errno.h" -#include class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test { public: diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp index 39337262f1e0089..a8a2c62f07b5ea3 100644 --- a/libc/test/src/stdio/fgets_test.cpp +++ b/libc/test/src/stdio/fgets_test.cpp @@ -15,7 +15,6 @@ #include "test/UnitTest/Test.h" #include "src/errno/libc_errno.h" -#include TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) { constexpr char FILENAME[] = "testdata/fgets.test"; diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp index 0fbe19cf08d8370..98ead6edd38b471 100644 --- a/libc/test/src/stdio/fileop_test.cpp +++ b/libc/test/src/stdio/fileop_test.cpp @@ -20,8 +20,8 @@ #include "test/UnitTest/ErrnoSetterMatcher.h" #include "test/UnitTest/Test.h" +#include "hdr/stdio_macros.h" #include "src/errno/libc_errno.h" -#include using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::EQ; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::NE; diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp index 6c86b8759801e1b..016722aa11ab82d 100644 --- a/libc/test/src/stdio/fopencookie_test.cpp +++ b/libc/test/src/stdio/fopencookie_test.cpp @@ -18,8 +18,8 @@ #include "test/UnitTest/MemoryMatcher.h" #include "test/UnitTest/Test.h" +#include "hdr/stdio_macros.h" #include "src/errno/libc_errno.h" -#include #include using MemoryView = LIBC_NAMESPACE::testing::MemoryView; diff --git a/libc/test/src/stdio/fprintf_test.cpp b/libc/test/src/stdio/fprintf_test.cpp index 08b31795b435b21..82a3e039d9baadf 100644 --- a/libc/test/src/stdio/fprintf_test.cpp +++ b/libc/test/src/stdio/fprintf_test.cpp @@ -17,8 +17,6 @@ #include "test/UnitTest/Test.h" -#include - namespace printf_test { #ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE using LIBC_NAMESPACE::fclose; diff --git a/libc/test/src/stdio/fscanf_test.cpp b/libc/test/src/stdio/fscanf_test.cpp index 701090788ca10c3..e5b8c4f422bacd4 100644 --- a/libc/test/src/stdio/fscanf_test.cpp +++ b/libc/test/src/stdio/fscanf_test.cpp @@ -19,8 +19,6 @@ #include "test/UnitTest/Test.h" -#include - namespace scanf_test { #ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE using LIBC_NAMESPACE::fclose; diff --git a/libc/test/src/stdio/ftell_test.cpp b/libc/test/src/stdio/ftell_test.cpp index 62745e2194be6d3..01ff071f2ee78cb 100644 --- a/libc/test/src/stdio/ftell_test.cpp +++ b/libc/test/src/stdio/ftell_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/stdio_macros.h" #include "src/stdio/fclose.h" #include "src/stdio/fopen.h" #include "src/stdio/fread.h" @@ -17,8 +18,6 @@ #include "src/stdio/setvbuf.h" #include "test/UnitTest/Test.h" -#include - class LlvmLibcFTellTest : public LIBC_NAMESPACE::testing::Test { protected: void test_with_bufmode(int bufmode) { diff --git a/libc/test/src/stdio/putc_test.cpp b/libc/test/src/stdio/putc_test.cpp index 7349a97d80e19dc..e881a0e2d0108bf 100644 --- a/libc/test/src/stdio/putc_test.cpp +++ b/libc/test/src/stdio/putc_test.cpp @@ -15,8 +15,6 @@ #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcPutcTest, WriteToFile) { constexpr char FILENAME[] = "testdata/putc_output.test"; ::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w"); diff --git a/libc/test/src/stdio/setbuf_test.cpp b/libc/test/src/stdio/setbuf_test.cpp index b0abca4acf731bf..25fea59076626f1 100644 --- a/libc/test/src/stdio/setbuf_test.cpp +++ b/libc/test/src/stdio/setbuf_test.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "hdr/stdio_macros.h" #include "src/stdio/fclose.h" #include "src/stdio/fopen.h" #include "src/stdio/fread.h" @@ -14,8 +15,6 @@ #include "src/stdio/ungetc.h" #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcSetbufTest, DefaultBufsize) { // The idea in this test is to change the buffer after opening a file and // ensure that read and write work as expected. diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp index d42ebac12ead286..a1e1fee25db31df 100644 --- a/libc/test/src/stdio/setvbuf_test.cpp +++ b/libc/test/src/stdio/setvbuf_test.cpp @@ -13,8 +13,8 @@ #include "src/stdio/setvbuf.h" #include "test/UnitTest/Test.h" +#include "hdr/stdio_macros.h" #include "src/errno/libc_errno.h" -#include TEST(LlvmLibcSetvbufTest, SetNBFBuffer) { // The idea in this test is that we open a file for writing and reading, and diff --git a/libc/test/src/stdio/sscanf_test.cpp b/libc/test/src/stdio/sscanf_test.cpp index 59be4e6de6ed65b..33bb0acba3e6628 100644 --- a/libc/test/src/stdio/sscanf_test.cpp +++ b/libc/test/src/stdio/sscanf_test.cpp @@ -6,13 +6,11 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/limits.h" -#include "src/__support/FPUtil/FPBits.h" - #include "src/stdio/sscanf.h" -#include // For EOF - +#include "hdr/stdio_macros.h" // For EOF +#include "src/__support/CPP/limits.h" +#include "src/__support/FPUtil/FPBits.h" #include "test/UnitTest/FPMatcher.h" #include "test/UnitTest/Test.h" diff --git a/libc/test/src/stdio/ungetc_test.cpp b/libc/test/src/stdio/ungetc_test.cpp index c98995ff0811bb3..b9d7530fc717710 100644 --- a/libc/test/src/stdio/ungetc_test.cpp +++ b/libc/test/src/stdio/ungetc_test.cpp @@ -6,16 +6,16 @@ // //===----------------------------------------------------------------------===// +#include "src/stdio/ungetc.h" + +#include "hdr/stdio_macros.h" #include "src/stdio/fclose.h" #include "src/stdio/fopen.h" #include "src/stdio/fread.h" #include "src/stdio/fseek.h" #include "src/stdio/fwrite.h" -#include "src/stdio/ungetc.h" #include "test/UnitTest/Test.h" -#include - TEST(LlvmLibcUngetcTest, UngetAndReadBack) { constexpr char FILENAME[] = "testdata/ungetc_test.test"; ::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w"); diff --git a/libc/test/src/stdio/unlocked_fileop_test.cpp b/libc/test/src/stdio/unlocked_fileop_test.cpp index 09697a6452f4860..67f1b0ff513bc59 100644 --- a/libc/test/src/stdio/unlocked_fileop_test.cpp +++ b/libc/test/src/stdio/unlocked_fileop_test.cpp @@ -18,7 +18,6 @@ #include "test/UnitTest/Test.h" #include "src/errno/libc_errno.h" -#include TEST(LlvmLibcFILETest, UnlockedReadAndWrite) { constexpr char fNAME[] = "testdata/unlocked_read_and_write.test"; diff --git a/libc/test/src/stdio/vfprintf_test.cpp b/libc/test/src/stdio/vfprintf_test.cpp index 9bad2c831e5c427..80d484500d5f237 100644 --- a/libc/test/src/stdio/vfprintf_test.cpp +++ b/libc/test/src/stdio/vfprintf_test.cpp @@ -21,8 +21,6 @@ #include "test/UnitTest/Test.h" -#include - namespace printf_test { #ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE using LIBC_NAMESPACE::fclose; diff --git a/libc/test/src/stdio/vfscanf_test.cpp b/libc/test/src/stdio/vfscanf_test.cpp index fa4e27582375f8b..b66538671f62063 100644 --- a/libc/test/src/stdio/vfscanf_test.cpp +++ b/libc/test/src/stdio/vfscanf_test.cpp @@ -19,8 +19,6 @@ #include "test/UnitTest/Test.h" -#include - namespace scanf_test { #ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE using LIBC_NAMESPACE::fclose; diff --git a/libc/test/src/unistd/getopt_test.cpp b/libc/test/src/unistd/getopt_test.cpp index 1ca7c99e1ce3731..e6e87720cde48d3 100644 --- a/libc/test/src/unistd/getopt_test.cpp +++ b/libc/test/src/unistd/getopt_test.cpp @@ -13,8 +13,6 @@ #include "src/stdio/fflush.h" #include "src/stdio/fopencookie.h" -#include - using LIBC_NAMESPACE::cpp::array; namespace test_globals { diff --git a/libc/test/src/wchar/wctob_test.cpp b/libc/test/src/wchar/wctob_test.cpp index 3f911884a7c12c6..977224bf77abe0c 100644 --- a/libc/test/src/wchar/wctob_test.cpp +++ b/libc/test/src/wchar/wctob_test.cpp @@ -6,10 +6,8 @@ // //===----------------------------------------------------------------------===// -#include //for EOF - +#include "hdr/stdio_macros.h" //for EOF #include "src/wchar/wctob.h" - #include "test/UnitTest/Test.h" TEST(LlvmLibcWctob, DefaultLocale) {