@@ -447,19 +447,17 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
447
447
createFile (StringRef FileName,
448
448
Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
449
449
Optional<StringRef> Source) {
450
- StringRef Dir;
451
- StringRef File;
452
- SmallString<128 > DirBuf;
453
- SmallString<128 > FileBuf;
454
- std::string RemappedFileString = DebugPrefixMap.remapPath (FileName);
455
- SmallString<128 > RemappedFile = StringRef (RemappedFileString);
456
- llvm::sys::path::remove_dots (RemappedFile);
457
- std::string CurDir = DebugPrefixMap.remapPath (Opts.DebugCompilationDir );
458
- if (llvm::sys::path::is_absolute (RemappedFile)) {
450
+ StringRef File, Dir;
451
+ StringRef CurDir = Opts.DebugCompilationDir ;
452
+ SmallString<128 > NormalizedFile (FileName);
453
+ SmallString<128 > FileBuf, DirBuf;
454
+ llvm::sys::path::remove_dots (NormalizedFile);
455
+ if (llvm::sys::path::is_absolute (NormalizedFile) &&
456
+ llvm::sys::path::is_absolute (CurDir)) {
459
457
// Strip the common prefix (if it is more than just "/") from current
460
458
// directory and FileName for a more space-efficient encoding.
461
- auto FileIt = llvm::sys::path::begin (RemappedFile );
462
- auto FileE = llvm::sys::path::end (RemappedFile );
459
+ auto FileIt = llvm::sys::path::begin (NormalizedFile );
460
+ auto FileE = llvm::sys::path::end (NormalizedFile );
463
461
auto CurDirIt = llvm::sys::path::begin (CurDir);
464
462
auto CurDirE = llvm::sys::path::end (CurDir);
465
463
for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
@@ -468,20 +466,22 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
468
466
// Don't strip the common prefix if it is only the root "/"
469
467
// since that would make LLVM diagnostic locations confusing.
470
468
Dir = {};
471
- File = RemappedFile ;
469
+ File = NormalizedFile ;
472
470
} else {
473
471
for (; FileIt != FileE; ++FileIt)
474
472
llvm::sys::path::append (FileBuf, *FileIt);
475
473
Dir = DirBuf;
476
474
File = FileBuf;
477
475
}
478
476
} else {
479
- File = RemappedFile ;
477
+ File = NormalizedFile ;
480
478
// Leave <compiler-generated> & friends as is, without directory.
481
479
if (!(File.startswith (" <" ) && File.endswith (" >" )))
482
480
Dir = CurDir;
483
481
}
484
- llvm::DIFile *F = DBuilder.createFile (File, Dir, CSInfo, Source);
482
+ llvm::DIFile *F =
483
+ DBuilder.createFile (DebugPrefixMap.remapPath (File),
484
+ DebugPrefixMap.remapPath (Dir), CSInfo, Source);
485
485
DIFileCache[FileName].reset (F);
486
486
return F;
487
487
}
@@ -1880,9 +1880,13 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
1880
1880
StringRef SplitName = StringRef ();
1881
1881
// Note that File + Dir need not result in a valid path.
1882
1882
// The directory part of the main file is the current working directory.
1883
- MainFile =
1884
- DBuilder.createFile (DebugPrefixMap.remapPath (SourcePath),
1885
- DebugPrefixMap.remapPath (Opts.DebugCompilationDir ));
1883
+ std::string RemappedFile = DebugPrefixMap.remapPath (SourcePath);
1884
+ std::string RemappedDir = DebugPrefixMap.remapPath (Opts.DebugCompilationDir );
1885
+ bool RelFile = llvm::sys::path::is_relative (RemappedFile);
1886
+ bool RelDir = llvm::sys::path::is_relative (RemappedDir);
1887
+ MainFile = (RelFile && RelDir)
1888
+ ? createFile (SourcePath, {}, {})
1889
+ : DBuilder.createFile (RemappedFile, RemappedDir);
1886
1890
1887
1891
StringRef Sysroot = IGM.Context .SearchPathOpts .SDKPath ;
1888
1892
StringRef SDK;
0 commit comments