[PATCH] Improved handling of the naked attribute for MSVC compatibility

Aaron Ballman aaron at aaronballman.com
Sat May 4 08:02:31 PDT 2013


On Fri, May 3, 2013 at 6:43 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Fri, May 3, 2013 at 10:02 AM, Reid Kleckner <rnk at google.com> wrote:
>>
>> Cool!  There's two instances of trailing whitespace you'll want to fix.
>>
>> -  if (!isa<FunctionDecl>(D)) {
>> +  // Microsoft mode expects the naked attribute to only be applied to a
>> +  // function definition, or else it causes an error.  In non-Microsoft
>> mode,
>> +  // the attribute is allowed to be attached to a function definition or
>> is
>> +  // otherwise warned about.
>> +  //
>> +  // Because the attribute is handled before the function body is parsed,
>> try
>> +  // to use the Declarator to determine whether this is a function
>> definition
>> +  // or not.
>> +  bool IsFunctionDecl = isa<FunctionDecl>(D);
>> +  if (S.LangOpts.MicrosoftMode &&
>> +      (!IsFunctionDecl || (PD && !PD->isFunctionDefinition()))) {
>>
>> I'm trying to find a way to avoid passing the Declarator through to
>> here, but I assume you've looked and I can't find anything either...
>> All of the definition-related checks rely on Body which isn't set
>> until the body parsing is finished.
>>
>> If it were a TagDecl we could say 'D->isBeingDefined()', but for
>> functions it looks like we haven't needed that.  Maybe it's worth
>> adding a IsDefinition or BeingDefined bit to FunctionDecl?  Would
>> anyone else find that useful or is it a bad idea?
>
>
> This seems reasonable to me, although I'm not sure how generally useful it
> would be.

Do you think it would be a better approach than the current one given
the lack of general usefulness?

~Aaron



More information about the cfe-commits mailing list