diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 859f06a434bb..5526dfdb324f 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -78,12 +78,12 @@ bool CheckDiagnostics(Preprocessor &PP); /// AttachDependencyFileGen - Create a dependency file generator, and attach /// it to the given preprocessor. This takes ownership of the output stream. -void AttachDependencyFileGen(Preprocessor *PP, +void AttachDependencyFileGen(Preprocessor &PP, const DependencyOutputOptions &Opts); /// CacheTokens - Cache tokens for use with PCH. Note that this requires /// a seekable stream. -void CacheTokens(Preprocessor& PP, llvm::raw_fd_ostream* OS); +void CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS); } // end namespace clang diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 9c311fac629b..c7f93595e1ea 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -60,23 +60,23 @@ public: }; } -void clang::AttachDependencyFileGen(Preprocessor *PP, +void clang::AttachDependencyFileGen(Preprocessor &PP, const DependencyOutputOptions &Opts) { if (Opts.Targets.empty()) { - PP->getDiagnostics().Report(diag::err_fe_dependency_file_requires_MT); + PP.getDiagnostics().Report(diag::err_fe_dependency_file_requires_MT); return; } std::string Err; llvm::raw_ostream *OS(new llvm::raw_fd_ostream(Opts.OutputFile.c_str(), Err)); if (!Err.empty()) { - PP->getDiagnostics().Report(diag::err_fe_error_opening) + PP.getDiagnostics().Report(diag::err_fe_error_opening) << Opts.OutputFile << Err; return; } - assert(!PP->getPPCallbacks() && "Preprocessor callbacks already registered!"); - PP->setPPCallbacks(new DependencyFileCallback(PP, OS, Opts)); + assert(!PP.getPPCallbacks() && "Preprocessor callbacks already registered!"); + PP.setPPCallbacks(new DependencyFileCallback(&PP, OS, Opts)); } /// FileMatchesDepCriteria - Determine whether the given Filename should be diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index 85a11923e12f..f6e655720969 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -376,8 +376,10 @@ std::string GetBuiltinIncludePath(const char *Argv0) { static Preprocessor * CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, - const PreprocessorOptions &PPOpts, TargetInfo &Target, - SourceManager &SourceMgr, HeaderSearch &HeaderInfo) { + const PreprocessorOptions &PPOpts, + const DependencyOutputOptions &DepOpts, + TargetInfo &Target, SourceManager &SourceMgr, + HeaderSearch &HeaderInfo) { PTHManager *PTHMgr = 0; if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) { fprintf(stderr, "error: cannot use both -token-cache and -include-pth " @@ -411,6 +413,10 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, InitializePreprocessor(*PP, PPOpts); + // Handle generating dependencies, if requested. + if (!DepOpts.OutputFile.empty()) + AttachDependencyFileGen(*PP, DepOpts); + return PP; } @@ -1207,12 +1213,9 @@ int main(int argc, char **argv) { // Set up the preprocessor with these options. llvm::OwningPtr PP(CreatePreprocessor(Diags, CompOpts.getLangOpts(), - CompOpts.getPreprocessorOpts(), *Target, SourceMgr, - HeaderInfo)); - - // Handle generating dependencies, if requested. - if (!CompOpts.getDependencyOutputOpts().OutputFile.empty()) - AttachDependencyFileGen(PP.get(), CompOpts.getDependencyOutputOpts()); + CompOpts.getPreprocessorOpts(), + CompOpts.getDependencyOutputOpts(), + *Target, SourceMgr, HeaderInfo)); if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) { if (InitializeSourceManager(*PP.get(), InFile))