r212827 - 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.

Aaron Ballman aaron at aaronballman.com
Fri Jul 11 09:31:30 PDT 2014


Author: aaronballman
Date: Fri Jul 11 11:31:29 2014
New Revision: 212827

URL: http://llvm.org/viewvc/llvm-project?rev=212827&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/nonnull.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=212827&r1=212826&r2=212827&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Fri Jul 11 11:31:29 2014
@@ -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];
 }

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=212827&r1=212826&r2=212827&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Jul 11 11:31:29 2014
@@ -90,7 +90,7 @@ static QualType getFunctionOrMethodParam
 
 static QualType getFunctionOrMethodResultType(const Decl *D) {
   if (const FunctionType *FnTy = D->getFunctionType())
-    return cast<FunctionProtoType>(FnTy)->getReturnType();
+    return cast<FunctionType>(FnTy)->getReturnType();
   return cast<ObjCMethodDecl>(D)->getReturnType();
 }
 

Modified: cfe/trunk/test/Sema/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nonnull.c?rev=212827&r1=212826&r2=212827&view=diff
==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (original)
+++ cfe/trunk/test/Sema/nonnull.c Fri Jul 11 11:31:29 2014
@@ -38,7 +38,8 @@ void *test_ptr_returns_nonnull(void) __a
 
 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) {





More information about the cfe-commits mailing list