From: Aaron Ballman Date: Fri, 11 Jul 2014 16:31:29 +0000 (+0000) Subject: The returns_nonnull attribute does not require a function prototype because it affect... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6d998b1ddec7e712928c48ab112987fa2357561;p=clang The returns_nonnull attribute does not require a function prototype because it affects only the return value, not any arguments. In turn, asking for a function or method result type should not require a function prototype either, so getFunctionOrMethodResultType has been relaxed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212827 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index df4b38d331..f34034e325 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -855,7 +855,7 @@ def NonNull : InheritableAttr { def ReturnsNonNull : InheritableAttr { let Spellings = [GCC<"returns_nonnull">]; - let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag, + let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag, "ExpectedFunctionOrMethod">; let Documentation = [Undocumented]; } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 45ca8dcaef..7674aa4854 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -90,7 +90,7 @@ static QualType getFunctionOrMethodParamType(const Decl *D, unsigned Idx) { static QualType getFunctionOrMethodResultType(const Decl *D) { if (const FunctionType *FnTy = D->getFunctionType()) - return cast(FnTy)->getReturnType(); + return cast(FnTy)->getReturnType(); return cast(D)->getReturnType(); } diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c index 0e92654c28..b1f6920824 100644 --- a/test/Sema/nonnull.c +++ b/test/Sema/nonnull.c @@ -38,7 +38,8 @@ void *test_ptr_returns_nonnull(void) __attribute__((returns_nonnull)); // no-war int i __attribute__((nonnull)); // expected-warning {{'nonnull' attribute only applies to functions, methods, and parameters}} int j __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to functions and methods}} -void *test_no_fn_proto() __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to functions and methods}} +void *test_no_fn_proto() __attribute__((returns_nonnull)); // no-warning +void *test_with_fn_proto(void) __attribute__((returns_nonnull)); // no-warning __attribute__((returns_nonnull)) void *test_bad_returns_null(void) {