<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 29, 2014 at 1:11 PM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> +def Thread : InheritableAttr {<br>
> + let Spellings = [Declspec<"thread">];<br>
> + let LangOpts = [MicrosoftExt];<br>
> + let Documentation = [Undocumented];<br>
<br>
Please document this attribute (it's fine to punt on most of it and<br>
simply point to MSDN).<br></blockquote><div><br></div><div>Grumble grumble fine. ;)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> +static void handleDeclspecThreadAttr(Sema &S, Decl *D,<br>
> + const AttributeList &Attr) {<br>
> + VarDecl *VD = cast<VarDecl>(D);<br>
> + if (VD->getTSCSpec() != TSCS_unspecified) {<br>
> + S.Diag(Attr.getLoc(), diag::err_multiple_thread_specifiers);<br>
> + return;<br>
> + }<br>
<br>
Looking at MSDN, don't we need to check more semantics? For instance,<br>
the linkage:<br>
<br>
"You can specify the thread attribute only on data items with static<br>
storage duration. This includes global data objects (both static and<br>
extern), local static objects, and static data members of classes. You<br>
cannot declare automatic data objects with the thread attribute."<br>
<br>
Also, if the type is a class, it needs to be POD (also according to MSDN).<br></blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> Index: test/SemaCXX/declspec-thread.cpp<br>
> ===================================================================<br>
> --- /dev/null<br>
> +++ test/SemaCXX/declspec-thread.cpp<br>
> @@ -0,0 +1,8 @@<br>
> +// RUN: %clang_cc1 -fms-extensions -verify %s<br>
> +<br>
> +__thread __declspec(thread) int a; // expected-error {{already has a thread specifier}}<br>
> +__declspec(thread) __thread int b; // expected-error {{already has a thread specifier}}<br>
> +__declspec(thread) int c(); // expected-warning {{only applies to variables}}<br>
> +__declspec(thread) int d;<br>
> +int foo();<br>
> +__declspec(thread) int e = foo(); // expected-error {{must be a constant expression}}<br>
><br>
<br>
What about cases where redeclarations have a mismatched specifier?<br>
(That's in addition to a test case for a non-POD test, and a<br>
non-static storage duration.) I'd also like to see a test case where<br>
__declspec(thread) shouldn't belong in the declaration (such as in a<br>
typedef), and accepting parameters (just so we don't accidentally<br>
break that in the future).<br></blockquote><div><br></div><div>Woops, gotta add that. Will send a new patch.</div></div></div></div>