[PATCH] D38356: keeps include path order when emulate msvc compiler
comicfans44 via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 28 06:56:46 PDT 2017
comicfans44 created this revision.
comicfans44 added a project: clang.
clang will drop user supplied include path if it's already in system include paths to emulate gcc. if two files with same name both exist in user path and system path, and user set system path first in arguments, this leads different behavior to msvc. this patch preserve user include path order when emulating msvc.
Repository:
rL LLVM
https://reviews.llvm.org/D38356
Files:
clang/lib/Frontend/InitHeaderSearch.cpp
Index: clang/lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- clang/lib/Frontend/InitHeaderSearch.cpp
+++ clang/lib/Frontend/InitHeaderSearch.cpp
@@ -99,7 +99,7 @@
/// Realize - Merges all search path lists into one list and send it to
/// HeaderSearch.
- void Realize(const LangOptions &Lang);
+ void Realize(const LangOptions &Lang, bool msvc);
};
} // end anonymous namespace.
@@ -493,7 +493,7 @@
/// 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) {
+ unsigned First, bool Verbose, bool msvc) {
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenDirs;
llvm::SmallPtrSet<const DirectoryEntry *, 8> SeenFrameworkDirs;
llvm::SmallPtrSet<const HeaderMap *, 8> SeenHeaderMaps;
@@ -525,7 +525,7 @@
//
// Since dupes of system dirs are rare, just rescan to find the original
// that we're nuking instead of using a DenseMap.
- if (CurEntry.getDirCharacteristic() != SrcMgr::C_User) {
+ if (!msvc && (CurEntry.getDirCharacteristic() != SrcMgr::C_User)) {
// Find the dir that this is the same of.
unsigned FirstDir;
for (FirstDir = First;; ++FirstDir) {
@@ -576,7 +576,7 @@
}
-void InitHeaderSearch::Realize(const LangOptions &Lang) {
+void InitHeaderSearch::Realize(const LangOptions &Lang, bool msvc) {
// Concatenate ANGLE+SYSTEM+AFTER chains together into SearchList.
std::vector<DirectoryLookup> SearchList;
SearchList.reserve(IncludePath.size());
@@ -587,14 +587,14 @@
SearchList.push_back(Include.second);
// Deduplicate and remember index.
- RemoveDuplicates(SearchList, 0, Verbose);
+ RemoveDuplicates(SearchList, 0, Verbose, msvc);
unsigned NumQuoted = SearchList.size();
for (auto &Include : IncludePath)
if (Include.first == Angled || Include.first == IndexHeaderMap)
SearchList.push_back(Include.second);
- RemoveDuplicates(SearchList, NumQuoted, Verbose);
+ RemoveDuplicates(SearchList, NumQuoted, Verbose, msvc);
unsigned NumAngled = SearchList.size();
for (auto &Include : IncludePath)
@@ -613,7 +613,8 @@
// Remove duplicates across both the Angled and System directories. GCC does
// this and failing to remove duplicates across these two groups breaks
// #include_next.
- unsigned NonSystemRemoved = RemoveDuplicates(SearchList, NumQuoted, Verbose);
+ unsigned NonSystemRemoved =
+ RemoveDuplicates(SearchList, NumQuoted, Verbose, msvc);
NumAngled -= NonSystemRemoved;
bool DontSearchCurDir = false; // TODO: set to true if -I- is set?
@@ -673,5 +674,6 @@
HS.getModuleMap().setBuiltinIncludeDir(Dir);
}
- Init.Realize(Lang);
+ Init.Realize(Lang,
+ Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38356.116976.patch
Type: text/x-patch
Size: 3025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170928/c026a3f7/attachment.bin>
More information about the cfe-commits
mailing list