This diagnostic did not accept arguments, and did not have any test coverage. Parameterized the diagnostic, and made it more consistent with other attribute diagnostic wordings. Added test coverage.

Since this warning was generalized, it was also given a sensible warning group flag and the corresponding test was updated to reflect this.

llvm-svn: 198053
This commit is contained in:
Aaron Ballman 2013-12-26 17:07:49 +00:00
parent 213cf41a58
commit cedaaea691
4 changed files with 7 additions and 6 deletions

View File

@ -1838,8 +1838,9 @@ def err_attribute_argument_out_of_bounds : Error<
"%0 attribute parameter %1 is out of bounds">;
def err_attribute_uuid_malformed_guid : Error<
"uuid attribute contains a malformed GUID">;
def warn_nonnull_pointers_only : Warning<
"nonnull attribute only applies to pointer arguments">;
def warn_attribute_pointers_only : Warning<
"%0 attribute only applies to pointer arguments">,
InGroup<IgnoredAttributes>;
def err_attribute_pointers_only : Error<
"%0 attribute only applies to pointer arguments">;
def err_attribute_no_member_pointers : Error<

View File

@ -1194,8 +1194,8 @@ static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (!T->isAnyPointerType() && !T->isBlockPointerType()) {
// FIXME: Should also highlight argument in decl.
S.Diag(Attr.getLoc(), diag::warn_nonnull_pointers_only)
<< "nonnull" << Ex->getSourceRange();
S.Diag(Attr.getLoc(), diag::warn_attribute_pointers_only)
<< Attr.getName() << Ex->getSourceRange();
continue;
}

View File

@ -18,7 +18,7 @@ This test serves two purposes:
The list of warnings below should NEVER grow. It should gradually shrink to 0.
CHECK: Warnings without flags (133):
CHECK: Warnings without flags (132):
CHECK-NEXT: ext_delete_void_ptr_operand
CHECK-NEXT: ext_expected_semi_decl_list
CHECK-NEXT: ext_explicit_specialization_storage_class
@ -97,7 +97,6 @@ CHECK-NEXT: warn_missing_exception_specification
CHECK-NEXT: warn_missing_whitespace_after_macro_name
CHECK-NEXT: warn_multiple_method_decl
CHECK-NEXT: warn_no_constructor_for_refconst
CHECK-NEXT: warn_nonnull_pointers_only
CHECK-NEXT: warn_not_compound_assign
CHECK-NEXT: warn_objc_property_copy_missing_on_block
CHECK-NEXT: warn_objc_protocol_qualifier_missing_id

View File

@ -20,3 +20,4 @@ int main(void) {
}
void foo(const char *str) __attribute__((nonnull("foo"))); // expected-error{{'nonnull' attribute requires parameter 1 to be an integer constant}}
void bar(int i) __attribute__((nonnull(1))); // expected-warning {{'nonnull' attribute only applies to pointer arguments}} expected-warning {{'nonnull' attribute applied to function with no pointer arguments}}