[cfe-dev] Thread Safety for C structs RFC.
David Blaikie
dblaikie at gmail.com
Sun Jul 14 23:51:48 PDT 2013
On Sat, Jul 13, 2013 at 8:29 PM, Ethan Jackson <ethan at nicira.com> wrote:
> I'm in the process of evaluating using clang for the Open vSwitch project with
> hopes of taking advantage of its thread safety annotations. Unfortunately, on
> tot these annotations only work in C++ because it's only possible to declare C++
> classes and structs as "lockable". This simple patch appears to fix the issue
> (in my testing), but it's so trivial that I'm wondering if I've overlooked
> something. I don't know clang well, so any advice in this area would be
> appreciated.
>
> Thanks,
> Ethan Jackson
>
> ---
> lib/Sema/SemaDeclAttr.cpp | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
> index 4c18a33..dc1c75d 100644
> --- a/lib/Sema/SemaDeclAttr.cpp
> +++ b/lib/Sema/SemaDeclAttr.cpp
> @@ -584,8 +584,7 @@ static bool checkLockableAttrCommon(Sema &S, Decl *D,
> if (!checkAttributeNumArgs(S, Attr, 0))
> return false;
>
> - // FIXME: Lockable structs for C code.
> - if (!isa<CXXRecordDecl>(D)) {
> + if (!isa<CXXRecordDecl>(D) && !isa<RecordDecl>(D)) {
Before this is committed, though - you can just replace this with "if
(!isa<RecordDecl>(D))" I hope (please test/try this, of course), since
all CXXRecordDecls are RecordDecls. (& as Delesley mentioned - a test
case will be appropriate/necessary)
> S.Diag(Attr.getLoc(), diag::warn_thread_attribute_wrong_decl_type)
> << Attr.getName() << ThreadExpectedClassOrStruct;
> return false;
> --
> 1.7.9.5
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list