-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[CMake] Remove some always-true HAVE_XXX_H #123087
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
[CMake] Remove some always-true HAVE_XXX_H #123087
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-llvm-support @llvm/pr-subscribers-llvm-analysis Author: Fangrui Song (MaskRay) ChangesThese are unneeded even on AIX, PURE_WINDOWS, and ZOS (per #104706)
Full diff: https://github.com/llvm/llvm-project/pull/123087.diff 13 Files Affected:
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index 64878d28d9e1e5..14248624d54504 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -59,7 +59,6 @@ endif()
# include checks
check_include_file(dlfcn.h HAVE_DLFCN_H)
-check_include_file(errno.h HAVE_ERRNO_H)
check_include_file(fcntl.h HAVE_FCNTL_H)
check_include_file(malloc/malloc.h HAVE_MALLOC_MALLOC_H)
if( NOT PURE_WINDOWS )
@@ -69,7 +68,6 @@ check_include_file(signal.h HAVE_SIGNAL_H)
check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
-check_include_file(sys/stat.h HAVE_SYS_STAT_H)
check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_include_file(sysexits.h HAVE_SYSEXITS_H)
check_include_file(termios.h HAVE_TERMIOS_H)
diff --git a/llvm/include/llvm/Config/config.h.cmake b/llvm/include/llvm/Config/config.h.cmake
index 3e6b94dfbe5458..dbecb5c17ce386 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -72,9 +72,6 @@
/* Define if __unw_add_dynamic_fde() is available on this platform. */
#cmakedefine HAVE_UNW_ADD_DYNAMIC_FDE ${HAVE_UNW_ADD_DYNAMIC_FDE}
-/* Define to 1 if you have the <errno.h> header file. */
-#cmakedefine HAVE_ERRNO_H ${HAVE_ERRNO_H}
-
/* Define to 1 if you have the <fcntl.h> header file. */
#cmakedefine HAVE_FCNTL_H ${HAVE_FCNTL_H}
@@ -198,9 +195,6 @@
/* Define to 1 if you have the <sys/resource.h> header file. */
#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H}
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}
-
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h
index 9cf53360b4e966..c16ea2dcbb770f 100644
--- a/llvm/include/llvm/Support/FileSystem.h
+++ b/llvm/include/llvm/Support/FileSystem.h
@@ -44,9 +44,7 @@
#include <system_error>
#include <vector>
-#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif
namespace llvm {
namespace sys {
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 031d675c330ec4..ecdc841a38d112 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1885,7 +1885,7 @@ Constant *GetConstantFoldFPValue128(float128 V, Type *Ty) {
/// Clear the floating-point exception state.
inline void llvm_fenv_clearexcept() {
-#if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
+#if HAVE_DECL_FE_ALL_EXCEPT
feclearexcept(FE_ALL_EXCEPT);
#endif
errno = 0;
@@ -1896,7 +1896,7 @@ inline bool llvm_fenv_testexcept() {
int errno_val = errno;
if (errno_val == ERANGE || errno_val == EDOM)
return true;
-#if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
+#if HAVE_DECL_FE_ALL_EXCEPT && HAVE_DECL_FE_INEXACT
if (fetestexcept(FE_ALL_EXCEPT & ~FE_INEXACT))
return true;
#endif
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
index 71036f33cf9291..10160ddbf826ee 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
@@ -20,11 +20,9 @@
#ifdef __linux__
// These includes used by RTDyldMemoryManager::getPointerToNamedFunction()
// for Glibc trickery. See comments in this function for more information.
- #ifdef HAVE_SYS_STAT_H
- #include <sys/stat.h>
- #endif
- #include <fcntl.h>
- #include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
#endif
namespace llvm {
diff --git a/llvm/lib/Support/Errno.cpp b/llvm/lib/Support/Errno.cpp
index 60a7e536b6c5cf..0ef8d1ef1c99ae 100644
--- a/llvm/lib/Support/Errno.cpp
+++ b/llvm/lib/Support/Errno.cpp
@@ -13,10 +13,7 @@
#include "llvm/Support/Errno.h"
#include "llvm/Config/config.h"
#include <cstring>
-
-#if HAVE_ERRNO_H
#include <errno.h>
-#endif
//===----------------------------------------------------------------------===//
//=== WARNING: Implementation here must contain only TRULY operating system
@@ -26,11 +23,9 @@
namespace llvm {
namespace sys {
-#if HAVE_ERRNO_H
std::string StrError() {
return StrError(errno);
}
-#endif // HAVE_ERRNO_H
std::string StrError(int errnum) {
std::string str;
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 44097bad7b46ed..9f943687c9e721 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -18,9 +18,7 @@
#include "Unix.h"
#include <limits.h>
#include <stdio.h>
-#if HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 3c07cba7122bf9..bc7391bd8c08aa 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -26,9 +26,7 @@
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
-#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index ec0fad7076b450..9af2c175806275 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -28,9 +28,7 @@
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/SystemZ/zOSSupport.h"
#include "llvm/Support/raw_ostream.h"
-#if HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 50d6248ba6af8e..b66e858c965ffb 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -53,9 +53,7 @@
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
-#if HAVE_SYS_STAT_H
#include <sys/stat.h>
-#endif
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
diff --git a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
index 75a370a3b7e8ee..db2a78765858fc 100644
--- a/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn
@@ -89,9 +89,7 @@ write_cmake_config("config") {
"HAVE_DECL_FE_ALL_EXCEPT=1",
"HAVE_DECL_FE_INEXACT=1",
"LLVM_ENABLE_CRASH_DUMPS=",
- "HAVE_ERRNO_H=1",
"HAVE_FCNTL_H=1",
- "HAVE_FENV_H=1",
"HAVE_FFI_CALL=",
"HAVE_FFI_FFI_H=",
"HAVE_FFI_H=",
@@ -101,7 +99,6 @@ write_cmake_config("config") {
"HAVE_PTHREAD_GET_NAME_NP=",
"HAVE_PTHREAD_SET_NAME_NP=",
"HAVE_SIGNAL_H=1",
- "HAVE_SYS_STAT_H=1",
"HAVE_VALGRIND_VALGRIND_H=",
"HAVE__ALLOCA=",
"HAVE___ALLOCA=",
diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
index 74b4eca0889a7a..52e5106812c1f3 100644
--- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
+++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
@@ -201,9 +201,6 @@
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
diff --git a/utils/bazel/llvm_configs/config.h.cmake b/utils/bazel/llvm_configs/config.h.cmake
index 3e6b94dfbe5458..9dfb70710f74e3 100644
--- a/utils/bazel/llvm_configs/config.h.cmake
+++ b/utils/bazel/llvm_configs/config.h.cmake
@@ -198,9 +198,6 @@
/* Define to 1 if you have the <sys/resource.h> header file. */
#cmakedefine HAVE_SYS_RESOURCE_H ${HAVE_SYS_RESOURCE_H}
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#cmakedefine HAVE_SYS_STAT_H ${HAVE_SYS_STAT_H}
-
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H ${HAVE_SYS_TIME_H}
|
You can test this locally with the following command:git-clang-format --diff 091adb8807decb4fa1b4e58eba141a06058eb804 b25902a36e8353a1916e9470b98044d43c0e36c7 --extensions cpp,h,inc -- llvm/include/llvm/Support/FileSystem.h llvm/lib/Analysis/ConstantFolding.cpp llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp llvm/lib/Support/Errno.cpp llvm/lib/Support/Unix/Path.inc llvm/lib/Support/Unix/Process.inc llvm/lib/Support/Unix/Program.inc llvm/lib/Support/Unix/Signals.inc llvm/lib/Support/Unix/Unix.h llvm/lib/Support/raw_ostream.cpp utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h View the diff from clang-format here.diff --git a/llvm/lib/Support/Errno.cpp b/llvm/lib/Support/Errno.cpp
index 0ef8d1ef1c..174deea459 100644
--- a/llvm/lib/Support/Errno.cpp
+++ b/llvm/lib/Support/Errno.cpp
@@ -23,9 +23,7 @@
namespace llvm {
namespace sys {
-std::string StrError() {
- return StrError(errno);
-}
+std::string StrError() { return StrError(errno); }
std::string StrError(int errnum) {
std::string str;
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 280f290e90..ea0957c5e2 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -16,10 +16,10 @@
//===----------------------------------------------------------------------===//
#include "Unix.h"
+#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <sys/stat.h>
-#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 2c55059e05..a59be39398 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -15,9 +15,9 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
+#include <fcntl.h>
#include <mutex>
#include <optional>
-#include <fcntl.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
diff --git a/llvm/lib/Support/Unix/Unix.h b/llvm/lib/Support/Unix/Unix.h
index 4840b51f75..c173442483 100644
--- a/llvm/lib/Support/Unix/Unix.h
+++ b/llvm/lib/Support/Unix/Unix.h
@@ -45,7 +45,7 @@
# include <dlfcn.h>
#endif
-# include <fcntl.h>
+#include <fcntl.h>
/// This function builds an error message into \p ErrMsg using the \p prefix
/// string and the Unix error number given by \p errnum. If errnum is -1, the
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index e75ddc66b7..5943be6795 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -30,7 +30,7 @@
#include <sys/stat.h>
// <fcntl.h> may provide O_BINARY.
-# include <fcntl.h>
+#include <fcntl.h>
#if defined(HAVE_UNISTD_H)
# include <unistd.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.
LGTM!
Created using spr 1.3.5-bogner
LGTM |
These are unneeded even on AIX, PURE_WINDOWS, and ZOS (per #104706) * HAVE_ERRNO_H: introduced by 1a93330 (2009) but unneeded. The guarded ABI is unconditionally used by lldb. * HAVE_FCNTL_H * HAVE_FENV_H * HAVE_SYS_STAT_H Pull Request: llvm/llvm-project#123087
@@ -44,9 +44,7 @@ | |||
#include <system_error> | |||
#include <vector> | |||
|
|||
#ifdef HAVE_SYS_STAT_H | |||
#include <sys/stat.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.
This change, quite surprisingly, broke building LLDB for a mingw target: https://github.com/mstorsjo/llvm-mingw/actions/runs/12799882284/job/35692046639
The culprit seems to be this particular change; FileSystem.h
doesn't include config.h
(only llvm-config.h
), so in many (but not all) cases of including this header, HAVE_SYS_STAT_H
was not defined, and thus <sys/stat.h>
wasn't included.
It seems like the <sys/stat.h>
include here is (mostly?) unnecessary - I've successfully rebuilt LLVM (llvm+clang+lld+lldb+clang-tools-extra) for both macOS and Linux, with this include entirely removed.
The reason for why it broke LLDB for mingw targets, is that LLDB contains a structure with a field named fstat
: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.7/lldb/source/Plugins/Process/Utility/RegisterContext_x86.h#L271
The mingw-w64 sys/stat.h
header contains a #define fstat _fstat64
: https://github.com/mingw-w64/mingw-w64/blob/v12.0.0/mingw-w64-headers/crt/sys/stat.h#L280
This define would work fine if it would be included before the LLDB struct declaration, but not when it gets included between the struct declaration and use.
I guess the most straightforward fix is to just drop the include of <sys/stat.h>
here which doesn't seem to be needed in practice?
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.
Dropping sys/stat.h
sounds good to me, but I'd wait for Fangrui to come online if time permits.
These are unneeded even on AIX, PURE_WINDOWS, and ZOS (per #104706)
The guarded ABI is unconditionally used by lldb.