r198355 - Updated the wording of two attribute-related diagnostics so that they print the offending attribute name. Also updates the associated test cases.

Aaron Ballman aaron at aaronballman.com
Thu Jan 2 13:26:14 PST 2014


Author: aaronballman
Date: Thu Jan  2 15:26:14 2014
New Revision: 198355

URL: http://llvm.org/viewvc/llvm-project?rev=198355&view=rev
Log:
Updated the wording of two attribute-related diagnostics so that they print the offending attribute name. Also updates the associated test cases.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/lib/Sema/TargetAttributesSema.cpp
    cfe/trunk/test/Sema/arm-interrupt-attr.c
    cfe/trunk/test/Sema/attr-ownership.c
    cfe/trunk/test/Sema/constructor-attribute.c
    cfe/trunk/test/Sema/sentinel-attribute.c
    cfe/trunk/test/SemaCUDA/launch_bounds.cu
    cfe/trunk/test/SemaCXX/warn-consumed-parsing.cpp
    cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp
    cfe/trunk/test/SemaObjC/method-sentinel-attr.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan  2 15:26:14 2014
@@ -1804,9 +1804,9 @@ def err_attribute_wrong_number_arguments
   "%0 attribute %plural{0:takes no arguments|1:takes one argument|"
   ":requires exactly %1 arguments}1">;
 def err_attribute_too_many_arguments : Error<
-  "attribute takes no more than %0 argument%s0">;
+  "%0 attribute takes no more than %1 argument%s1">;
 def err_attribute_too_few_arguments : Error<
-  "attribute takes at least %0 argument%s0">;
+  "%0 attribute takes at least %1 argument%s1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type %0">;
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jan  2 15:26:14 2014
@@ -211,7 +211,8 @@ static bool checkAttributeNumArgs(Sema &
 static bool checkAttributeAtLeastNumArgs(Sema &S, const AttributeList &Attr,
                                          unsigned Num) {
   if (getNumAttributeArgs(Attr) < Num) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_few_arguments) << Num;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_few_arguments)
+      << Attr.getName() << Num;
     return false;
   }
 
@@ -1264,13 +1265,15 @@ static void handleOwnershipAttr(Sema &S,
   case OwnershipAttr::Takes:
   case OwnershipAttr::Holds:
     if (AL.getNumArgs() < 2) {
-      S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments) << 2;
+      S.Diag(AL.getLoc(), diag::err_attribute_too_few_arguments)
+        << AL.getName() << 2;
       return;
     }
     break;
   case OwnershipAttr::Returns:
     if (AL.getNumArgs() > 2) {
-      S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+      S.Diag(AL.getLoc(), diag::err_attribute_too_many_arguments)
+        << AL.getName() << 1;
       return;
     }
     break;
@@ -1639,7 +1642,8 @@ static void handleUsedAttr(Sema &S, Decl
 static void handleConstructorAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   // check the attribute arguments.
   if (Attr.getNumArgs() > 1) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
+      << Attr.getName() << 1;
     return;
   }
 
@@ -1656,7 +1660,8 @@ static void handleConstructorAttr(Sema &
 static void handleDestructorAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   // check the attribute arguments.
   if (Attr.getNumArgs() > 1) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
+      << Attr.getName() << 1;
     return;
   }
 
@@ -1675,7 +1680,8 @@ static void handleAttrWithMessage(Sema &
                                   const AttributeList &Attr) {
   unsigned NumArgs = Attr.getNumArgs();
   if (NumArgs > 1) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 1;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
+      << Attr.getName() << 1;
     return;
   }
 
@@ -2079,7 +2085,8 @@ static void handleBlocksAttr(Sema &S, De
 static void handleSentinelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   // check the attribute arguments.
   if (Attr.getNumArgs() > 2) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 2;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
+      << Attr.getName() << 2;
     return;
   }
 
@@ -3284,7 +3291,8 @@ static void handleLaunchBoundsAttr(Sema
   // check the attribute arguments.
   if (Attr.getNumArgs() != 1 && Attr.getNumArgs() != 2) {
     // FIXME: 0 is not okay.
-    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments) << 2;
+    S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
+      << Attr.getName() << 2;
     return;
   }
 

