diff options
-rw-r--r-- | include/clang/Frontend/Utils.h | 5 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 6 | ||||
-rw-r--r-- | lib/Frontend/InitHeaderSearch.cpp | 5 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 8 | ||||
-rw-r--r-- | tools/clang-cc/clang-cc.cpp | 22 |
5 files changed, 28 insertions, 18 deletions
diff --git a/include/clang/Frontend/Utils.h b/include/clang/Frontend/Utils.h index 5526dfdb32..cc0d1b5671 100644 --- a/include/clang/Frontend/Utils.h +++ b/include/clang/Frontend/Utils.h @@ -41,8 +41,9 @@ class Stmt; class TargetInfo; /// Apply the header search options to get given HeaderSearch object. -void ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts, - HeaderSearch &HS, const LangOptions &Lang, +void ApplyHeaderSearchOptions(HeaderSearch &HS, + const HeaderSearchOptions &HSOpts, + const LangOptions &Lang, const llvm::Triple &triple); /// InitializePreprocessor - Initialize the preprocessor getting it and the diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 2783716b89..799efa8685 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -94,6 +94,9 @@ class Preprocessor { bool DisableMacroExpansion : 1; // True if macro expansion is disabled. bool InMacroArgs : 1; // True if parsing fn macro invocation args. + /// Whether the preprocessor owns the header search object. + bool OwnsHeaderSearch : 1; + /// Identifiers - This is mapping/lookup information for all identifiers in /// the program, including program keywords. mutable IdentifierTable Identifiers; @@ -209,7 +212,8 @@ private: // Cached tokens state. public: Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target, SourceManager &SM, HeaderSearch &Headers, - IdentifierInfoLookup *IILookup = 0); + IdentifierInfoLookup *IILookup = 0, + bool OwnsHeaderSearch = false); ~Preprocessor(); diff --git a/lib/Frontend/InitHeaderSearch.cpp b/lib/Frontend/InitHeaderSearch.cpp index 0e120e87ac..b4f48ac8fd 100644 --- a/lib/Frontend/InitHeaderSearch.cpp +++ b/lib/Frontend/InitHeaderSearch.cpp @@ -641,8 +641,9 @@ void InitHeaderSearch::Realize() { } } -void clang::ApplyHeaderSearchOptions(const HeaderSearchOptions &HSOpts, - HeaderSearch &HS, const LangOptions &Lang, +void clang::ApplyHeaderSearchOptions(HeaderSearch &HS, + const HeaderSearchOptions &HSOpts, + const LangOptions &Lang, const llvm::Triple &Triple) { InitHeaderSearch Init(HS, HSOpts.Verbose, HSOpts.Sysroot); diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 487b9d63c1..0110e6b9a4 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -46,12 +46,14 @@ using namespace clang; Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts, TargetInfo &target, SourceManager &SM, HeaderSearch &Headers, - IdentifierInfoLookup* IILookup) + IdentifierInfoLookup* IILookup, + bool OwnsHeaders) : Diags(&diags), Features(opts), Target(target),FileMgr(Headers.getFileMgr()), SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup), BuiltinInfo(Target), CurPPLexer(0), CurDirLookup(0), Callbacks(0) { ScratchBuf = new ScratchBuffer(SourceMgr); CounterValue = 0; // __COUNTER__ starts at 0. + OwnsHeaderSearch = OwnsHeaders; // Clear stats. NumDirectives = NumDefined = NumUndefined = NumPragma = 0; @@ -115,6 +117,10 @@ Preprocessor::~Preprocessor() { // Delete the scratch buffer info. delete ScratchBuf; + // Delete the header search info, if we own it. + if (OwnsHeaderSearch) + delete &HeaderInfo; + delete Callbacks; } diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index f6e6557209..0b5a6d35a6 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -379,7 +379,7 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, const PreprocessorOptions &PPOpts, const DependencyOutputOptions &DepOpts, TargetInfo &Target, SourceManager &SourceMgr, - HeaderSearch &HeaderInfo) { + FileManager &FileMgr) { PTHManager *PTHMgr = 0; if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) { fprintf(stderr, "error: cannot use both -token-cache and -include-pth " @@ -400,8 +400,10 @@ CreatePreprocessor(Diagnostic &Diags, const LangOptions &LangInfo, exit(1); // Create the Preprocessor. + HeaderSearch *HeaderInfo = new HeaderSearch(FileMgr); Preprocessor *PP = new Preprocessor(Diags, LangInfo, Target, - SourceMgr, HeaderInfo, PTHMgr); + SourceMgr, *HeaderInfo, PTHMgr, + /*OwnsHeaderSearch=*/true); // Note that this is different then passing PTHMgr to Preprocessor's ctor. // That argument is used as the IdentifierInfoLookup argument to @@ -1203,19 +1205,17 @@ int main(int argc, char **argv) { if (i) SourceMgr.clearIDTables(); - // Process the -I options and set them in the HeaderInfo. - HeaderSearch HeaderInfo(FileMgr); - - // Apply all the options to the header search object. - ApplyHeaderSearchOptions(CompOpts.getHeaderSearchOpts(), HeaderInfo, - CompOpts.getLangOpts(), Triple); - // Set up the preprocessor with these options. llvm::OwningPtr<Preprocessor> PP(CreatePreprocessor(Diags, CompOpts.getLangOpts(), CompOpts.getPreprocessorOpts(), CompOpts.getDependencyOutputOpts(), - *Target, SourceMgr, HeaderInfo)); + *Target, SourceMgr, FileMgr)); + + // Apply all the options to the header search object. + ApplyHeaderSearchOptions(PP->getHeaderSearchInfo(), + CompOpts.getHeaderSearchOpts(), + CompOpts.getLangOpts(), Triple); if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) { if (InitializeSourceManager(*PP.get(), InFile)) @@ -1230,8 +1230,6 @@ int main(int argc, char **argv) { Diags.getClient()->BeginSourceFile(CompOpts.getLangOpts()); ProcessInputFile(CompOpts, *PP, InFile, ProgAction, Context); Diags.getClient()->EndSourceFile(); - - HeaderInfo.ClearFileInfo(); } if (CompOpts.getDiagnosticOpts().ShowCarets) |