summaryrefslogtreecommitdiffstats
path: root/lib/Frontend/InitHeaderSearch.cpp
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
committerdim <dim@FreeBSD.org>2011-10-20 21:14:49 +0000
commit3963a48221351c61c17fb3f382341ab04809a3d3 (patch)
treeee2483e98b09cac943dc93a6969d83ca737ff139 /lib/Frontend/InitHeaderSearch.cpp
parent611ba3ea3300b71eb95dc4e45f20eee5dddd32e1 (diff)
downloadFreeBSD-src-3963a48221351c61c17fb3f382341ab04809a3d3.zip
FreeBSD-src-3963a48221351c61c17fb3f382341ab04809a3d3.tar.gz
Vendor import of clang release_30 branch r142614:
http://llvm.org/svn/llvm-project/cfe/branches/release_30@142614
Diffstat (limited to 'lib/Frontend/InitHeaderSearch.cpp')
-rw-r--r--lib/Frontend/InitHeaderSearch.cpp204
1 files changed, 112 insertions, 92 deletions
diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp
index e11a415..b066e71 100644
--- a/lib/Frontend/InitHeaderSearch.cpp
+++ b/lib/Frontend/InitHeaderSearch.cpp
@@ -52,38 +52,34 @@ class InitHeaderSearch {
public:
- InitHeaderSearch(HeaderSearch &HS, bool verbose, llvm::StringRef sysroot)
+ InitHeaderSearch(HeaderSearch &HS, bool verbose, StringRef sysroot)
: Headers(HS), Verbose(verbose), IncludeSysroot(sysroot),
IsNotEmptyOrRoot(!(sysroot.empty() || sysroot == "/")) {
}
/// AddPath - Add the specified path to the specified group list.
- void AddPath(const llvm::Twine &Path, IncludeDirGroup Group,
+ void AddPath(const Twine &Path, IncludeDirGroup Group,
bool isCXXAware, bool isUserSupplied,
bool isFramework, bool IgnoreSysRoot = false);
/// AddGnuCPlusPlusIncludePaths - Add the necessary paths to support a gnu
/// libstdc++.
- void AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
- llvm::StringRef ArchDir,
- llvm::StringRef Dir32,
- llvm::StringRef Dir64,
+ void AddGnuCPlusPlusIncludePaths(StringRef Base,
+ StringRef ArchDir,
+ StringRef Dir32,
+ StringRef Dir64,
const llvm::Triple &triple);
/// AddMinGWCPlusPlusIncludePaths - Add the necessary paths to support a MinGW
/// libstdc++.
- void AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
- llvm::StringRef Arch,
- llvm::StringRef Version);
+ void AddMinGWCPlusPlusIncludePaths(StringRef Base,
+ StringRef Arch,
+ StringRef Version);
/// AddMinGW64CXXPaths - Add the necessary paths to support
/// libstdc++ of x86_64-w64-mingw32 aka mingw-w64.
- 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.
- void AddDelimitedPaths(llvm::StringRef String);
+ void AddMinGW64CXXPaths(StringRef Base,
+ StringRef Version);
// AddDefaultCIncludePaths - Add paths that should always be searched.
void AddDefaultCIncludePaths(const llvm::Triple &triple,
@@ -96,9 +92,9 @@ public:
/// AddDefaultSystemIncludePaths - Adds the default system include paths so
/// that e.g. stdio.h is found.
- void AddDefaultSystemIncludePaths(const LangOptions &Lang,
- const llvm::Triple &triple,
- const HeaderSearchOptions &HSOpts);
+ void AddDefaultIncludePaths(const LangOptions &Lang,
+ const llvm::Triple &triple,
+ const HeaderSearchOptions &HSOpts);
/// Realize - Merges all search path lists into one list and send it to
/// HeaderSearch.
@@ -107,7 +103,7 @@ public:
} // end anonymous namespace.
-void InitHeaderSearch::AddPath(const llvm::Twine &Path,
+void InitHeaderSearch::AddPath(const Twine &Path,
IncludeDirGroup Group, bool isCXXAware,
bool isUserSupplied, bool isFramework,
bool IgnoreSysRoot) {
@@ -116,7 +112,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
// Compute the actual path, taking into consideration -isysroot.
llvm::SmallString<256> MappedPathStorage;
- llvm::StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
+ StringRef MappedPathStr = Path.toStringRef(MappedPathStorage);
// Handle isysroot.
if ((Group == System || Group == CXXSystem) && !IgnoreSysRoot &&
@@ -134,7 +130,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
// Compute the DirectoryLookup type.
SrcMgr::CharacteristicKind Type;
- if (Group == Quoted || Group == Angled)
+ if (Group == Quoted || Group == Angled || Group == IndexHeaderMap)
Type = SrcMgr::C_User;
else if (isCXXAware)
Type = SrcMgr::C_System;
@@ -156,7 +152,7 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
if (const HeaderMap *HM = Headers.CreateHeaderMap(FE)) {
// It is a headermap, add it to the search path.
IncludePath.push_back(std::make_pair(Group, DirectoryLookup(HM, Type,
- isUserSupplied)));
+ isUserSupplied, Group == IndexHeaderMap)));
return;
}
}
@@ -167,30 +163,10 @@ void InitHeaderSearch::AddPath(const llvm::Twine &Path,
<< MappedPathStr << "\"\n";
}
-
-void InitHeaderSearch::AddDelimitedPaths(llvm::StringRef at) {
- if (at.empty()) // Empty string should not add '.' path.
- return;
-
- llvm::StringRef::size_type delim;
- while ((delim = at.find(llvm::sys::PathSeparator)) != llvm::StringRef::npos) {
- if (delim == 0)
- AddPath(".", Angled, false, true, false);
- else
- AddPath(at.substr(0, delim), Angled, false, true, false);
- at = at.substr(delim + 1);
- }
-
- if (at.empty())
- AddPath(".", Angled, false, true, false);
- else
- AddPath(at, Angled, false, true, false);
-}
-
-void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
- llvm::StringRef ArchDir,
- llvm::StringRef Dir32,
- llvm::StringRef Dir64,
+void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(StringRef Base,
+ StringRef ArchDir,
+ StringRef Dir32,
+ StringRef Dir64,
const llvm::Triple &triple) {
// Add the base dir
AddPath(Base, CXXSystem, true, false, false);
@@ -207,9 +183,9 @@ void InitHeaderSearch::AddGnuCPlusPlusIncludePaths(llvm::StringRef Base,
AddPath(Base + "/backward", CXXSystem, true, false, false);
}
-void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
- llvm::StringRef Arch,
- llvm::StringRef Version) {
+void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(StringRef Base,
+ StringRef Arch,
+ StringRef Version) {
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++",
CXXSystem, true, false, false);
AddPath(Base + "/" + Arch + "/" + Version + "/include/c++/" + Arch,
@@ -218,8 +194,8 @@ void InitHeaderSearch::AddMinGWCPlusPlusIncludePaths(llvm::StringRef Base,
CXXSystem, true, false, false);
}
-void InitHeaderSearch::AddMinGW64CXXPaths(llvm::StringRef Base,
- llvm::StringRef Version) {
+void InitHeaderSearch::AddMinGW64CXXPaths(StringRef Base,
+ StringRef Version) {
// Assumes Base is HeaderSearchOpts' ResourceDir
AddPath(Base + "/../../../include/c++/" + Version,
CXXSystem, true, false, false);
@@ -448,14 +424,16 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
llvm::Triple::OSType os = triple.getOS();
- switch (os) {
- case llvm::Triple::FreeBSD:
- case llvm::Triple::NetBSD:
- break;
- default:
- // FIXME: temporary hack: hard-coded paths.
- AddPath("/usr/local/include", System, true, false, false);
- break;
+ if (HSOpts.UseStandardSystemIncludes) {
+ switch (os) {
+ case llvm::Triple::FreeBSD:
+ case llvm::Triple::NetBSD:
+ break;
+ default:
+ // FIXME: temporary hack: hard-coded paths.
+ AddPath("/usr/local/include", System, true, false, false);
+ break;
+ }
}
// Builtin includes use #include_next directives and should be positioned
@@ -468,12 +446,17 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
AddPath(P.str(), System, false, false, false, /*IgnoreSysRoot=*/ true);
}
+ // All remaining additions are for system include directories, early exit if
+ // we aren't using them.
+ if (!HSOpts.UseStandardSystemIncludes)
+ return;
+
// Add dirs specified via 'configure --with-c-include-dirs'.
- llvm::StringRef CIncludeDirs(C_INCLUDE_DIRS);
+ StringRef CIncludeDirs(C_INCLUDE_DIRS);
if (CIncludeDirs != "") {
- llvm::SmallVector<llvm::StringRef, 5> dirs;
+ SmallVector<StringRef, 5> dirs;
CIncludeDirs.split(dirs, ":");
- for (llvm::SmallVectorImpl<llvm::StringRef>::iterator i = dirs.begin();
+ for (SmallVectorImpl<StringRef>::iterator i = dirs.begin();
i != dirs.end();
++i)
AddPath(*i, System, false, false, false);
@@ -597,9 +580,9 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
void InitHeaderSearch::
AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOptions &HSOpts) {
llvm::Triple::OSType os = triple.getOS();
- llvm::StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
+ StringRef CxxIncludeRoot(CXX_INCLUDE_ROOT);
if (CxxIncludeRoot != "") {
- llvm::StringRef CxxIncludeArch(CXX_INCLUDE_ARCH);
+ StringRef CxxIncludeArch(CXX_INCLUDE_ARCH);
if (CxxIncludeArch == "")
AddGnuCPlusPlusIncludePaths(CxxIncludeRoot, triple.str().c_str(),
CXX_INCLUDE_32BIT_DIR, CXX_INCLUDE_64BIT_DIR,
@@ -737,7 +720,12 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp
//===------------------------------------------------------------------===//
// Redhat based distros.
//===------------------------------------------------------------------===//
- // Fedora 15
+ // Fedora 15 (GCC 4.6.1)
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.1",
+ "x86_64-redhat-linux", "32", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.1",
+ "i686-redhat-linux", "", "", triple);
+ // Fedora 15 (GCC 4.6.0)
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
"x86_64-redhat-linux", "32", "", triple);
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
@@ -840,6 +828,17 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp
AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.6.0",
"x86_64-unknown-linux-gnu", "", "", triple);
+ // Slackware gcc 4.5.2 (13.37)
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.2",
+ "i486-slackware-linux", "", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.2",
+ "x86_64-slackware-linux", "", "", triple);
+ // Slackware gcc 4.5.3 (-current)
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.3",
+ "i486-slackware-linux", "", "", triple);
+ AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.5.3",
+ "x86_64-slackware-linux", "", "", triple);
+
// Gentoo x86 gcc 4.5.2
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/i686-pc-linux-gnu/4.5.2/include/g++-v4",
@@ -889,6 +888,10 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/g++-v4",
"x86_64-pc-linux-gnu", "32", "", triple);
+ // Gentoo amd64 gcc 4.3.4
+ AddGnuCPlusPlusIncludePaths(
+ "/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.4/include/g++-v4",
+ "x86_64-pc-linux-gnu", "", "", triple);
// Gentoo amd64 gcc 4.3.2
AddGnuCPlusPlusIncludePaths(
"/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.2/include/g++-v4",
@@ -936,32 +939,53 @@ AddDefaultCPlusPlusIncludePaths(const llvm::Triple &triple, const HeaderSearchOp
}
}
-void InitHeaderSearch::AddDefaultSystemIncludePaths(const LangOptions &Lang,
- const llvm::Triple &triple,
+void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
+ const llvm::Triple &triple,
const HeaderSearchOptions &HSOpts) {
- if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes) {
- if (HSOpts.UseLibcxx)
+ if (Lang.CPlusPlus && HSOpts.UseStandardCXXIncludes &&
+ HSOpts.UseStandardSystemIncludes) {
+ if (HSOpts.UseLibcxx) {
+ if (triple.isOSDarwin()) {
+ // On Darwin, libc++ may be installed alongside the compiler in
+ // lib/c++/v1.
+ llvm::sys::Path P(HSOpts.ResourceDir);
+ if (!P.isEmpty()) {
+ P.eraseComponent(); // Remove version from foo/lib/clang/version
+ P.eraseComponent(); // Remove clang from foo/lib/clang
+
+ // Get foo/lib/c++/v1
+ P.appendComponent("c++");
+ P.appendComponent("v1");
+ AddPath(P.str(), CXXSystem, true, false, false, true);
+ }
+ }
+
AddPath("/usr/include/c++/v1", CXXSystem, true, false, false);
- else
+ } else {
AddDefaultCPlusPlusIncludePaths(triple, HSOpts);
+ }
}
AddDefaultCIncludePaths(triple, HSOpts);
// Add the default framework include paths on Darwin.
- if (triple.isOSDarwin()) {
- AddPath("/System/Library/Frameworks", System, true, false, true);
- AddPath("/Library/Frameworks", System, true, false, true);
+ if (HSOpts.UseStandardSystemIncludes) {
+ if (triple.isOSDarwin()) {
+ AddPath("/System/Library/Frameworks", System, true, false, true);
+ AddPath("/Library/Frameworks", System, true, false, true);
+ }
}
}
/// RemoveDuplicates - If there are duplicate directory entries in the specified
-/// search list, remove the later (dead) ones.
-static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
- unsigned First, bool Verbose) {
+/// search list, remove the later (dead) ones. Returns the number of non-system
+/// headers removed, which is used to update NumAngled.
+static unsigned RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
+ unsigned First, bool Verbose) {
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
+ unsigned NonSystemRemoved = 0;
for (unsigned i = First; i != SearchList.size(); ++i) {
unsigned DirToRemove = i;
@@ -1028,12 +1052,15 @@ static void RemoveDuplicates(std::vector<DirectoryLookup> &SearchList,
llvm::errs() << " as it is a non-system directory that duplicates "
<< "a system directory\n";
}
+ if (DirToRemove != i)
+ ++NonSystemRemoved;
// This is reached if the current entry is a duplicate. Remove the
// DirToRemove (usually the current dir).
SearchList.erase(SearchList.begin()+DirToRemove);
--i;
}
+ return NonSystemRemoved;
}
@@ -1054,7 +1081,7 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) {
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
it != ie; ++it) {
- if (it->first == Angled)
+ if (it->first == Angled || it->first == IndexHeaderMap)
SearchList.push_back(it->second);
}
@@ -1063,7 +1090,11 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) {
for (path_iterator it = IncludePath.begin(), ie = IncludePath.end();
it != ie; ++it) {
- if (it->first == System || (Lang.CPlusPlus && it->first == CXXSystem))
+ if (it->first == System ||
+ (!Lang.ObjC1 && !Lang.CPlusPlus && it->first == CSystem) ||
+ (/*FIXME !Lang.ObjC1 && */Lang.CPlusPlus && it->first == CXXSystem) ||
+ (Lang.ObjC1 && !Lang.CPlusPlus && it->first == ObjCSystem) ||
+ (Lang.ObjC1 && Lang.CPlusPlus && it->first == ObjCXXSystem))
SearchList.push_back(it->second);
}
@@ -1076,7 +1107,8 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) {
// Remove duplicates across both the Angled and System directories. GCC does
// this and failing to remove duplicates across these two groups breaks
// #include_next.
- RemoveDuplicates(SearchList, NumQuoted, Verbose);
+ unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
+ NumAngled -= NonSystemRemoved;
bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
Headers.SetSearchPaths(SearchList, NumQuoted, NumAngled, DontSearchCurDir);
@@ -1116,19 +1148,7 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
E.IgnoreSysRoot);
}
- // Add entries from CPATH and friends.
- Init.AddDelimitedPaths(HSOpts.EnvIncPath);
- if (Lang.CPlusPlus && Lang.ObjC1)
- Init.AddDelimitedPaths(HSOpts.ObjCXXEnvIncPath);
- else if (Lang.CPlusPlus)
- Init.AddDelimitedPaths(HSOpts.CXXEnvIncPath);
- else if (Lang.ObjC1)
- Init.AddDelimitedPaths(HSOpts.ObjCEnvIncPath);
- else
- Init.AddDelimitedPaths(HSOpts.CEnvIncPath);
-
- if (HSOpts.UseStandardIncludes)
- Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
+ Init.AddDefaultIncludePaths(Lang, Triple, HSOpts);
Init.Realize(Lang);
}
OpenPOWER on IntegriCloud