This patch fixes the parsing of thread-safety attributes so that empty
attribute lists are allowed, e.g.
 __attribute__((unlock_function())) is allowed, and is the same
as__attribute__((unlock_function)).
This fix is necessary to use existing macros and header files with the
attributes.

   http://codereview.appspot.com/5483083/

   -DeLesley

-- 
DeLesley Hutchins | Software Engineer | [email protected] | 505-206-0315
From 332423e31e3d495c91d2daa77a50f3a924d92b6a Mon Sep 17 00:00:00 2001
From: DeLesley Hutchins <[email protected]>
Date: Wed, 14 Dec 2011 11:07:19 -0800
Subject: [PATCH] Allow empty argument lists in thread safety attributes

---
 lib/Parse/ParseDecl.cpp                     |    4 ++--
 test/SemaCXX/warn-thread-safety-parsing.cpp |    9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 0c5a487..658d5fe 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -829,7 +829,7 @@ void Parser::ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
   bool ArgExprsOk = true;
   
   // now parse the list of expressions
-  while (1) {
+  while (Tok.isNot(tok::r_paren)) {
     ExprResult ArgExpr(ParseAssignmentExpression());
     if (ArgExpr.isInvalid()) {
       ArgExprsOk = false;
@@ -843,7 +843,7 @@ void Parser::ParseThreadSafetyAttribute(IdentifierInfo &AttrName,
     ConsumeToken(); // Eat the comma, move to the next argument
   }
   // Match the ')'.
-  if (ArgExprsOk && !T.consumeClose()) {
+  if (ArgExprsOk && !T.consumeClose() && ArgExprs.size() > 0) {
     Attrs.addNew(&AttrName, AttrNameLoc, 0, AttrNameLoc, 0, SourceLocation(),
                  ArgExprs.take(), ArgExprs.size());
   }
diff --git a/test/SemaCXX/warn-thread-safety-parsing.cpp b/test/SemaCXX/warn-thread-safety-parsing.cpp
index 67882d0..b243365 100644
--- a/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ b/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -1253,3 +1253,12 @@ public:
   Mu mu;
 };
 
+//-------------------------
+// Empty argument lists
+//-------------------------
+
+class __attribute__((lockable)) EmptyArgListsTest {
+  void lock() __attribute__((exclusive_lock_function())) { }
+  void unlock() __attribute__((unlock_function())) { }
+};
+
-- 
1.7.3.1

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to