From baa74bd3968028d8e5b10ee9b50d0dceb41e85a9 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 22 Mar 2013 21:12:51 +0000 Subject: [PATCH] [modules] When a MacroInfo object is deserialized, allocate and store its submodule ID. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177760 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/MacroInfo.h | 23 +++++++++++++++++++++++ include/clang/Lex/Preprocessor.h | 4 ++++ lib/Lex/MacroInfo.cpp | 3 ++- lib/Lex/PPDirectives.cpp | 13 +++++++++++++ lib/Serialization/ASTReader.cpp | 2 +- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/include/clang/Lex/MacroInfo.h b/include/clang/Lex/MacroInfo.h index 08052019cb..ec1385d1ea 100644 --- a/include/clang/Lex/MacroInfo.h +++ b/include/clang/Lex/MacroInfo.h @@ -101,6 +101,9 @@ private: /// \brief Must warn if the macro is unused at the end of translation unit. bool IsWarnIfUnused : 1; + /// \brief Whether this macro info was loaded from an AST file. + unsigned FromASTFile : 1; + ~MacroInfo() { assert(ArgumentList == 0 && "Didn't call destroy before dtor!"); } @@ -272,8 +275,28 @@ public: IsDisabled = true; } + /// \brief Determine whether this macro info came from an AST file (such as + /// a precompiled header or module) rather than having been parsed. + bool isFromASTFile() const { return FromASTFile; } + + /// \brief Retrieve the global ID of the module that owns this particular + /// macro info. + unsigned getOwningModuleID() const { + if (isFromASTFile()) + return *(const unsigned*)(this+1); + + return 0; + } + private: unsigned getDefinitionLengthSlow(SourceManager &SM) const; + + void setOwningModuleID(unsigned ID) { + assert(isFromASTFile()); + *(unsigned*)(this+1) = ID; + } + + friend class Preprocessor; }; /// \brief Encapsulates changes to the "macros namespace" (the location where diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index eccd449869..799f0902d5 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1208,6 +1208,10 @@ public: /// \brief Allocate a new MacroInfo object with the provided SourceLocation. MacroInfo *AllocateMacroInfo(SourceLocation L); + /// \brief Allocate a new MacroInfo object loaded from an AST file. + MacroInfo *AllocateDeserializedMacroInfo(SourceLocation L, + unsigned SubModuleID); + /// \brief Turn the specified lexer token into a fully checked and spelled /// filename, e.g. as an operand of \#include. /// diff --git a/lib/Lex/MacroInfo.cpp b/lib/Lex/MacroInfo.cpp index 3d4ffb40c0..213e71132b 100644 --- a/lib/Lex/MacroInfo.cpp +++ b/lib/Lex/MacroInfo.cpp @@ -28,7 +28,8 @@ MacroInfo::MacroInfo(SourceLocation DefLoc) IsDisabled(false), IsUsed(false), IsAllowRedefinitionsWithoutWarning(false), - IsWarnIfUnused(false) { + IsWarnIfUnused(false), + FromASTFile(false) { } unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const { diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index e19eb31335..163dbf413e 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -57,6 +57,19 @@ MacroInfo *Preprocessor::AllocateMacroInfo(SourceLocation L) { return MI; } +MacroInfo *Preprocessor::AllocateDeserializedMacroInfo(SourceLocation L, + unsigned SubModuleID) { + LLVM_STATIC_ASSERT(llvm::AlignOf::Alignment >= sizeof(SubModuleID), + "alignment for MacroInfo is less than the ID"); + MacroInfo *MI = + (MacroInfo*)BP.Allocate(sizeof(MacroInfo) + sizeof(SubModuleID), + llvm::AlignOf::Alignment); + new (MI) MacroInfo(L); + MI->FromASTFile = true; + MI->setOwningModuleID(SubModuleID); + return MI; +} + MacroDirective *Preprocessor::AllocateMacroDirective(MacroInfo *MI, SourceLocation Loc, bool isImported) { diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 0f674530bc..73cd72f44c 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -1151,7 +1151,7 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, SubmoduleID GlobalSubmoduleID = getGlobalSubmoduleID(F, Record[2]); unsigned NextIndex = 3; SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); - MacroInfo *MI = PP.AllocateMacroInfo(Loc); + MacroInfo *MI = PP.AllocateDeserializedMacroInfo(Loc, GlobalSubmoduleID); // FIXME: Location should be import location in case of module. MacroDirective *MD = PP.AllocateMacroDirective(MI, Loc, /*isImported=*/true); -- 2.40.0