Simplify lifetime management of MacroInfo objects in Preprocessor by having the Preprocessor maintain them in a linked
list of allocated MacroInfos. This requires only 1 extra pointer per MacroInfo object, and allows us to blow them
away in one place. This fixes an elusive memory leak with MacroInfos (whose exact location I couldn't still figure
out despite substantial digging).
Fixes <rdar://problem/8361834>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116842 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 5e3b16e..ffdc6ae 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -33,8 +33,12 @@
if (!MICache.empty()) {
MI = MICache.back();
MICache.pop_back();
- } else
- MI = (MacroInfo*) BP.Allocate<MacroInfo>();
+ } else {
+ MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();
+ MIChain->Next = MIChainHead;
+ MIChainHead = MIChain;
+ MI = &(MIChainHead->MI);
+ }
return MI;
}