diff options
author | Douglas Gregor <dgregor@apple.com> | 2015-06-19 18:13:19 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2015-06-19 18:13:19 +0000 |
commit | b4866e85e5ffa0d352d496958582f0983172dc01 (patch) | |
tree | bfc790bef93a450379f8936f20589b99a524657b /clang/test/Sema/non-null-warning.c | |
parent | bb3a01cfaf679413b5e9ee3f3187e06bb246dcf3 (diff) | |
download | bcm5719-llvm-b4866e85e5ffa0d352d496958582f0983172dc01.tar.gz bcm5719-llvm-b4866e85e5ffa0d352d496958582f0983172dc01.zip |
Diagnose unsafe uses of nil and __nonnull pointers.
This generalizes the checking of null arguments to also work with
values of pointer-to-function, reference-to-function, and block
pointer type, using the nullability information within the underling
function prototype to extend non-null checking, and diagnoses returns
of 'nil' within a function with a __nonnull return type.
Note that we don't warn about nil returns from Objective-C methods,
because it's common for Objective-C methods to mimic the nil-swallowing
behavior of the receiver by checking ostensibly non-null parameters
and returning nil from otherwise non-null methods in that
case.
It also diagnoses (via a separate flag) conversions from nullable to
nonnull pointers. It's a separate flag because this warning can be noisy.
llvm-svn: 240153
Diffstat (limited to 'clang/test/Sema/non-null-warning.c')
-rw-r--r-- | clang/test/Sema/non-null-warning.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/clang/test/Sema/non-null-warning.c b/clang/test/Sema/non-null-warning.c index 0cabc713baf..6cd98e298e2 100644 --- a/clang/test/Sema/non-null-warning.c +++ b/clang/test/Sema/non-null-warning.c @@ -33,3 +33,10 @@ int *foo3(int * __nonnull x) { // expected-warning {{nullability specifier '__no return 0; } +int * ret_nonnull() { + return 0; // expected-warning {{null returned from function that requires a non-null return value}} +} + +int main () { + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}} +} |