From 832de9fcf1793a73a9f4909346d9938b1f56304b Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Fri, 22 Feb 2013 18:35:59 +0000 Subject: [PATCH] [preprocessing record] Have the MacroDefinitions map point to the MacroDefinition object instead its index in the preprocessed entities vector. This is because the order of the entities in the vector can change in some (uncommon) cases. llvm-svn: 175907 --- clang/include/clang/Lex/PreprocessingRecord.h | 4 ++-- clang/lib/Lex/PreprocessingRecord.cpp | 16 +++++++--------- clang/lib/Serialization/ASTReader.cpp | 8 ++++++-- clang/test/Preprocessor/pp-record.c | 6 ++++++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index 535e0ca..665d250 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -325,7 +325,7 @@ namespace clang { } /// \brief Mapping from MacroInfo structures to their definitions. - llvm::DenseMap MacroDefinitions; + llvm::DenseMap MacroDefinitions; /// \brief External source of preprocessed entities. ExternalPreprocessingRecordSource *ExternalSource; @@ -356,7 +356,7 @@ namespace clang { unsigned allocateLoadedEntities(unsigned NumEntities); /// \brief Register a new macro definition. - void RegisterMacroDefinition(MacroInfo *Macro, PPEntityID PPID); + void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinition *Def); public: /// \brief Construct a new preprocessing record. diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index ac0985b..0f3587e 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -320,8 +320,8 @@ unsigned PreprocessingRecord::allocateLoadedEntities(unsigned NumEntities) { } void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro, - PPEntityID PPID) { - MacroDefinitions[Macro] = PPID; + MacroDefinition *Def) { + MacroDefinitions[Macro] = Def; } /// \brief Retrieve the preprocessed entity at the given ID. @@ -358,15 +358,12 @@ PreprocessingRecord::getLoadedPreprocessedEntity(unsigned Index) { } MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) { - llvm::DenseMap::iterator Pos + llvm::DenseMap::iterator Pos = MacroDefinitions.find(MI); if (Pos == MacroDefinitions.end()) return 0; - - PreprocessedEntity *Entity = getPreprocessedEntity(Pos->second); - if (Entity->isInvalid()) - return 0; - return cast(Entity); + + return Pos->second; } void PreprocessingRecord::addMacroExpansion(const Token &Id, @@ -415,7 +412,8 @@ void PreprocessingRecord::MacroDefined(const Token &Id, SourceRange R(MI->getDefinitionLoc(), MI->getDefinitionEndLoc()); MacroDefinition *Def = new (*this) MacroDefinition(Id.getIdentifierInfo(), R); - MacroDefinitions[MI] = addPreprocessedEntity(Def); + addPreprocessedEntity(Def); + MacroDefinitions[MI] = Def; } void PreprocessingRecord::MacroUndefined(const Token &Id, diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index da3add3..4c11f38 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1249,8 +1249,12 @@ void ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset, PreprocessedEntityID GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); - PPRec.RegisterMacroDefinition(Macro, - PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true)); + PreprocessingRecord::PPEntityID + PPID = PPRec.getPPEntityID(GlobalID-1, /*isLoaded=*/true); + MacroDefinition *PPDef = + cast_or_null(PPRec.getPreprocessedEntity(PPID)); + if (PPDef) + PPRec.RegisterMacroDefinition(Macro, PPDef); } ++NumMacrosRead; diff --git a/clang/test/Preprocessor/pp-record.c b/clang/test/Preprocessor/pp-record.c index 92ca366..48000ed 100644 --- a/clang/test/Preprocessor/pp-record.c +++ b/clang/test/Preprocessor/pp-record.c @@ -26,3 +26,9 @@ FNM( #define M2 int #define FM2(x,y) y x FM2(M1, M2); + +#define FM3(x) x +FM3( +#define M3 int x2 +) +M3; -- 2.7.4