[llvm] [Support] Remove an unnecessary include (PR #123182)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 16 03:08:56 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Martin Storsjö (mstorsjo)

<details>
<summary>Changes</summary>

In 1e53f9523d3d5fcb2993b4b6540f1ed8d743380b, 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
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

``````````

</details>


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


More information about the llvm-commits mailing list