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">;
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">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits