-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang][Cygwin] Remove erroneous _WIN32 define and clean up Cygwin code #138120
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
Conversation
With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. Co-authored-by: Jeremy Drake <[email protected]>
@llvm/pr-subscribers-clang Author: Mateusz Mikuła (mati865) ChangesWith this define present and building with Clang the build fails:
Removing it allows the build with Clang to succeed and doesn't break build with GCC. Split out from #134494 Full diff: https://github.com/llvm/llvm-project/pull/138120.diff 1 Files Affected:
diff --git a/clang/tools/libclang/CIndexer.cpp b/clang/tools/libclang/CIndexer.cpp
index 12d9d418dea51..11d9312b64849 100644
--- a/clang/tools/libclang/CIndexer.cpp
+++ b/clang/tools/libclang/CIndexer.cpp
@@ -26,12 +26,6 @@
#include <cstdio>
#include <mutex>
-#ifdef __CYGWIN__
-#include <cygwin/version.h>
-#include <sys/cygwin.h>
-#define _WIN32 1
-#endif
-
#ifdef _WIN32
#include <windows.h>
#elif defined(_AIX)
@@ -112,16 +106,6 @@ const std::string &CIndexer::getClangResourcesPath() {
sizeof(mbi));
GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH);
-#ifdef __CYGWIN__
- char w32path[MAX_PATH];
- strcpy(w32path, path);
-#if CYGWIN_VERSION_API_MAJOR > 0 || CYGWIN_VERSION_API_MINOR >= 181
- cygwin_conv_path(CCP_WIN_A_TO_POSIX, w32path, path, MAX_PATH);
-#else
- cygwin_conv_to_full_posix_path(w32path, path);
-#endif
-#endif
-
LibClangPath += path;
#elif defined(_AIX)
getClangResourcesPathImplAIX(LibClangPath);
|
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 feels a little more unclear to me.
Defining _WIN32
in cygwin mode compilations, and including w32api headers from there, feels brittle; I'm not familiar enough with cygwin to know if this is something that one usually can do, or whether it is commonly done, or what caveats that involves (doesn't e.g. cygwin have an incompatible definition of the type long
?) - so getting rid of that probably is good in itself.
Was this an issue only when building Clang with Clang - did this succeed if building Clang with GCC?
I presume that the removed codepaths did serve some purpose at some point initially. Can we dig up that purpose from the git history and recheck whether it's needed/relevant still at this point.
While building may be broken right now, the individual issue of missing _aligned_malloc()
probably is fixable as well, so I'd like to know a bit more about the reasoning for why this cygwin specific codepath should be removed.
The rule of thumb is to avoid using Win32 APIs unless absolutely necessary, but I'm not familiar with the reasons.
Indeed, it builds fine with GCC. If I grep through
GCC has some
It would be possible to apply similar
It was introduced by aa63fdf I'd expect Cygwin API missing the required bits back then, these days it can use the same code as Linux in this file.
There is another error for |
I agree; it may be a way to go overall, but not necessarily the primary solution here (and it may end up requiring many more tweaks).
Yes, I think so too. In this case here, the history seems to be a bit more tricky, as this originated as
Ah, I hadn't read the earlier discussions of these patches (or I have read and promptly forgot), now I understand this a bit better. So yeah, I would also first have taken the direction of just removing the Anyway, the comments from @jeremyd2019 there seal the case here I think. So if you update the PR description (i.e. future commit message) explaining why this no longer is necessary, I think this PR is good to go! |
dladdr was added to cygwin in 2017, according to the tags in version 2.8.0. |
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 updated the PR description with the details I wanted to have included in the commit message.
Looks good, thanks. |
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
…de (llvm#138120) With this define present and building with Clang the build fails: ``` In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36: In file included from /usr/include/w32api/windows.h:69: In file included from /usr/include/w32api/windef.h:9: In file included from /usr/include/w32api/minwindef.h:163: In file included from /usr/include/w32api/winnt.h:1658: In file included from /usr/lib/clang/20/include/x86intrin.h:15: In file included from /usr/lib/clang/20/include/immintrin.h:24: In file included from /usr/lib/clang/20/include/xmmintrin.h:31: /usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'? 45 | __mallocedMemory = _aligned_malloc(__size, __align); | ^ ``` Removing it allows the build with Clang to succeed and doesn't break build with GCC. The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring. This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.) Co-authored-by: Jeremy Drake <[email protected]>
With this define present and building with Clang the build fails:
Removing it allows the build with Clang to succeed and doesn't break build with GCC.
The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this was changed into a plain "#define _WIN32" (which not necessarily is something that is supported to do) in 1865df4 as part of a larger refactoring.
This cygwin specific code isn't needed for converting paths anymore, as dladdr takes care of it. (dladdr was added to cygwin in 2017, according to the tags in version 2.8.0.)