[PATCH] Add support for __declspec(thread) under -fms-extensions
Reid Kleckner
rnk at google.com
Tue Apr 29 15:08:32 PDT 2014
On Tue, Apr 29, 2014 at 1:11 PM, Aaron Ballman <aaron at aaronballman.com>wrote:
>
> > +def Thread : InheritableAttr {
> > + let Spellings = [Declspec<"thread">];
> > + let LangOpts = [MicrosoftExt];
> > + let Documentation = [Undocumented];
>
> Please document this attribute (it's fine to punt on most of it and
> simply point to MSDN).
>
Grumble grumble fine. ;)
> > +static void handleDeclspecThreadAttr(Sema &S, Decl *D,
> > + const AttributeList &Attr) {
> > + VarDecl *VD = cast<VarDecl>(D);
> > + if (VD->getTSCSpec() != TSCS_unspecified) {
> > + S.Diag(Attr.getLoc(), diag::err_multiple_thread_specifiers);
> > + return;
> > + }
>
> Looking at MSDN, don't we need to check more semantics? For instance,
> the linkage:
>
> "You can specify the thread attribute only on data items with static
> storage duration. This includes global data objects (both static and
> extern), local static objects, and static data members of classes. You
> cannot declare automatic data objects with the thread attribute."
>
> Also, if the type is a class, it needs to be POD (also according to MSDN).
>
Done. MSVC actually checks for, "does this class have any ctors or dtors",
not POD-ness. I tried to soften that to cover just the cases where we'd
have to emit dynamic initialization due to a constructor.
> > Index: test/SemaCXX/declspec-thread.cpp
> > ===================================================================
> > --- /dev/null
> > +++ test/SemaCXX/declspec-thread.cpp
> > @@ -0,0 +1,8 @@
> > +// RUN: %clang_cc1 -fms-extensions -verify %s
> > +
> > +__thread __declspec(thread) int a; // expected-error {{already has a
> thread specifier}}
> > +__declspec(thread) __thread int b; // expected-error {{already has a
> thread specifier}}
> > +__declspec(thread) int c(); // expected-warning {{only applies to
> variables}}
> > +__declspec(thread) int d;
> > +int foo();
> > +__declspec(thread) int e = foo(); // expected-error {{must be a
> constant expression}}
> >
>
> What about cases where redeclarations have a mismatched specifier?
> (That's in addition to a test case for a non-POD test, and a
> non-static storage duration.) I'd also like to see a test case where
> __declspec(thread) shouldn't belong in the declaration (such as in a
> typedef), and accepting parameters (just so we don't accidentally
> break that in the future).
>
Woops, gotta add that. Will send a new patch.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140429/4d6ada39/attachment.html>
More information about the cfe-commits
mailing list