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

Ethan Jackson ethan at nicira.com
Sat Jul 13 20:29:53 PDT 2013


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




More information about the cfe-dev mailing list