r297592 - Allow the nonnull attribute to be inherited as a parameter in the redefinition of a function. Fixes PR30828.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 12 15:30:07 PDT 2017


Author: aaronballman
Date: Sun Mar 12 17:30:07 2017
New Revision: 297592

URL: http://llvm.org/viewvc/llvm-project?rev=297592&view=rev
Log:
Allow the nonnull attribute to be inherited as a parameter in the redefinition of a function. Fixes PR30828.

Patch by Matt Bettinson.

Modified:
    cfe/trunk/include/clang/Basic/Attr.td
    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=297592&r1=297591&r2=297592&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Sun Mar 12 17:30:07 2017
@@ -1149,7 +1149,7 @@ def NoSplitStack : InheritableAttr {
   let Documentation = [NoSplitStackDocs];
 }
 
-def NonNull : InheritableAttr {
+def NonNull : InheritableParamAttr {
   let Spellings = [GCC<"nonnull">];
   let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
                              "ExpectedFunctionMethodOrParameter">;

Modified: cfe/trunk/test/Sema/nonnull.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/nonnull.c?rev=297592&r1=297591&r2=297592&view=diff
==============================================================================
--- cfe/trunk/test/Sema/nonnull.c (original)
+++ cfe/trunk/test/Sema/nonnull.c Sun Mar 12 17:30:07 2017
@@ -167,3 +167,10 @@ void returns_nonnull_warning_tests() {
   int and_again = !returns_nonnull_whee(); // expected-warning {{nonnull function call 'returns_nonnull_whee()' will evaluate to 'true' on first encounter}}
   and_again = !returns_nonnull_whee(); // expected-warning {{nonnull function call 'returns_nonnull_whee()' will evaluate to 'true' on first encounter}}
 }
+
+void pr30828(char *p __attribute__((nonnull)));
+void pr30828(char *p) {}
+
+void call_pr30828() {
+  pr30828(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+}




More information about the cfe-commits mailing list