Skip to content

[Support] Remove an unnecessary include #123182

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

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

mstorsjo
Copy link
Member

In 1e53f95, the FileSystem.h header was changed to always include <sys/stat.h>, while it previously only was included if HAVE_SYS_STAT_H was defined.

HAVE_SYS_STAT_H was defined in llvm/Config/config.h, while this header only included llvm/Config/llvm-config.h. Thus, <sys/stat.h> was only being included in some but not all cases.

The change to always include <sys/stat.h> broke compiling LLDB for MinGW targets, because the MinGW <sys/stat.h> header adds an "#define fstat _fstat64" define, which breaks LLDBs use of a struct with a member named "fstat".

Remove the include of <sys/stat.h> in FileSystem.h, as it seems to not be necessary in practice.

Change one instance of defined(_MSC_VER) into defined(_WIN32) in ErrorHandling.cpp to get <io.h> included; this source file did include config.h before transitively including FileSystem.h. The include of <sys/stat.h> in FileSystem.h would bring in <io.h> (needed for ::write()), explaining why this ifdef didn't need to cover MinGW before.

In 1e53f95, the FileSystem.h header
was changed to always include <sys/stat.h>, while it previously
only was included if HAVE_SYS_STAT_H was defined.

HAVE_SYS_STAT_H was defined in llvm/Config/config.h, while this
header only included llvm/Config/llvm-config.h. Thus, <sys/stat.h>
was only being included in some but not all cases.

The change to always include <sys/stat.h> broke compiling LLDB
for MinGW targets, because the MinGW <sys/stat.h> header adds
an "#define fstat _fstat64" define, which breaks LLDBs use of
a struct with a member named "fstat".

Remove the include of <sys/stat.h> in FileSystem.h, as it seems to
not be necessary in practice.

Change one instance of defined(_MSC_VER) into defined(_WIN32)
in ErrorHandling.cpp to get <io.h> included; this source file did
include config.h before transitively including FileSystem.h. The
include of <sys/stat.h> in FileSystem.h would bring in <io.h>
(needed for ::write()), explaining why this ifdef didn't need
to cover MinGW before.
@llvmbot
Copy link
Member

llvmbot commented Jan 16, 2025

@llvm/pr-subscribers-llvm-support

Author: Martin Storsjö (mstorsjo)

Changes

In 1e53f95, the FileSystem.h header was changed to always include <sys/stat.h>, while it previously only was included if HAVE_SYS_STAT_H was defined.

HAVE_SYS_STAT_H was defined in llvm/Config/config.h, while this header only included llvm/Config/llvm-config.h. Thus, <sys/stat.h> was only being included in some but not all cases.

The change to always include <sys/stat.h> broke compiling LLDB for MinGW targets, because the MinGW <sys/stat.h> header adds an "#define fstat _fstat64" define, which breaks LLDBs use of a struct with a member named "fstat".

Remove the include of <sys/stat.h> in FileSystem.h, as it seems to not be necessary in practice.

Change one instance of defined(_MSC_VER) into defined(_WIN32) in ErrorHandling.cpp to get <io.h> included; this source file did include config.h before transitively including FileSystem.h. The include of <sys/stat.h> in FileSystem.h would bring in <io.h> (needed for ::write()), explaining why this ifdef didn't need to cover MinGW before.


Full diff: https://github.com/llvm/llvm-project/pull/123182.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Support/FileSystem.h (-2)
  • (modified) llvm/lib/Support/ErrorHandling.cpp (+1-1)
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h
index c16ea2dcbb770f..245e4a24c70df1 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -44,8 +44,6 @@
 #include <system_error>
 #include <vector>
 
-#include <sys/stat.h>
-
 namespace llvm {
 namespace sys {
 namespace fs {
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index 8659f9492d5a35..afe3b37cc34319 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -33,7 +33,7 @@
 #if defined(HAVE_UNISTD_H)
 # include <unistd.h>
 #endif
-#if defined(_MSC_VER)
+#if defined(_WIN32)
 # include <io.h>
 # include <fcntl.h>
 #endif

@mstorsjo mstorsjo merged commit 94609ae into llvm:main Jan 16, 2025
10 checks passed
@mstorsjo mstorsjo deleted the remove-unnecessary-include branch January 16, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants