r201162 - 'nonnull(1)' on a block parameter should apply to the block's argument.
Jordan Rose
jordan_rose at apple.com
Tue Feb 11 09:27:59 PST 2014
Author: jrose
Date: Tue Feb 11 11:27:59 2014
New Revision: 201162
URL: http://llvm.org/viewvc/llvm-project?rev=201162&view=rev
Log:
'nonnull(1)' on a block parameter should apply to the block's argument.
Thanks to r199467, __attribute__((nonnull)) (without arguments) can apply
directly to parameters, instead of being applied to the whole function.
However, the old form of nonnull (with an argument index) could also apply
to the arguments of function and block pointers, and both of these can be
passed as parameters.
Now, if 'nonnull' with an argument is found on a parameter, /and/ the
parameter is a function or block pointer, it is handled the old way.
PR18795
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/nonnull.c
cfe/trunk/test/SemaObjC/nonnull.m
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=201162&r1=201161&r2=201162&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Feb 11 11:27:59 2014
@@ -1170,23 +1170,6 @@ static bool attrNonNullArgCheck(Sema &S,
return true;
}
-static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D,
- const AttributeList &Attr) {
- // Is the argument a pointer type?
- if (!attrNonNullArgCheck(S, D->getType(), Attr, D->getSourceRange()))
- return;
-
- if (Attr.getNumArgs() > 0) {
- S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_parm_no_args)
- << D->getSourceRange();
- return;
- }
-
- D->addAttr(::new (S.Context)
- NonNullAttr(Attr.getRange(), S.Context, 0, 0,
- Attr.getAttributeSpellingListIndex()));
-}
-
static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) {
SmallVector<unsigned, 8> NonNullArgs;
for (unsigned i = 0; i < Attr.getNumArgs(); ++i) {
@@ -1232,6 +1215,27 @@ static void handleNonNullAttr(Sema &S, D
Attr.getAttributeSpellingListIndex()));
}
+static void handleNonNullAttrParameter(Sema &S, ParmVarDecl *D,
+ const AttributeList &Attr) {
+ if (Attr.getNumArgs() > 0) {
+ if (D->getFunctionType()) {
+ handleNonNullAttr(S, D, Attr);
+ } else {
+ S.Diag(Attr.getLoc(), diag::warn_attribute_nonnull_parm_no_args)
+ << D->getSourceRange();
+ }
+ return;
+ }
+
+ // Is the argument a pointer type?
+ if (!attrNonNullArgCheck(S, D->getType(), Attr, D->getSourceRange()))
+ return;
+
+ D->addAttr(::new (S.Context)
+ NonNullAttr(Attr.getRange(), S.Context, 0, 0,
+ Attr.getAttributeSpellingListIndex()));
+}
+
static void handleReturnsNonNullAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
QualType ResultType = getFunctionOrMethodResultType(D);
Modified: cfe/trunk/test/Sema/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nonnull.c?rev=201162&r1=201161&r2=201162&view=diff
==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (original)
+++ cfe/trunk/test/Sema/nonnull.c Tue Feb 11 11:27:59 2014
@@ -45,3 +45,11 @@ void *test_bad_returns_null(void) {
return 0; // expected-warning {{null returned from function that requires a non-null return value}}
}
+void PR18795(int (*g)(const char *h, ...) __attribute__((nonnull(1))) __attribute__((nonnull))) {
+ g(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}
+void PR18795_helper() {
+ PR18795(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}
+
+
Modified: cfe/trunk/test/SemaObjC/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?rev=201162&r1=201161&r2=201162&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.m (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Tue Feb 11 11:27:59 2014
@@ -116,3 +116,10 @@ void test(TestNonNullParameters *f) {
[f doNotPassNullOnMethod:0]; // expected-warning {{null passed to a callee which requires a non-null argument}}
}
+
+void PR18795(int (^g)(const char *h, ...) __attribute__((nonnull(1))) __attribute__((nonnull))) {
+ g(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}
+void PR18795_helper() {
+ PR18795(0); // expected-warning{{null passed to a callee which requires a non-null argument}}
+}
More information about the cfe-commits
mailing list