summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 04a4c7dbe68..c02eb761041 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -712,15 +712,18 @@ std::unique_ptr<llvm::raw_pwrite_stream> CompilerInstance::createOutputFile(
// Initialization Utilities
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input){
- return InitializeSourceManager(Input, getDiagnostics(),
- getFileManager(), getSourceManager(),
- getFrontendOpts());
+ return InitializeSourceManager(
+ Input, getDiagnostics(), getFileManager(), getSourceManager(),
+ hasPreprocessor() ? &getPreprocessor().getHeaderSearchInfo() : nullptr,
+ getFrontendOpts());
}
+// static
bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
DiagnosticsEngine &Diags,
FileManager &FileMgr,
SourceManager &SourceMgr,
+ HeaderSearch *HS,
const FrontendOptions &Opts) {
SrcMgr::CharacteristicKind
Kind = Input.isSystem() ? SrcMgr::C_System : SrcMgr::C_User;
@@ -737,7 +740,32 @@ bool CompilerInstance::InitializeSourceManager(const FrontendInputFile &Input,
// Figure out where to get and map in the main file.
if (InputFile != "-") {
- const FileEntry *File = FileMgr.getFile(InputFile, /*OpenFile=*/true);
+ const FileEntry *File;
+ if (Opts.FindPchSource.empty()) {
+ File = FileMgr.getFile(InputFile, /*OpenFile=*/true);
+ } else {
+ // When building a pch file in clang-cl mode, the .h file is built as if
+ // it was included by a cc file. Since the driver doesn't know about
+ // all include search directories, the frontend must search the input
+ // file through HeaderSearch here, as if it had been included by the
+ // cc file at Opts.FindPchSource.
+ const FileEntry *FindFile = FileMgr.getFile(Opts.FindPchSource);
+ if (!FindFile) {
+ Diags.Report(diag::err_fe_error_reading) << Opts.FindPchSource;
+ return false;
+ }
+ const DirectoryLookup *UnusedCurDir;
+ SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 16>
+ Includers;
+ Includers.push_back(std::make_pair(FindFile, FindFile->getDir()));
+ File = HS->LookupFile(InputFile, SourceLocation(), /*isAngled=*/false,
+ /*FromDir=*/nullptr,
+ /*CurDir=*/UnusedCurDir, Includers,
+ /*SearchPath=*/nullptr,
+ /*RelativePath=*/nullptr,
+ /*RequestingModule=*/nullptr,
+ /*SuggestedModule=*/nullptr, /*SkipCache=*/true);
+ }
if (!File) {
Diags.Report(diag::err_fe_error_reading) << InputFile;
return false;
OpenPOWER on IntegriCloud