[cfe-dev] MinGW(-w64) fixes to InitHeaderSearch.cpp and float.h
Ruben Van Boxem
vanboxem.ruben at gmail.com
Sat Jun 25 07:55:04 PDT 2011
Now with patch...
2011/6/25 Ruben Van Boxem <vanboxem.ruben at gmail.com>:
> Hi,
>
> I bring fixes for MinGW(-w64) Clang users:
>
> 1. InitHeaderSearch.cpp: add a HeaderSearchOptions argument to
> AddDefaultCXXIncludePaths (AddDefaultCIncludePaths already had this,
> seems only logical to have it here) and use ResourceDir to find the
> sysroot of where Clang.exe is located. From there, add the
> x86_64-w64-mingw32 and i686-w64-mingw32 include paths for C and C++.
> All mingw-w64 toolchains are built --with-sysroot, and thus
> relocatable, so this change will always find the accompanying headers.
>
> 2. float.h: MinGW needs an #include_next, because as described on this
> page (http://msdn.microsoft.com/en-us/library/y0ybw9fy.aspx) there are
> non-standard extensions to float.h which are expected on Windows, and
> MinGW provides these declarations in their system header. GCC's
> float.h is "fixinclude"d to include_next the system header. Note that
> a trivial change is needed in mingw-w64's float.h, and that change
> will be committed as soon as Clang's header does what it's supposed to
> do.
>
> I do not have commit access, so if someone would please commit these
> changes, Clang will become a nicer MinGW compiler, and I would very
> much appreciate it. There are still lots of problems though, but this
> will make a basic setup work at least for trivial programs.
>
> Thanks!
>
> Ruben
>
-------------- next part --------------
Index: lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- lib/Frontend/InitHeaderSearch.cpp (revision 133866)
+++ lib/Frontend/InitHeaderSearch.cpp (working copy)
@@ -78,7 +78,8 @@
/// AddMinGW64CXXPaths - Add the necessary paths to support
/// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
- void AddMinGW64CXXPaths(llvm::StringRef Base);
+ void AddMinGW64CXXPaths(llvm::StringRef Base,
+ llvm::StringRef Version);
/// AddDelimitedPaths - Add a list of paths delimited by the system PATH
/// separator. The processing follows that of the CPATH variable for gcc.
@@ -90,7 +91,8 @@
// AddDefaultCPlusPlusIncludePaths - Add paths that should be searched when
// compiling c++.
- void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple);
+ void AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple,
+ const HeaderSearchOptions &HSOpts);
/// AddDefaultSystemIncludePaths - Adds the default system include paths so
/// that e.g. stdio.h is found.
@@ -216,13 +218,17 @@
CXXSystem, true, false, false);
}
-void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base) {
- AddPath(Base,
+void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base,
+ llvm::StringRef Version) {
+ // Assumes Base is HeaderSearchOpts' ResourceDir
+ AddPath(Base + "/../../../include/c++/" + Version,
CXXSystem, true, false, false);
- AddPath(Base + "/x86_64-w64-mingw32",
+ AddPath(Base + "/../../../include/c++/" + Version + "/x86_64-w64-mingw32",
CXXSystem, true, false, false);
- AddPath(Base + "/backward",
+ AddPath(Base + "/../../../include/c++/" + Version + "/i686-w64-mingw32",
CXXSystem, true, false, false);
+ AddPath(Base + "/../../../include/c++/" + Version + "/backward",
+ CXXSystem, true, false, false);
}
// FIXME: This probably should goto to some platform utils place.
@@ -550,13 +556,21 @@
case llvm::Triple::Cygwin:
AddPath("/usr/include/w32api", System, true, false, false);
break;
- case llvm::Triple::MinGW32:
- // FIXME: We should be aware of i686-w64-mingw32.
- if (triple.getArch() == llvm::Triple::x86_64)
- AddPath("c:/mingw/x86_64-w64-mingw32/include",
- System, true, false, false);
+ case llvm::Triple::MinGW32: {
+ // mingw-w64 crt include paths
+ llvm::sys::Path P(HSOpts.ResourceDir);
+ P.appendComponent("../../../i686-w64-mingw32/include"); // <sysroot>/i686-w64-mingw32/include
+ AddPath(P.str(), System, true, false, false);
+ P = llvm::sys::Path(HSOpts.ResourceDir);
+ P.appendComponent("../../../x86_64-w64-mingw32/include"); // <sysroot>/x86_64-w64-mingw32/include
+ AddPath(P.str(), System, true, false, false);
+ // mingw.org crt include paths
+ P = llvm::sys::Path(HSOpts.ResourceDir);
+ P.appendComponent("../../../include"); // <sysroot>/include
+ AddPath(P.str(), System, true, false, false);
AddPath("/mingw/include", System, true, false, false);
- AddPath("c:/mingw/include", System, true, false, false);
+ AddPath("c:/mingw/include", System, true, false, false);
+ } // brace to work around error skipping P initialization when jumping
break;
case llvm::Triple::Linux:
// Generic Debian multiarch support:
@@ -579,7 +593,7 @@
}
void InitHeaderSearch::
-AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple) {
+AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
llvm::Triple::OSType os = triple.getOS();
llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
if (CxxIncludeRoot != "") {
@@ -639,20 +653,17 @@
AddMinGWCPlusPlusIncludePaths("/usr/lib/gcc", "i686-pc-cygwin", "3.4.4");
break;
case llvm::Triple::MinGW32:
- // FIXME: We should be aware of i686-w64-mingw32.
- if (triple.getArch() == llvm::Triple::x86_64) {
- // mingw-w64-20110207
- AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.3");
- // mingw-w64-20101129
- AddMinGW64CXXPaths("c:/mingw/x86_64-w64-mingw32/include/c++/4.5.2");
- }
- // Try gcc 4.5.2 (MSYS)
- AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2");
- // Try gcc 4.5.0
+ // mingw-w64 C++ include paths (i686-w64-mingw32 and x86_64-w64-mingw32)
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.0");
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.1");
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.2");
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.5.3");
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.0");
+ AddMinGW64CXXPaths(HSOpts.ResourceDir, "4.6.1");
+ // mingw.org C++ include paths
+ AddMinGWCPlusPlusIncludePaths("/mingw/lib/gcc", "mingw32", "4.5.2"); //MSYS
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.5.0");
- // Try gcc 4.4.0
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.4.0");
- // Try gcc 4.3.0
AddMinGWCPlusPlusIncludePaths("c:/MinGW/lib/gcc", "mingw32", "4.3.0");
break;
case llvm::Triple::DragonFly:
@@ -924,7 +935,7 @@
if (HSOpts.UseLibcxx)
AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
else
- AddDefaultCPlusPlusIncludePaths(triple);
+ AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
}
AddDefaultCIncludePaths(triple, HSOpts);
Index: lib/Headers/float.h
===================================================================
--- lib/Headers/float.h (revision 133866)
+++ lib/Headers/float.h (working copy)
@@ -24,6 +24,14 @@
#ifndef __FLOAT_H
#define __FLOAT_H
+/* If we're on MinGW, fall back to the system's float.h, which might have
+ * additional definitions provided for Windows.
+ */
+#if defined(__MINGW32__) && \
+ defined(__has_include_next) && __has_include_next(<float.h>)
+# include_next <float.h>
+#endif
+
/* Characteristics of floating point types, C99 5.2.4.2.2 */
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
More information about the cfe-dev
mailing list