-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc][stdio] Use proxy headers of stdio.h in src and test folders. #110067
Conversation
@llvm/pr-subscribers-libc Author: None (lntue) ChangesPatch is 28.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/110067.diff 46 Files Affected:
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 5e3122f59de9ed..13dc892978bb87 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 a212846dd8f411..a4d6a972ec9ac9 100644
--- a/libc/hdr/stdio_macros.h
+++ b/libc/hdr/stdio_macros.h
@@ -16,7 +16,7 @@
#else // Overlay mode
-#include <stdio.h>
+#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 00000000000000..cec55abfde7bf6
--- /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 <stdio.h> 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 <stdio.h>.
+// 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 <stdio.h>
+
+#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 b4de39621416f7..fab5245816bbe1 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 60e95f07e37f91..ecb52b7102cb0e 100644
--- a/libc/hdr/types/FILE.h
+++ b/libc/hdr/types/FILE.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <stdio.h>
+#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 d8fe7731a84bda..7323a05001c407 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 <stdio.h>
+#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 abc3aa659365f7..52337e5b63e2dc 100644
--- a/libc/hdr/types/off_t.h
+++ b/libc/hdr/types/off_t.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <stdio.h>
+#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 69fb71ad3f6515..96f0e6933ade68 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 5556b812596f83..5abbf11b3671cd 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 fd2b908db171df..0c0d5a350829e7 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 <stdarg.h>
-#include <stdio.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt
index 9cac42ed71fb76..c4ad333e251639 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 5de76842d7beab..0856a3430803ae 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 <stdio.h> //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 42d6ad00877734..6222589cc4bab9 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 <stdio.h>
+#include <stdarg.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/getchar.cpp b/libc/src/stdio/gpu/getchar.cpp
index 048cf23b0d64a5..d99b97b5c5a008 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 <stdio.h> //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 63af6fffeea73c..d9903193ef1658 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 <stdio.h>
+#include <stdarg.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/putchar.cpp b/libc/src/stdio/gpu/putchar.cpp
index d03a3fe68daf7a..c49b02e2f1f10f 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 <stdio.h> //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 af84432d1ef8c7..20f7a889a378a1 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 <stdio.h> //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 f314f6872ad0e4..961cfa48579e0a 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 <stdio.h>
-
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 f364646fcea58f..7c012d139ba5dc 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 <stdio.h>
-
namespace LIBC_NAMESPACE {
template <uint16_t opcode>
diff --git a/libc/src/stdio/gpu/vprintf.cpp b/libc/src/stdio/gpu/vprintf.cpp
index 1356aceeb51c52..2bb74d7f017b59 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 <stdio.h>
-
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 fa36732a159be1..d6241e1ca0439d 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 1095f01d71f24e..542327ad5a49a9 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 fcf0b88885f17b..f3f56bce64292b 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 <stdarg.h>
-#include <stdio.h>
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 2f68c3faa0ad08..5977ea7c8e0b57 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 <stdio.h>
#include <stdlib.h>
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 8aa07219a6527b..82f17d2ef2e17b 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 <stdio.h> // 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 ffbb3ec337ed4d..1a21afe51085b1 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 <stdio.h>
#include <sys/stat.h> // 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 1412c3f27a2d5f..fb2c89c4980b48 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 <stdio.h>
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 989bb312afadf4..2cc8436bd66f28 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 <stdio.h>
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 48d7a043cad7c3..46cf12c2c253be 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 <stdio.h>
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 d005a71710d21a..984acbdd371a99 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 <stdio.h>
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 0fbe19cf08d837..98ead6edd38b47 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 <stdio.h>
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 6c86b8759801e1..016722aa11ab82 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 <stdio.h>
#include <stdlib.h>
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 08b31795b435b2..82a3e039d9baad 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 <stdio.h>
-
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 701090788ca10c..e5b8c4f422bacd 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 <stdio.h>
-
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 62745e2194be6d..01ff071f2ee78c 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 <stdio.h>
-
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 7349a97d80e19d..e881a0e2d0108b 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 <stdio.h>
-
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 b0abca4acf731b..25fea59076626f 100644
--- a/libc/test/src/stdio/setbuf_test.cpp
+++ b/libc/test/src/stdio/setbuf_test.cpp
@@ -6,6 +6...
[truncated]
|
#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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be in FILE.h
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C99 (and C++) define these as macros https://en.cppreference.com/w/c/io/std_streams, and so I put their definition here together with the macros. Probably we could factor them out to stdio-streams.h
instead. WDYT?
libc/test/src/stdio/sprintf_test.cpp
Outdated
// using ::sprintf; | ||
// } | ||
|
||
class LlvmLibcSPrintfTest : public LIBC_NAMESPACE::testing::Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this change is necessary, but if you'd like to do it it should be in a separate patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is needed to fix a race condition due to multiple tests below accessing to the same buffer, that somehow become very consistent with the new proxy headers when I test locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it can land before this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this file's change to #110624
@@ -6,6 +6,7 @@ | |||
// | |||
//===----------------------------------------------------------------------===// | |||
|
|||
#include "hdr/stdio_macros.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we have the hdr/ includes after the src/ includes. Not sure if that's a convention to stick to, or something that can't be done here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the target header to the top.
#60481