From 010c6d13be63af4b82db8cb0e4c157f9289d0110 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Sun, 12 Mar 2017 22:30:07 +0000 Subject: [PATCH] Allow the nonnull attribute to be inherited as a parameter in the redefinition of a function. Fixes PR30828. Patch by Matt Bettinson. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297592 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Attr.td | 2 +- test/Sema/nonnull.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 53faac82c4..5960cca1e7 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -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">; diff --git a/test/Sema/nonnull.c b/test/Sema/nonnull.c index e98a8194db..217bbb16df 100644 --- a/test/Sema/nonnull.c +++ b/test/Sema/nonnull.c @@ -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}} +} -- 2.40.0