[PATCH] lex: improve include handling on Linux for Windows
Saleem Abdulrasool
abdulras at fb.com
Thu Mar 6 14:29:22 PST 2014
Hi majnemer,
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.
http://llvm-reviews.chandlerc.com/D2994
Files:
lib/Lex/PPDirectives.cpp
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ 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 @@
// the path.
ModuleMap::KnownHeader SuggestedModule;
SourceLocation FilenameLoc = FilenameTok.getLocation();
+ SmallString<1024> NormalizedPath;
+ if (LangOpts.MSVCCompat) {
+ NormalizedPath = Filename.str();
+ llvm::sys::fs::normalise_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 @@
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 @@
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 @@
// 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2994.1.patch
Type: text/x-patch
Size: 3343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140306/4525d02f/attachment.bin>
More information about the cfe-commits
mailing list