[cfe-commits] r134587 - in /cfe/trunk: include/clang/Basic/SourceManager.h include/clang/Lex/MacroInfo.h include/clang/Lex/TokenLexer.h lib/ARCMigrate/TransformActions.cpp lib/ARCMigrate/Transforms.cpp lib/Basic/SourceManager.cpp lib/Lex/Lexer.cpp lib/Lex/MacroArgs.cpp lib/Lex/MacroArgs.h lib/Lex/MacroInfo.cpp lib/Lex/TokenLexer.cpp lib/Parse/ParseExpr.cpp test/PCH/variables.c test/PCH/variables.h test/Parser/recovery.c

Douglas Gregor dgregor at apple.com
Thu Jul 7 08:46:29 PDT 2011


On Jul 6, 2011, at 8:40 PM, Argyrios Kyrtzidis wrote:

> Author: akirtzidis
> Date: Wed Jul  6 22:40:34 2011
> New Revision: 134587
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=134587&view=rev
> Log:
> Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
> 
> When a macro instantiation occurs, reserve a SLocEntry chunk with length the
> full length of the macro definition source. Set the spelling location of this chunk
> to point to the start of the macro definition and any tokens that are lexed directly
> from the macro definition will get a location from this chunk with the appropriate offset.
> 
> For any tokens that come from argument expansion, '##' paste operator, etc. have their
> instantiation location point at the appropriate place in the instantiated macro definition
> (the argument identifier and the '##' token respectively).
> This improves macro instantiation diagnostics:
> 
> Before:
> 
> t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
> int y = M(/);
>        ^~~~
> t.c:5:11: note: instantiated from:
> int y = M(/);
>          ^
> 
> After:
> 
> t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
> int y = M(/);
>        ^~~~
> t.c:3:20: note: instantiated from:
> \#define M(op) (foo op 3);
>                ~~~ ^  ~
> t.c:5:11: note: instantiated from:
> int y = M(/);
>          ^
> 
> The memory savings for a candidate boost library that abuses the preprocessor are:
> 
> - 32% less SLocEntries (37M -> 25M)
> - 30% reduction in PCH file size (900M -> 635M)
> - 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

Very impressive!

	- Doug




More information about the cfe-commits mailing list