r175907 - [preprocessing record] Have the MacroDefinitions map point to the MacroDefinition object instead
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Feb 22 10:35:59 PST 2013
Author: akirtzidis
Date: Fri Feb 22 12:35:59 2013
New Revision: 175907
URL: http://llvm.org/viewvc/llvm-project?rev=175907&view=rev
Log:
[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.
Modified:
cfe/trunk/include/clang/Lex/PreprocessingRecord.h
cfe/trunk/lib/Lex/PreprocessingRecord.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Preprocessor/pp-record.c
Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=175907&r1=175906&r2=175907&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Fri Feb 22 12:35:59 2013
@@ -325,7 +325,7 @@ namespace clang {
}
/// \brief Mapping from MacroInfo structures to their definitions.
- llvm::DenseMap<const MacroInfo *, PPEntityID> MacroDefinitions;
+ llvm::DenseMap<const MacroInfo *, MacroDefinition *> 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.
Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=175907&r1=175906&r2=175907&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Fri Feb 22 12:35:59 2013
@@ -320,8 +320,8 @@ unsigned PreprocessingRecord::allocateLo
}
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::getLoadedPreprocess
}
MacroDefinition *PreprocessingRecord::findMacroDefinition(const MacroInfo *MI) {
- llvm::DenseMap<const MacroInfo *, PPEntityID>::iterator Pos
+ llvm::DenseMap<const MacroInfo *, MacroDefinition *>::iterator Pos
= MacroDefinitions.find(MI);
if (Pos == MacroDefinitions.end())
return 0;
-
- PreprocessedEntity *Entity = getPreprocessedEntity(Pos->second);
- if (Entity->isInvalid())
- return 0;
- return cast<MacroDefinition>(Entity);
+
+ return Pos->second;
}
void PreprocessingRecord::addMacroExpansion(const Token &Id,
@@ -415,7 +412,8 @@ void PreprocessingRecord::MacroDefined(c
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,
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=175907&r1=175906&r2=175907&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Feb 22 12:35:59 2013
@@ -1249,8 +1249,12 @@ void ASTReader::ReadMacroRecord(ModuleFi
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<MacroDefinition>(PPRec.getPreprocessedEntity(PPID));
+ if (PPDef)
+ PPRec.RegisterMacroDefinition(Macro, PPDef);
}
++NumMacrosRead;
Modified: cfe/trunk/test/Preprocessor/pp-record.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/pp-record.c?rev=175907&r1=175906&r2=175907&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/pp-record.c (original)
+++ cfe/trunk/test/Preprocessor/pp-record.c Fri Feb 22 12:35:59 2013
@@ -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;
More information about the cfe-commits
mailing list