annotate clang/test/Sema/non-null-warning.c @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -Wnonnull -Wnullability %s -verify
anatofuz
parents:
diff changeset
2 // rdar://19160762
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 #if __has_feature(nullability)
anatofuz
parents:
diff changeset
5 #else
anatofuz
parents:
diff changeset
6 # error nullability feature should be defined
anatofuz
parents:
diff changeset
7 #endif
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9
anatofuz
parents:
diff changeset
10 int * _Nullable foo(int * _Nonnull x);
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 int *_Nonnull ret_nonnull();
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 int *foo(int *x) {
anatofuz
parents:
diff changeset
15 return 0;
anatofuz
parents:
diff changeset
16 }
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 int * _Nullable foo1(int * _Nonnull x); // expected-note {{previous declaration is here}}
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 int *foo1(int * _Nullable x) { // expected-warning {{nullability specifier '_Nullable' conflicts with existing specifier '_Nonnull'}}
anatofuz
parents:
diff changeset
21 return 0;
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 int * _Nullable foo2(int * _Nonnull x);
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 int *foo2(int * _Nonnull x) {
anatofuz
parents:
diff changeset
27 return 0;
anatofuz
parents:
diff changeset
28 }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 int * _Nullable foo3(int * _Nullable x); // expected-note {{previous declaration is here}}
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 int *foo3(int * _Nonnull x) { // expected-warning {{nullability specifier '_Nonnull' conflicts with existing specifier '_Nullable'}}
anatofuz
parents:
diff changeset
33 return 0;
anatofuz
parents:
diff changeset
34 }
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 int * ret_nonnull() {
anatofuz
parents:
diff changeset
37 return 0; // expected-warning {{null returned from function that requires a non-null return value}}
anatofuz
parents:
diff changeset
38 }
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 #define SAFE_CALL(X) if (X) foo(X)
anatofuz
parents:
diff changeset
41 int main () {
anatofuz
parents:
diff changeset
42 foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
anatofuz
parents:
diff changeset
43 (void)sizeof(foo(0)); // expect no diagnostic in unevaluated context.
anatofuz
parents:
diff changeset
44 SAFE_CALL(0); // expect no diagnostic for unreachable code.
anatofuz
parents:
diff changeset
45 }