r187315 - Reduce stack frame size by avoiding a large token vector on an error path.

Bob Wilson bob.wilson at apple.com
Sat Jul 27 14:59:57 PDT 2013

Author: bwilson
Date: Sat Jul 27 16:59:57 2013
New Revision: 187315

URL: http://llvm.org/viewvc/llvm-project?rev=187315&view=rev
Reduce stack frame size by avoiding a large token vector on an error path.

Beginning with svn r186971, we noticed an internal test started to fail when
using clang built with LTO. After much investigation, it turns out that there
are no blatant bugs here, we are just running out of stack space and crashing.
Preprocessor::ReadFunctionLikeMacroArgs already has one vector of 64 Tokens,
and r186971 added another.  When built with LTO, that function is inlined into
Preprocessor::HandleMacroExpandedIdentifier, which for our internal test is
invoked in a deep recursive cycle. I'm leaving the original 64 Token vector
alone on the assumption that it is important for performance, but the new
FixedArgTokens vector is only used on an error path, so it should be OK if it
requires additional heap storage. It would be even better if we could avoid
the deep recursion, but I think this change is a good thing to do regardless.


Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=187315&r1=187314&r2=187315&view=diff
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sat Jul 27 16:59:57 2013
@@ -681,7 +681,7 @@ MacroArgs *Preprocessor::ReadFunctionLik
     // TODO: See if this can be generalized to angle brackets for templates
     // inside macro arguments.
-    SmallVector<Token, 64> FixedArgTokens;
+    SmallVector<Token, 4> FixedArgTokens;
     unsigned FixedNumArgs = 0;
     SmallVector<SourceRange, 4> ParenHints, InitLists;
     if (!GenerateNewArgTokens(*this, ArgTokens, FixedArgTokens, FixedNumArgs,

More information about the cfe-commits mailing list