[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / non-null-warning.c
blob85cbed29960cd6dd7a622b0b21c3ced74b2d8fa9
1 // RUN: %clang_cc1 -fsyntax-only -Wnonnull -Wnullability %s -verify
3 #if __has_feature(nullability)
4 #else
5 # error nullability feature should be defined
6 #endif
9 int * _Nullable foo(int * _Nonnull x);
11 int *_Nonnull ret_nonnull(void);
13 int *foo(int *x) {
14 return 0;
17 int * _Nullable foo1(int * _Nonnull x); // expected-note {{previous declaration is here}}
19 int *foo1(int * _Nullable x) { // expected-warning {{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
20 return 0;
23 int * _Nullable foo2(int * _Nonnull x);
25 int *foo2(int * _Nonnull x) {
26 return 0;
29 int * _Nullable foo3(int * _Nullable x); // expected-note {{previous declaration is here}}
31 int *foo3(int * _Nonnull x) { // expected-warning {{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable'}}
32 return 0;
35 int * ret_nonnull(void) {
36 return 0; // expected-warning {{null returned from function that requires a non-null return value}}
39 int foo4(int * _Nonnull x, int * y) {
40 return 0;
43 #define SAFE_CALL(X) if (X) foo(X)
44 int main (void) {
45 foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
46 (void)sizeof(foo(0)); // expect no diagnostic in unevaluated context.
47 SAFE_CALL(0); // expect no diagnostic for unreachable code.
48 foo4(
49 0, // expected-warning {{null passed to a callee that requires a non-null argument}}
50 0);