Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang/include/clang/Basic/FileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,12 @@ class FileManager : public RefCountedBase<FileManager> {
/// If path is not absolute and FileSystemOptions set the working
/// directory, the path is modified to be relative to the given
/// working directory.
/// \returns true if \c path changed.
bool FixupRelativePath(SmallVectorImpl<char> &path) const;
/// \returns true if \c Path changed.
bool FixupRelativePath(SmallVectorImpl<char> &Path) const {
return fixupRelativePath(FileSystemOpts, Path);
}
static bool fixupRelativePath(const FileSystemOptions &FileSystemOpts,
SmallVectorImpl<char> &Path);

/// Makes \c Path absolute taking into account FileSystemOptions and the
/// working directory option.
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/Basic/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,17 @@ OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
return FileEntryRef(*Insertion.first);
}

bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
StringRef pathRef(path.data(), path.size());
bool FileManager::fixupRelativePath(const FileSystemOptions &FileSystemOpts,
SmallVectorImpl<char> &Path) {
StringRef pathRef(Path.data(), Path.size());

if (FileSystemOpts.WorkingDir.empty()
|| llvm::sys::path::is_absolute(pathRef))
return false;

SmallString<128> NewPath(FileSystemOpts.WorkingDir);
llvm::sys::path::append(NewPath, pathRef);
path = NewPath;
Path = NewPath;
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ CompilerInstance::createOutputFileImpl(StringRef OutputPath, bool Binary,
"File Manager is required to fix up relative path.\n");

AbsPath.emplace(OutputPath);
FileMgr->FixupRelativePath(*AbsPath);
FileManager::fixupRelativePath(getFileSystemOpts(), *AbsPath);
OutputPath = *AbsPath;
}

Expand Down
11 changes: 0 additions & 11 deletions clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,6 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
llvm::TimerGroup::clearAll();

if (llvm::timeTraceProfilerEnabled()) {
// It is possible that the compiler instance doesn't own a file manager here
// if we're compiling a module unit. Since the file manager are owned by AST
// when we're compiling a module unit. So the file manager may be invalid
// here.
//
// It should be fine to create file manager here since the file system
// options are stored in the compiler invocation and we can recreate the VFS
// from the compiler invocation.
if (!Clang->hasFileManager())
Clang->createFileManager();

if (auto profilerOutput = Clang->createOutputFile(
Clang->getFrontendOpts().TimeTracePath, /*Binary=*/false,
/*RemoveFileOnSignal=*/false,
Expand Down