[PATCH] Pragma optimize on/off

Aaron Ballman aaron at aaronballman.com
Wed May 7 10:30:20 PDT 2014


On Wed, May 7, 2014 at 1:15 PM, Dario Domizioli
<dario.domizioli at gmail.com> wrote:
> Hi Aaron.
>
>> We don't usually use "malformed" in our diagnostic wordings (though it
>> does happen from time to time). I think "unexpected" is more
>> consistent.
>>
>> As for not having text to display, wouldn't it be possible to simply
>> pass in the text as-lexed (via PP.getSpelling())?
>
>
> Hm, good idea! The only problem is with a missing argument, in which case
> the next token is an end of line and the diagnostic would actually print a
> newline. So in the end I have split the diagnostic into two, one for the
> "missing argument" case and one for the "unexpected argument" case.

You could get away with a single diagnostic by using %select

def err_pragma_optimize_invalid_argument : Error<
  "%select{unexpected|missing}0 argument %select{'%1'|}0 to '#pragma
clang optimize'; "
  "expected 'on' or 'off'">;

Then you can issue the diagnostic with:

PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument)
<< 0 /* unexpected */ <<  PP.getSpelling(Tok);
PP.Diag(Tok.getLocation(), diag::err_pragma_optimize_invalid_argument)
<< 1 /* missing*/;

>
> New patch attached.

Patch LGTM, modulo Richard's comments about serialization (I worried
about the same thing, and my preference is for the patch to be
all-inclusive when feasible, but Richard is welcome to weigh in). I
have no strong opinions on whether it should be one diagnostic or two.

Thanks!

~Aaron



More information about the cfe-commits mailing list