[cfe-commits] r132247 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp

Chandler Carruth chandlerc at google.com
Sat May 28 14:52:14 PDT 2011


On Sat, May 28, 2011 at 2:02 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> On May 28, 2011, at 12:50 AM, Chandler Carruth wrote:
>
> On Sat, May 28, 2011 at 12:45 AM, Abramo Bagnara
> <abramo.bagnara at gmail.com> wrote:
>
> This is *very* useful!
>
> Using similar technique do you think it is feasible to do an helper that
>
> permit to know if a macro token is at start/end of a macro argument?
>
> Before you start touching macro argument source locations, please look
> at P9279 and my last patch. I'm working on the final benchmarks to
> validate that this doesn't cause major performance problems for
> typical code. Hopefully I'll get that checked in this weekend, but I
> thought that the last time I rotated around to work on that....
>
> % ./new/clang -fsyntax-only t6.cc
> t6.cc:5:1: error: expected unqualified-id
> M3(1, M0(2), 3);
>          ^
> t6.cc:1:15: note: instantiated from:
> #define M0(x) x
>               ^
> t6.cc:4:27: note: instantiated from:
> #define M3(x, y, z) M2(x, y, z)
>                           ^
> t6.cc:3:27: note: instantiated from:
> #define M2(x, y, z) M1(x, y, z)
>                           ^
> t6.cc:2:21: note: instantiated from:
> #define M1(x, y, z) y
>                     ^
> 1 error generated.
>
> That is some serious diagnostic quality improvement, kudos Chandler!
> That said I think we can get the same effect without storing extra source
> locations, I'll look into it more..

I'm not sure how, I tried 3 different approaches before settling on
that one. And I also don't think storing extra locations is a problem.
The only way I could measure a performance drop was to take an extreme
edge case for macro arguments (GCC's source), and to run it is -Eonly
mode. The moment I do something else, and the performance hit drops
beneath the noise floor. Especially on typical code.

I should have a benchmark today that clearly demonstrates this, and
then I'll check in the patch.

One thing to remember, while we might be able to conjure up the
diagnostic improvements, having the full information for each
direction of the macro expansion really helps the precision of
refactoring and rewriting tools in the presence of macro arguments. We
have cases where we need to re-write the contents of macro bodies,
etc., and this level of information really helps that.



More information about the cfe-commits mailing list