Modified: cfe/trunk/lib/Sema/TargetAttributesSema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TargetAttributesSema.cpp?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TargetAttributesSema.cpp (original)
+++ cfe/trunk/lib/Sema/TargetAttributesSema.cpp Thu Jan  2 15:26:14 2014
@@ -31,7 +31,7 @@ static void HandleARMInterruptAttr(Decl
   // Check the attribute arguments.
   if (Attr.getNumArgs() > 1) {
     S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
-        << 1;
+      << Attr.getName() << 1;
     return;
   }
 

Modified: cfe/trunk/test/Sema/arm-interrupt-attr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arm-interrupt-attr.c?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/Sema/arm-interrupt-attr.c (original)
+++ cfe/trunk/test/Sema/arm-interrupt-attr.c Thu Jan  2 15:26:14 2014
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
 
-__attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' attribute requires a string}} 
+__attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' attribute requires a string}}
 __attribute__((interrupt("irq"))) void foo1() {} // expected-warning {{'interrupt' attribute argument not supported: irq}}
 
-__attribute__((interrupt("IRQ", 1))) void foo2() {} // expected-error {{attribute takes no more than 1 argument}}
+__attribute__((interrupt("IRQ", 1))) void foo2() {} // expected-error {{'interrupt' attribute takes no more than 1 argument}}
 
 __attribute__((interrupt("IRQ"))) void foo3() {}
 __attribute__((interrupt("FIQ"))) void foo4() {}

Modified: cfe/trunk/test/Sema/attr-ownership.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-ownership.c?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-ownership.c (original)
+++ cfe/trunk/test/Sema/attr-ownership.c Thu Jan  2 15:26:14 2014
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 %s -verify
 
 void f1(void) __attribute__((ownership_takes("foo"))); // expected-error {{'ownership_takes' attribute requires parameter 1 to be an identifier}}
-void *f2(void) __attribute__((ownership_returns(foo, 1, 2)));  // expected-error {{attribute takes no more than 1 argument}}
+void *f2(void) __attribute__((ownership_returns(foo, 1, 2)));  // expected-error {{'ownership_returns' attribute takes no more than 1 argument}}
 void f3(void) __attribute__((ownership_holds(foo, 1))); // expected-error {{'ownership_holds' attribute parameter 1 is out of bounds}}
 void *f4(void) __attribute__((ownership_returns(foo)));
-void f5(void) __attribute__((ownership_holds(foo)));  // expected-error {{attribute takes at least 2 arguments}}
+void f5(void) __attribute__((ownership_holds(foo)));  // expected-error {{'ownership_holds' attribute takes at least 2 arguments}}
 void f6(void) __attribute__((ownership_holds(foo, 1, 2, 3)));  // expected-error {{'ownership_holds' attribute parameter 1 is out of bounds}}
-void f7(void) __attribute__((ownership_takes(foo)));  // expected-error {{attribute takes at least 2 arguments}}
+void f7(void) __attribute__((ownership_takes(foo)));  // expected-error {{'ownership_takes' attribute takes at least 2 arguments}}
 void f8(int *i, int *j, int k) __attribute__((ownership_holds(foo, 1, 2, 4)));  // expected-error {{'ownership_holds' attribute parameter 3 is out of bounds}}
 
 int f9 __attribute__((ownership_takes(foo, 1)));  // expected-warning {{'ownership_takes' attribute only applies to functions}}

Modified: cfe/trunk/test/Sema/constructor-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constructor-attribute.c?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constructor-attribute.c (original)
+++ cfe/trunk/test/Sema/constructor-attribute.c Thu Jan  2 15:26:14 2014
@@ -3,13 +3,13 @@
 int x __attribute__((constructor)); // expected-warning {{'constructor' attribute only applies to functions}}
 int f() __attribute__((constructor));
 int f() __attribute__((constructor(1)));
-int f() __attribute__((constructor(1,2))); // expected-error {{attribute takes no more than 1 argument}}
+int f() __attribute__((constructor(1,2))); // expected-error {{'constructor' attribute takes no more than 1 argument}}
 int f() __attribute__((constructor(1.0))); // expected-error {{'constructor' attribute requires an integer constant}}
 
 int x __attribute__((destructor)); // expected-warning {{'destructor' attribute only applies to functions}}
 int f() __attribute__((destructor));
 int f() __attribute__((destructor(1)));
-int f() __attribute__((destructor(1,2))); // expected-error {{attribute takes no more than 1 argument}}
+int f() __attribute__((destructor(1,2))); // expected-error {{'destructor' attribute takes no more than 1 argument}}
 int f() __attribute__((destructor(1.0))); // expected-error {{'destructor' attribute requires an integer constant}}
 
 

Modified: cfe/trunk/test/Sema/sentinel-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/sentinel-attribute.c?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/Sema/sentinel-attribute.c (original)
+++ cfe/trunk/test/Sema/sentinel-attribute.c Thu Jan  2 15:26:14 2014
@@ -5,7 +5,7 @@ void f1(int a, ...) __attribute__ ((sent
 void f2(int a, ...) __attribute__ ((sentinel(1)));
 
 void f3(int a, ...) __attribute__ ((sentinel("hello"))); //expected-error{{'sentinel' attribute requires parameter 1 to be an integer constant}}
-void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{attribute takes no more than 2 arguments}}
+void f4(int a, ...) __attribute__ ((sentinel(1, 2, 3))); //expected-error{{'sentinel' attribute takes no more than 2 arguments}}
 void f4(int a, ...) __attribute__ ((sentinel(-1))); //expected-error{{parameter 1 less than zero}}
 void f4(int a, ...) __attribute__ ((sentinel(0, 2))); // expected-error{{parameter 2 not 0 or 1}}
 

Modified: cfe/trunk/test/SemaCUDA/launch_bounds.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/launch_bounds.cu?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/SemaCUDA/launch_bounds.cu (original)
+++ cfe/trunk/test/SemaCUDA/launch_bounds.cu Thu Jan  2 15:26:14 2014
@@ -5,10 +5,10 @@
 __launch_bounds__(128, 7) void Test1(void);
 __launch_bounds__(128) void Test2(void);
 
-__launch_bounds__(1, 2, 3) void Test3(void); // expected-error {{attribute takes no more than 2 arguments}}
+__launch_bounds__(1, 2, 3) void Test3(void); // expected-error {{'launch_bounds' attribute takes no more than 2 arguments}}
 
 // FIXME: the error should read that the attribute takes exactly one or two arguments, but there
 // is no support for such a diagnostic currently.
-__launch_bounds__() void Test4(void); // expected-error {{attribute takes no more than 2 arguments}}
+__launch_bounds__() void Test4(void); // expected-error {{'launch_bounds' attribute takes no more than 2 arguments}}
 
 int Test5 __launch_bounds__(128, 7); // expected-warning {{'launch_bounds' attribute only applies to functions and methods}}

Modified: cfe/trunk/test/SemaCXX/warn-consumed-parsing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-parsing.cpp?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-consumed-parsing.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-consumed-parsing.cpp Thu Jan  2 15:26:14 2014
@@ -17,9 +17,9 @@ int returnTypestateForUnconsumable() {
 }
 
 class AttrTester0 {
-  void consumes()       __attribute__ ((set_typestate())); // expected-error {{attribute takes one argument}}
-  bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{attribute takes one argument}}
-  void callableWhen()   __attribute__ ((callable_when())); // expected-error {{attribute takes at least 1 argument}}
+  void consumes()       __attribute__ ((set_typestate())); // expected-error {{'set_typestate' attribute takes one argument}}
+  bool testUnconsumed() __attribute__ ((test_typestate())); // expected-error {{'test_typestate' attribute takes one argument}}
+  void callableWhen()   __attribute__ ((callable_when())); // expected-error {{'callable_when' attribute takes at least 1 argument}}
 };
 
 int var0 SET_TYPESTATE(consumed); // expected-warning {{'set_typestate' attribute only applies to methods}}

Modified: cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-thread-safety-parsing.cpp Thu Jan  2 15:26:14 2014
@@ -446,12 +446,12 @@ int * pgb_var_arg_bad_4 PT_GUARDED_BY(um
 Mutex mu_aa ACQUIRED_AFTER(mu1);
 
 Mutex aa_var_noargs __attribute__((acquired_after)); // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'acquired_after' attribute takes at least 1 argument}}
 
 class AAFoo {
  private:
   Mutex aa_field_noargs __attribute__((acquired_after)); // \
-    // expected-error {{attribute takes at least 1 argument}}
+    // expected-error {{'acquired_after' attribute takes at least 1 argument}}
   Mutex aa_field_args ACQUIRED_AFTER(mu1);
 };
 
@@ -506,12 +506,12 @@ UnlockableMu aa_var_arg_bad_5 ACQUIRED_A
 Mutex mu_ab ACQUIRED_BEFORE(mu1);
 
 Mutex ab_var_noargs __attribute__((acquired_before)); // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'acquired_before' attribute takes at least 1 argument}}
 
 class ABFoo {
  private:
   Mutex ab_field_noargs __attribute__((acquired_before)); // \
-    // expected-error {{attribute takes at least 1 argument}}
+    // expected-error {{'acquired_before' attribute takes at least 1 argument}}
   Mutex ab_field_args ACQUIRED_BEFORE(mu1);
 };
 
@@ -715,7 +715,7 @@ int slf_function_bad_7() SHARED_LOCK_FUN
 // plus an optional list of locks (vars/fields)
 
 void etf_function() __attribute__((exclusive_trylock_function));  // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'exclusive_trylock_function' attribute takes at least 1 argument}}
 
 void etf_function_args() EXCLUSIVE_TRYLOCK_FUNCTION(1, mu2);
 
@@ -788,7 +788,7 @@ int etf_function_bad_6() EXCLUSIVE_TRYLO
 // plus an optional list of locks (vars/fields)
 
 void stf_function() __attribute__((shared_trylock_function));  // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'shared_trylock_function' attribute takes at least 1 argument}}
 
 void stf_function_args() SHARED_TRYLOCK_FUNCTION(1, mu2);
 
@@ -1001,7 +1001,7 @@ int lr_function_bad_4() LOCK_RETURNED(um
 // takes one or more arguments, all locks (vars/fields)
 
 void le_function() __attribute__((locks_excluded)); // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'locks_excluded' attribute takes at least 1 argument}}
 
 void le_function_arg() LOCKS_EXCLUDED(mu1);
 
@@ -1068,7 +1068,7 @@ int le_function_bad_4() LOCKS_EXCLUDED(u
 // takes one or more arguments, all locks (vars/fields)
 
 void elr_function() __attribute__((exclusive_locks_required)); // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'exclusive_locks_required' attribute takes at least 1 argument}}
 
 void elr_function_arg() EXCLUSIVE_LOCKS_REQUIRED(mu1);
 
@@ -1136,7 +1136,7 @@ int elr_function_bad_4() EXCLUSIVE_LOCKS
 // takes one or more arguments, all locks (vars/fields)
 
 void slr_function() __attribute__((shared_locks_required)); // \
-  // expected-error {{attribute takes at least 1 argument}}
+  // expected-error {{'shared_locks_required' attribute takes at least 1 argument}}
 
 void slr_function_arg() SHARED_LOCKS_REQUIRED(mu1);
 

Modified: cfe/trunk/test/SemaObjC/method-sentinel-attr.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-sentinel-attr.m?rev=198355&r1=198354&r2=198355&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-sentinel-attr.m (original)
+++ cfe/trunk/test/SemaObjC/method-sentinel-attr.m Thu Jan  2 15:26:14 2014
@@ -13,7 +13,7 @@
 - (void) foo8 : (int)x, ... __attribute__ ((__sentinel__("a")));  // expected-error {{'__sentinel__' attribute requires parameter 1 to be an integer constant}}
 - (void) foo9 : (int)x, ... __attribute__ ((__sentinel__(-1)));  // expected-error {{'sentinel' parameter 1 less than zero}}
 - (void) foo10 : (int)x, ... __attribute__ ((__sentinel__(1,1)));
-- (void) foo11 : (int)x, ... __attribute__ ((__sentinel__(1,1,3)));  // expected-error {{attribute takes no more than 2 arguments}}
+- (void) foo11 : (int)x, ... __attribute__ ((__sentinel__(1,1,3)));  // expected-error {{'__sentinel__' attribute takes no more than 2 arguments}}
 - (void) foo12 : (int)x, ... ATTR; // expected-note {{method has been explicitly marked sentinel here}}
 
 // rdar://7975788





More information about the cfe-commits mailing list