summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2014-03-11 22:41:45 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2014-03-11 22:41:45 +0000
commit198034105d36c7006b9506572d365a43f0d66f3c (patch)
tree5410988aadca93619d07f20502826346f38ac07b /clang/lib
parentdcd25e31a7387279da8bbe964652581f389784b4 (diff)
downloadbcm5719-llvm-198034105d36c7006b9506572d365a43f0d66f3c.tar.gz
bcm5719-llvm-198034105d36c7006b9506572d365a43f0d66f3c.zip
lex: improve include handling on Linux for Windows
Normalise the path separator character on non-windows platforms. Although this would work on Windows as well (most newer versions of Windows support either '/' or '\' as a path separator character), it could potentially cause problems with full UNC paths. This change enables the use of the Windows SDK on Linux which will not accept '\' as a path separator. llvm-svn: 203614
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 050ade45e44..b3d766a759c 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -25,6 +25,7 @@
#include "clang/Lex/Pragma.h"
#include "llvm/ADT/APInt.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/SaveAndRestore.h"
using namespace clang;
@@ -1449,9 +1450,15 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
// the path.
ModuleMap::KnownHeader SuggestedModule;
SourceLocation FilenameLoc = FilenameTok.getLocation();
+ SmallString<1024> NormalizedPath;
+ if (LangOpts.MSVCCompat) {
+ NormalizedPath = Filename.str();
+ llvm::sys::fs::normalize_separators(NormalizedPath);
+ }
const FileEntry *File = LookupFile(
- FilenameLoc, Filename, isAngled, LookupFrom, CurDir,
- Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL,
+ FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename,
+ isAngled, LookupFrom, CurDir, Callbacks ? &SearchPath : NULL,
+ Callbacks ? &RelativePath : NULL,
HeaderInfo.getHeaderSearchOpts().ModuleMaps ? &SuggestedModule : 0);
if (Callbacks) {
@@ -1465,8 +1472,11 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
HeaderInfo.AddSearchPath(DL, isAngled);
// Try the lookup again, skipping the cache.
- File = LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, CurDir,
- 0, 0, HeaderInfo.getHeaderSearchOpts().ModuleMaps
+ File = LookupFile(FilenameLoc,
+ LangOpts.MSVCCompat ? NormalizedPath.c_str()
+ : Filename,
+ isAngled, LookupFrom, CurDir, 0, 0,
+ HeaderInfo.getHeaderSearchOpts().ModuleMaps
? &SuggestedModule
: 0,
/*SkipCache*/ true);
@@ -1476,10 +1486,11 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
if (!SuggestedModule || !getLangOpts().Modules) {
// Notify the callback object that we've seen an inclusion directive.
- Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled,
- FilenameRange, File,
- SearchPath, RelativePath,
- /*ImportedModule=*/0);
+ Callbacks->InclusionDirective(HashLoc, IncludeTok,
+ LangOpts.MSVCCompat ? NormalizedPath.c_str()
+ : Filename,
+ isAngled, FilenameRange, File, SearchPath,
+ RelativePath, /*ImportedModule=*/0);
}
}
@@ -1490,8 +1501,9 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
// provide the user with a possible fixit.
if (isAngled) {
File = LookupFile(
- FilenameLoc, Filename, false, LookupFrom, CurDir,
- Callbacks ? &SearchPath : 0, Callbacks ? &RelativePath : 0,
+ FilenameLoc, LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename,
+ false, LookupFrom, CurDir, Callbacks ? &SearchPath : 0,
+ Callbacks ? &RelativePath : 0,
HeaderInfo.getHeaderSearchOpts().ModuleMaps ? &SuggestedModule : 0);
if (File) {
SourceRange Range(FilenameTok.getLocation(), CharEnd);
OpenPOWER on IntegriCloud