From 0f76ae8d75d27421c0924edda70d00d41f2abb0f Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Mon, 20 Jan 2014 14:19:44 +0000 Subject: [PATCH] Making some minor improvements to r199626. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199663 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 2 +- lib/Sema/SemaDeclAttr.cpp | 12 +++--------- test/Sema/nonnull.c | 8 ++++---- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index f1eb97ea77..5ea3915ccf 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -696,7 +696,7 @@ def NonNull : InheritableAttr { } def ReturnsNonNull : InheritableAttr { - let Spellings = [GNU<"returns_nonnull">]; + let Spellings = [GNU<"returns_nonnull">, CXX11<"gnu", "returns_nonnull">]; let Subjects = SubjectList<[ObjCMethod, HasFunctionProto], WarnDiag, "ExpectedFunctionOrMethod">; } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index ed8610cec3..65b3820a0b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1235,12 +1235,7 @@ static void handleNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) { static void handleReturnsNonNullAttr(Sema &S, Decl *D, const AttributeList &Attr) { - QualType ResultType; - if (const FunctionType *Ty = D->getFunctionType()) - ResultType = Ty->getResultType(); - else if (const ObjCMethodDecl *MD = dyn_cast(D)) - ResultType = MD->getResultType(); - + QualType ResultType = getFunctionOrMethodResultType(D); if (!attrNonNullArgCheck(S, ResultType, Attr, Attr.getRange(), /* isReturnValue */ true)) return; @@ -3997,9 +3992,8 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, else handleNonNullAttr(S, D, Attr); break; - case AttributeList::AT_ReturnsNonNull: - handleReturnsNonNullAttr(S, D, Attr); - break; + case AttributeList::AT_ReturnsNonNull: + handleReturnsNonNullAttr(S, D, Attr); break; case AttributeList::AT_Overloadable: handleSimpleAttribute(S, D, Attr); break; case AttributeList::AT_Ownership: handleOwnershipAttr (S, D, Attr); break; diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c index f1ba482453..9ec004fdde 100644 --- a/test/Sema/nonnull.c +++ b/test/Sema/nonnull.c @@ -32,10 +32,10 @@ void test_baz() { baz3(0); // no-warning } -void test_void_returns_nonnull() __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}} -int test_int_returns_nonnull() __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}} -void *test_ptr_returns_nonnull() __attribute__((returns_nonnull)); // no-warning +void test_void_returns_nonnull(void) __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}} +int test_int_returns_nonnull(void) __attribute__((returns_nonnull)); // expected-warning {{'returns_nonnull' attribute only applies to return values that are pointers}} +void *test_ptr_returns_nonnull(void) __attribute__((returns_nonnull)); // no-warning 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}} -- 2.50.0