r203614 - lex: improve include handling on Linux for Windows

Saleem Abdulrasool compnerd at compnerd.org
Tue Mar 11 19:32:53 PDT 2014


On Tue, Mar 11, 2014 at 3:55 PM, Nico Weber <thakis at chromium.org> wrote:

> Huh, did you see Richard's comments on the review for this patch?
>

No, sorry, I didnt see them.  Addressed in a follow up commit (SVN r203632).


>
> On Tue, Mar 11, 2014 at 3:41 PM, Saleem Abdulrasool <compnerd at compnerd.org
> > wrote:
>
>> Author: compnerd
>> Date: Tue Mar 11 17:41:45 2014
>> New Revision: 203614
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=203614&view=rev
>> Log:
>> 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.
>>
>> Modified:
>>     cfe/trunk/lib/Lex/PPDirectives.cpp
>>
>> Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=203614&r1=203613&r2=203614&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
>> +++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Mar 11 17:41:45 2014
>> @@ -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::HandleIncludeDirectiv
>>    // 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::HandleIncludeDirectiv
>>            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::HandleIncludeDirectiv
>>
>>      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::HandleIncludeDirectiv
>>        // 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);
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>


-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140311/ec5dc0a6/attachment.html>


More information about the cfe-commits mailing list