summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-09-09 01:17:32 +0000
committerTed Kremenek <kremenek@apple.com>2010-09-09 01:17:32 +0000
commit0f107e4386380e45ea61a16621e149e5d2e1e4c7 (patch)
tree85a0b0ab28977d6937c8280e66799400803f8a08
parent2ff757d4226205703ee24f63cbc6fae8a5f3a391 (diff)
downloadbcm5719-llvm-0f107e4386380e45ea61a16621e149e5d2e1e4c7.tar.gz
bcm5719-llvm-0f107e4386380e45ea61a16621e149e5d2e1e4c7.zip
Relax __attribute_((nonnull)) checking to allow the attribute on functions with no pointer arguments. GCC doesn't warn
in this case, and the attribute is trivially satisfied (and benign). Fixes <rdar://problem/8364828>. llvm-svn: 113464
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp6
-rw-r--r--clang/test/SemaObjC/nonnull.m4
3 files changed, 5 insertions, 8 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91b0b6aae25..849c5c477c9 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1016,14 +1016,11 @@ def err_mode_wrong_type : Error<
"type of machine mode does not match type of base type">;
def err_attr_wrong_decl : Error<
"'%0' attribute invalid on this declaration, requires typedef or value">;
-def warn_attribute_nonnull_no_pointers : Warning<
- "'nonnull' attribute applied to function with no pointer arguments">;
def warn_attribute_malloc_pointer_only : Warning<
"'malloc' attribute only applies to functions returning a pointer type">;
def warn_transparent_union_nonpointer : Warning<
"'transparent_union' attribute support incomplete; only supported for "
"pointer unions">;
-
def warn_attribute_sentinel_named_arguments : Warning<
"'sentinel' attribute requires named arguments">;
def warn_attribute_sentinel_not_variadic : Warning<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 25af73ae13d..a47d84fa35c 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -373,10 +373,10 @@ static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
NonNullArgs.push_back(I);
}
- if (NonNullArgs.empty()) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_no_pointers);
+ // No pointer arguments? The attribute in this case is
+ // trivially satisfied.
+ if (NonNullArgs.empty())
return;
- }
}
unsigned* start = &NonNullArgs[0];
diff --git a/clang/test/SemaObjC/nonnull.m b/clang/test/SemaObjC/nonnull.m
index 15fee74a3b5..282fd21a140 100644
--- a/clang/test/SemaObjC/nonnull.m
+++ b/clang/test/SemaObjC/nonnull.m
@@ -2,7 +2,7 @@
@class NSObject;
-int f1(int x) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
+int f1(int x) __attribute__((nonnull)); //no-warning
int f2(int *x) __attribute__ ((nonnull (1)));
int f3(int *x) __attribute__ ((nonnull (0))); // expected-error {{'nonnull' attribute parameter 1 is out of bounds}}
int f4(int *x, int *y) __attribute__ ((nonnull (1,2)));
@@ -44,4 +44,4 @@ foo (int i1, int i2, int i3, void (^cp1)(), void (^cp2)(), void (^cp3)())
func7((NSObject*) 0); // no-warning
}
-void func5(int) __attribute__((nonnull)); // expected-warning{{'nonnull' attribute applied to function with no pointer arguments}}
+void func5(int) __attribute__((nonnull)); // no-warning
OpenPOWER on IntegriCloud