diff options
| author | Jordan Rose <jordan_rose@apple.com> | 2014-02-11 17:27:59 +0000 |
|---|---|---|
| committer | Jordan Rose <jordan_rose@apple.com> | 2014-02-11 17:27:59 +0000 |
| commit | c939907a5af701aae3ebae452251520b88060694 (patch) | |
| tree | 7d98466bb91c98f8b55fe3bdbe7d4bd9f9c75f9d /clang/lib | |
| parent | 1515a48e1431115b99bec216e29c204847294b14 (diff) | |
| download | bcm5719-llvm-c939907a5af701aae3ebae452251520b88060694.tar.gz bcm5719-llvm-c939907a5af701aae3ebae452251520b88060694.zip | |
'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
llvm-svn: 201162
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 65fb7266dbf..1bc34aa85f9 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1170,23 +1170,6 @@ static bool attrNonNullArgCheck(Sema &S, QualType T, const AttributeList &Attr, 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, Decl *D, const AttributeList &Attr) { 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); |

