Skip to content

Commit

Permalink
This diagnostic did not accept arguments, and did not have any test c…
Browse files Browse the repository at this point in the history
…overage. 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
  • Loading branch information
AaronBallman committed Dec 26, 2013
1 parent 213cf41 commit cedaaea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions clang/test/Misc/warning-flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions clang/test/Sema/nonnull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

0 comments on commit cedaaea

Please sign in to comment.