[cfe-commits] [PATCH][MSExtensions] Add support for __forceinline.

Michael Spencer bigcheesegs at gmail.com
Mon Jun 18 00:02:53 PDT 2012


On Sun, Jun 17, 2012 at 11:41 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Sun, Jun 17, 2012 at 11:30 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>> Hi,
>>
>> On Sun, Jun 17, 2012 at 8:47 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:
>>> This patch adds codegen support for __forceinline. __forceinline is a
>>> combination of the inline keyword and __attribute__((always_inline)).
>>
>> Should handleForceInlineAttr call FunctionDecl::setImplicitlyInline?
>> As implemented, the attribute seems to have the same semantic effect
>> as just __attribute__((always_inline)).
>
> Ah, I missed that you were calling SetFunctionSpecInline. That seems
> reasonable (I'd expected the full semantic effect of the attribute to
> be handled by handleForceInlineAttr). LGTM subject to a couple of
> pedantic whitespacey things:
>
> --- a/lib/Parse/ParseDecl.cpp
> +++ b/lib/Parse/ParseDecl.cpp
> @@ -2251,9 +2251,14 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
>       continue;
>
>     // Microsoft single token adornments.
> -    case tok::kw___forceinline:
> -      // FIXME: Add handling here!
> -      break;
> +    case tok::kw___forceinline: {
> +        isInvalid = DS.SetFunctionSpecInline(Loc, PrevSpec, DiagID);
> +        IdentifierInfo *AttrName = Tok.getIdentifierInfo();
> +        SourceLocation AttrNameLoc = ConsumeToken();
> +        DS.getAttributes().addNew(AttrName, AttrNameLoc, 0, AttrNameLoc, 0,
> +                     SourceLocation(), 0, 0, false);
> +      }
> +      continue;
>
> Convention in Clang is to only indent once after "case ...: {" (just
> like without the '{'), and to put the 'continue' inside the braces.
> I'd prefer the SourceLocation() lined up with the '(' on the previous
> line.
>
>
> --- a/lib/Sema/SemaDeclAttr.cpp
> +++ b/lib/Sema/SemaDeclAttr.cpp
> @@ -3888,6 +3888,13 @@ static void handlePortabilityAttr(Sema &S, Decl
> *D, const AttributeList &Attr) {
>     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
>  }
>
> +static void handleForceInlineAttr(Sema &S, Decl *D, const
> AttributeList &Attr) {
> +  if (S.LangOpts.MicrosoftExt) {
> +    D->addAttr(::new (S.Context) ForceInlineAttr(Attr.getRange(), S.Context));
> +  } else
> +    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
> +}
>
> No braces on the 'if' here.
>
> -- Richard

Thanks! Committed with fixes in r158653.

- Michael Spencer




More information about the cfe-commits mailing list