[PATCH] D26800: [Sema] Make __attribute__((notnull)) inheritable through function parameters

Matt Bettinson via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 17 07:18:19 PST 2016


bettinson created this revision.
bettinson added reviewers: rsmith, aaron.ballman.
bettinson added a subscriber: cfe-commits.

Fix PR 30828. ` __attribute__((notnull))` was not inheritable in the redefinition of a function. This is because attribute NonNull wasn't `InheritableParamAttr`, it was `InheritableAttr`. Clang will now emit warning after calling the redeclared function with a null argument.

This is my first patch into Clang, so I'll need someone to commit this for me.

Cheers


https://reviews.llvm.org/D26800

Files:
  include/clang/Basic/Attr.td
  test/Sema/nonnull.c


Index: test/Sema/nonnull.c
===================================================================
--- test/Sema/nonnull.c
+++ test/Sema/nonnull.c
@@ -111,7 +111,7 @@
      return 0;
    } else {
      return *pointer;
-   } 
+   }
 
    set_param_to_null(&pointer);
    if (!pointer)
@@ -167,3 +167,10 @@
   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 pr31040(char *p __attribute__((nonnull)));
+void pr31040(char *p) {}
+
+void call_pr31040() {
+  pr31040(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+}
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1100,7 +1100,7 @@
   let Documentation = [NoSplitStackDocs];
 }
 
-def NonNull : InheritableAttr {
+def NonNull : InheritableParamAttr {
   let Spellings = [GCC<"nonnull">];
   let Subjects = SubjectList<[ObjCMethod, HasFunctionProto, ParmVar], WarnDiag,
                              "ExpectedFunctionMethodOrParameter">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26800.78365.patch
Type: text/x-patch
Size: 1313 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161117/7a082fbd/attachment.bin>


More information about the cfe-commits mailing list