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

llvm-svn: 198355
This commit is contained in:
Aaron Ballman 2014-01-02 21:26:14 +00:00
parent decb024c86
commit 05e420abad
11 changed files with 42 additions and 34 deletions

View File

@ -1804,9 +1804,9 @@ def err_attribute_wrong_number_arguments : Error<
"%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">;

View File

@ -211,7 +211,8 @@ static bool checkAttributeNumArgs(Sema &S, const AttributeList &Attr,
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, Decl *D, const AttributeList &AL) {
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 *D, const AttributeList &Attr) {
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 &S, Decl *D, const AttributeList &Attr) {
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 &S, Decl *D,
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, Decl *D, const AttributeList &Attr) {
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 &S, Decl *D,
// 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;
}

View File

@ -31,7 +31,7 @@ static void HandleARMInterruptAttr(Decl *d,
// Check the attribute arguments.
if (Attr.getNumArgs() > 1) {
S.Diag(Attr.getLoc(), diag::err_attribute_too_many_arguments)
<< 1;
<< Attr.getName() << 1;
return;
}

View File

@ -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() {}

View File

@ -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}}

View File

@ -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}}

View File

@ -5,7 +5,7 @@ void f1(int a, ...) __attribute__ ((sentinel));
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}}

View File

@ -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}}

View File

@ -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}}

View File

@ -446,12 +446,12 @@ int * pgb_var_arg_bad_4 PT_GUARDED_BY(umu); // \
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_AFTER(mu_aa); // \
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_FUNCTION(0); // \
// 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_TRYLOCK_FUNCTION(1, umu); // \
// 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(umu); // \
// 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(umu); // \
// 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_REQUIRED(umu); // \
// 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);

View File

@ -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