aboutsummaryrefslogtreecommitdiff
path: root/Lex
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-22 01:16:55 +0000
committerChris Lattner <sabre@nondot.org>2007-07-22 01:16:55 +0000
commit9c683062752a26014197df1c8792a19efa9e93cf (patch)
tree4348ea31261d70bc881253804d1459cf866e8a26 /Lex
parent8146b6851e873eab71341f1b1d3198894bc4c0ac (diff)
Fix a really subtle bug in the macro expander caching code, where
redefinition of a macro could cause invalid memory to be deleted. Found preprocessing 253.perlbmk. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40380 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Lex')
-rw-r--r--Lex/MacroExpander.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lex/MacroExpander.cpp b/Lex/MacroExpander.cpp
index fade854657..57bdfccc11 100644
--- a/Lex/MacroExpander.cpp
+++ b/Lex/MacroExpander.cpp
@@ -245,6 +245,7 @@ void MacroExpander::Init(Token &Tok, MacroArgs *Actuals) {
AtStartOfLine = Tok.isAtStartOfLine();
HasLeadingSpace = Tok.hasLeadingSpace();
MacroTokens = &*Macro->tokens_begin();
+ OwnsMacroTokens = false;
NumMacroTokens = Macro->tokens_end()-Macro->tokens_begin();
// If this is a function-like macro, expand the arguments and change
@@ -270,6 +271,7 @@ void MacroExpander::Init(const Token *TokArray, unsigned NumToks) {
Macro = 0;
ActualArgs = 0;
MacroTokens = TokArray;
+ OwnsMacroTokens = false;
NumMacroTokens = NumToks;
CurToken = 0;
InstantiateLoc = SourceLocation();
@@ -288,8 +290,10 @@ void MacroExpander::Init(const Token *TokArray, unsigned NumToks) {
void MacroExpander::destroy() {
// If this was a function-like macro that actually uses its arguments, delete
// the expanded tokens.
- if (Macro && MacroTokens != &*Macro->tokens_begin())
+ if (OwnsMacroTokens) {
delete [] MacroTokens;
+ MacroTokens = 0;
+ }
// MacroExpander owns its formal arguments.
if (ActualArgs) ActualArgs->destroy();
@@ -455,6 +459,7 @@ void MacroExpander::ExpandFunctionArguments() {
if (NumMacroTokens)
memcpy(Res, &ResultToks[0], NumMacroTokens*sizeof(Token));
MacroTokens = Res;
+ OwnsMacroTokens = true;
}
}