[cfe-commits] [Patch] Support for __thiscall
Douglas Gregor
dgregor at apple.com
Mon May 17 22:54:52 PDT 2010
Hi Steven,
On May 15, 2010, at 8:29 PM, Steven Watanabe wrote:
> AMDG
>
> Anton Korobeynikov wrote:
>>> The attached patch adds support for Microsoft's __thiscall
>>> keyword.
>>>
>> Patch itself looks ok, but before it can be committed, thiscall CC
>> should be implemented in LLVM.
>> Otherwise the code will be silently miscompiled (and no error will be
>> produced as now).
>>
>
> There was one bug in my previous patch, which caused it to ignore thiscall.
> Here's an updated patch.
This generally looks very good. Could you write a test case that verifies that the __thiscall keyword/attribute gets from the source all the way down to LLVM IR?
- Doug
>
> In Christ,
> Steven Watanabe
>
> Index: tools/clang/include/clang/Basic/TokenKinds.def
> ===================================================================
> --- tools/clang/include/clang/Basic/TokenKinds.def (revision 103897)
> +++ tools/clang/include/clang/Basic/TokenKinds.def (working copy)
> @@ -336,6 +336,7 @@
> KEYWORD(__cdecl , KEYALL)
> KEYWORD(__stdcall , KEYALL)
> KEYWORD(__fastcall , KEYALL)
> +KEYWORD(__thiscall , KEYALL)
> KEYWORD(__forceinline , KEYALL)
>
> // Altivec Extension.
> @@ -372,6 +373,7 @@
> ALIAS("_cdecl" , __cdecl , KEYMS)
> ALIAS("_fastcall" , __fastcall , KEYMS)
> ALIAS("_stdcall" , __stdcall , KEYMS)
> +ALIAS("_thiscall" , __thiscall , KEYMS)
>
> //===----------------------------------------------------------------------===//
> // Objective-C @-preceeded keywords.
> Index: tools/clang/include/clang/AST/Attr.h
> ===================================================================
> --- tools/clang/include/clang/AST/Attr.h (revision 103897)
> +++ tools/clang/include/clang/AST/Attr.h (working copy)
> @@ -86,6 +86,7 @@
> Section,
> Sentinel,
> StdCall,
> + ThisCall,
> TransparentUnion,
> Unavailable,
> Unused,
> @@ -457,6 +458,7 @@
>
> DEF_SIMPLE_ATTR(FastCall);
> DEF_SIMPLE_ATTR(StdCall);
> +DEF_SIMPLE_ATTR(ThisCall);
> DEF_SIMPLE_ATTR(CDecl);
> DEF_SIMPLE_ATTR(TransparentUnion);
> DEF_SIMPLE_ATTR(ObjCNSObject);
> Index: tools/clang/include/clang/AST/Type.h
> ===================================================================
> --- tools/clang/include/clang/AST/Type.h (revision 103897)
> +++ tools/clang/include/clang/AST/Type.h (working copy)
> @@ -396,7 +396,8 @@
> CC_Default,
> CC_C, // __attribute__((cdecl))
> CC_X86StdCall, // __attribute__((stdcall))
> - CC_X86FastCall // __attribute__((fastcall))
> + CC_X86FastCall, // __attribute__((fastcall))
> + CC_X86ThisCall // __attribute__((thiscall))
> };
>
>
> @@ -1754,7 +1755,7 @@
> unsigned RegParm : 3;
>
> /// CallConv - The calling convention used by the function.
> - unsigned CallConv : 2;
> + unsigned CallConv : 3;
>
> // The type returned by the function.
> QualType ResultType;
> @@ -1822,7 +1823,7 @@
> // The value passed to __attribute__((regparm(x)))
> unsigned RegParm;
> // The calling convention as specified via
> - // __attribute__((cdecl|stdcall||fastcall))
> + // __attribute__((cdecl|stdcall|fastcall|thiscall))
> CallingConv CC;
> };
>
> Index: tools/clang/include/clang/Parse/AttributeList.h
> ===================================================================
> --- tools/clang/include/clang/Parse/AttributeList.h (revision 103897)
> +++ tools/clang/include/clang/Parse/AttributeList.h (working copy)
> @@ -102,6 +102,7 @@
> AT_section,
> AT_sentinel,
> AT_stdcall,
> + AT_thiscall,
> AT_transparent_union,
> AT_unavailable,
> AT_unused,
> Index: tools/clang/lib/Frontend/PCHReaderDecl.cpp
> ===================================================================
> --- tools/clang/lib/Frontend/PCHReaderDecl.cpp (revision 103897)
> +++ tools/clang/lib/Frontend/PCHReaderDecl.cpp (working copy)
> @@ -763,6 +763,7 @@
> UNSIGNED_ATTR(Regparm);
> STRING_ATTR(Section);
> SIMPLE_ATTR(StdCall);
> + SIMPLE_ATTR(ThisCall);
> SIMPLE_ATTR(TransparentUnion);
> SIMPLE_ATTR(Unavailable);
> SIMPLE_ATTR(Unused);
> Index: tools/clang/lib/Sema/SemaDeclAttr.cpp
> ===================================================================
> --- tools/clang/lib/Sema/SemaDeclAttr.cpp (revision 103897)
> +++ tools/clang/lib/Sema/SemaDeclAttr.cpp (working copy)
> @@ -1654,6 +1654,8 @@
> case AttributeList::AT_stdcall:
> d->addAttr(::new (S.Context) StdCallAttr());
> return;
> + case AttributeList::AT_thiscall:
> + d->addAttr(::new (S.Context) ThisCallAttr());
> case AttributeList::AT_cdecl:
> d->addAttr(::new (S.Context) CDeclAttr());
> return;
> @@ -1950,6 +1952,7 @@
> case AttributeList::AT_stdcall:
> case AttributeList::AT_cdecl:
> case AttributeList::AT_fastcall:
> + case AttributeList::AT_thiscall:
> HandleCallConvAttr(D, Attr, S);
> break;
> default:
> Index: tools/clang/lib/Sema/SemaType.cpp
> ===================================================================
> --- tools/clang/lib/Sema/SemaType.cpp (revision 103897)
> +++ tools/clang/lib/Sema/SemaType.cpp (working copy)
> @@ -1815,6 +1815,7 @@
> case AttributeList::AT_cdecl: CC = CC_C; break;
> case AttributeList::AT_fastcall: CC = CC_X86FastCall; break;
> case AttributeList::AT_stdcall: CC = CC_X86StdCall; break;
> + case AttributeList::AT_thiscall: CC = CC_X86ThisCall; break;
> default: llvm_unreachable("unexpected attribute kind"); return false;
> }
>
> @@ -1939,6 +1940,7 @@
> case AttributeList::AT_cdecl:
> case AttributeList::AT_fastcall:
> case AttributeList::AT_stdcall:
> + case AttributeList::AT_thiscall:
> case AttributeList::AT_regparm:
> // Don't process these on the DeclSpec.
> if (IsDeclSpec ||
> Index: tools/clang/lib/AST/Type.cpp
> ===================================================================
> --- tools/clang/lib/AST/Type.cpp (revision 103897)
> +++ tools/clang/lib/AST/Type.cpp (working copy)
> @@ -919,6 +919,7 @@
> case CC_C: return "cdecl";
> case CC_X86StdCall: return "stdcall";
> case CC_X86FastCall: return "fastcall";
> + case CC_X86ThisCall: return "thiscall";
> }
> }
>
> Index: tools/clang/lib/AST/TypePrinter.cpp
> ===================================================================
> --- tools/clang/lib/AST/TypePrinter.cpp (revision 103897)
> +++ tools/clang/lib/AST/TypePrinter.cpp (working copy)
> @@ -295,6 +295,9 @@
> case CC_X86FastCall:
> S += " __attribute__((fastcall))";
> break;
> + case CC_X86ThisCall:
> + S += " __attribute__((thiscall))";
> + break;
> }
> if (Info.getNoReturn())
> S += " __attribute__((noreturn))";
> Index: tools/clang/lib/AST/AttrImpl.cpp
> ===================================================================
> --- tools/clang/lib/AST/AttrImpl.cpp (revision 103897)
> +++ tools/clang/lib/AST/AttrImpl.cpp (working copy)
> @@ -100,6 +100,7 @@
> DEF_SIMPLE_ATTR_CLONE(Packed)
> DEF_SIMPLE_ATTR_CLONE(Pure)
> DEF_SIMPLE_ATTR_CLONE(StdCall)
> +DEF_SIMPLE_ATTR_CLONE(ThisCall)
> DEF_SIMPLE_ATTR_CLONE(TransparentUnion)
> DEF_SIMPLE_ATTR_CLONE(Unavailable)
> DEF_SIMPLE_ATTR_CLONE(Unused)
> Index: tools/clang/lib/CodeGen/CGCall.cpp
> ===================================================================
> --- tools/clang/lib/CodeGen/CGCall.cpp (revision 103897)
> +++ tools/clang/lib/CodeGen/CGCall.cpp (working copy)
> @@ -38,6 +38,7 @@
> default: return llvm::CallingConv::C;
> case CC_X86StdCall: return llvm::CallingConv::X86_StdCall;
> case CC_X86FastCall: return llvm::CallingConv::X86_FastCall;
> + case CC_X86ThisCall: return llvm::CallingConv::X86_ThisCall;
> }
> }
>
> @@ -97,6 +98,9 @@
> if (D->hasAttr<FastCallAttr>())
> return CC_X86FastCall;
>
> + if (D->hasAttr<ThisCallAttr>())
> + return CC_X86ThisCall;
> +
> return CC_C;
> }
>
> Index: tools/clang/lib/Parse/ParseTentative.cpp
> ===================================================================
> --- tools/clang/lib/Parse/ParseTentative.cpp (revision 103897)
> +++ tools/clang/lib/Parse/ParseTentative.cpp (working copy)
> @@ -753,6 +753,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> case tok::kw___w64:
> case tok::kw___ptr64:
> case tok::kw___forceinline:
> Index: tools/clang/lib/Parse/AttributeList.cpp
> ===================================================================
> --- tools/clang/lib/Parse/AttributeList.cpp (revision 103897)
> +++ tools/clang/lib/Parse/AttributeList.cpp (working copy)
> @@ -119,5 +119,6 @@
> .Case("cf_returns_retained", AT_cf_returns_retained)
> .Case("reqd_work_group_size", AT_reqd_wg_size)
> .Case("no_instrument_function", AT_no_instrument_function)
> + .Case("thiscall", AT_thiscall)
> .Default(UnknownAttribute);
> }
> Index: tools/clang/lib/Parse/ParseDecl.cpp
> ===================================================================
> --- tools/clang/lib/Parse/ParseDecl.cpp (revision 103897)
> +++ tools/clang/lib/Parse/ParseDecl.cpp (working copy)
> @@ -277,8 +277,8 @@
> // Treat these like attributes
> // FIXME: Allow Sema to distinguish between these and real attributes!
> while (Tok.is(tok::kw___fastcall) || Tok.is(tok::kw___stdcall) ||
> - Tok.is(tok::kw___cdecl) || Tok.is(tok::kw___ptr64) ||
> - Tok.is(tok::kw___w64)) {
> + Tok.is(tok::kw___thiscall) || Tok.is(tok::kw___cdecl) ||
> + Tok.is(tok::kw___ptr64) || Tok.is(tok::kw___w64)) {
> IdentifierInfo *AttrName = Tok.getIdentifierInfo();
> SourceLocation AttrNameLoc = ConsumeToken();
> if (Tok.is(tok::kw___ptr64) || Tok.is(tok::kw___w64))
> @@ -1143,6 +1143,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> DS.AddAttributes(ParseMicrosoftTypeAttributes());
> continue;
>
> @@ -1622,6 +1623,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> DS.AddAttributes(ParseMicrosoftTypeAttributes());
> return true;
>
> @@ -2198,6 +2200,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> case tok::kw___w64:
> case tok::kw___ptr64:
> return true;
> @@ -2304,6 +2307,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> case tok::kw___w64:
> case tok::kw___ptr64:
> case tok::kw___forceinline:
> @@ -2401,6 +2405,7 @@
> case tok::kw___cdecl:
> case tok::kw___stdcall:
> case tok::kw___fastcall:
> + case tok::kw___thiscall:
> if (GNUAttributesAllowed) {
> DS.AddAttributes(ParseMicrosoftTypeAttributes());
> continue;
> @@ -2785,8 +2790,8 @@
> }
> // Eat any Microsoft extensions.
> if (Tok.is(tok::kw___cdecl) || Tok.is(tok::kw___stdcall) ||
> - Tok.is(tok::kw___fastcall) || Tok.is(tok::kw___w64) ||
> - Tok.is(tok::kw___ptr64)) {
> + Tok.is(tok::kw___thiscall) || Tok.is(tok::kw___fastcall) ||
> + Tok.is(tok::kw___w64) || Tok.is(tok::kw___ptr64)) {
> AttrList.reset(ParseMicrosoftTypeAttributes(AttrList.take()));
> }
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list