[cfe-dev] Thread Safety for C structs RFC.

Ethan Jackson ethan at nicira.com
Mon Jul 15 14:16:35 PDT 2013


Actually, I had one more question in this area.  Is there any reason
to only allow structs an classes to be lockable?  In C it would be
really clean to mark pthread_rwlock_t as lockable for example.  I know
in most (all?) implementations, this is a struct under the covers, but
I'm not sure if marking the underlying struct as lockable is portable
(or possible for that matter).

If you think it's reasonable, I'd be willing to write up a patch
supporting this (with unit tests of course).

Thoughts?
Ethan

On Sun, Jul 14, 2013 at 10:15 PM, Delesley Hutchins <delesley at google.com> wrote:
> Patch looks good to me.  Thanks!  All the thread safety test cases are
> in C++, so this was probably overlooked.  Please update
> warn-thread-safety-parsing with a test case.
>
>   -DeLesley
>
> 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)) {
>>      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
>
>
>
> --
> DeLesley Hutchins | Software Engineer | delesley at google.com | 505-206-0315



More information about the cfe-dev mailing list