1 // UNSUPPORTED: android
2 // RUN: %clang -w -fsanitize=nullability-arg,nullability-assign,nullability-return %s -O3 -o %t
3 // RUN: %run %t foo 2>&1 | FileCheck %s --check-prefix=NOERROR --allow-empty --implicit-check-not='runtime error'
4 // RUN: %run %t 2>&1 | FileCheck %s
6 // RUN: echo "nullability-arg:nullability.c" > %t.supp
7 // RUN: echo "nullability-return:nullability.c" >> %t.supp
8 // RUN: echo "nullability-assign:nullability.c" >> %t.supp
9 // RUN: env UBSAN_OPTIONS=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck -allow-empty -check-prefix=SUPPRESS %s
10 // SUPPRESS-NOT: runtime error
12 // CHECK: nullability.c:[[@LINE+2]]:41: runtime error: null pointer returned from function declared to never return null
13 // CHECK-NEXT: nullability.c:[[@LINE+1]]:6: note: _Nonnull return type annotation specified here
14 int *_Nonnull
nonnull_retval1(int *p
) { return p
; }
16 // CHECK: nullability.c:1001:22: runtime error: null pointer passed as argument 2, which is declared to never be null
17 // CHECK-NEXT: nullability.c:[[@LINE+1]]:56: note: _Nonnull type annotation specified here
18 int *_Nonnull
nonnull_retval2(int *_Nonnull arg1
, int *_Nonnull arg2
,
19 int *_Nullable arg3
, int *arg4
, int arg5
, ...) {
23 // CHECK: nullability.c:1002:15: runtime error: null pointer passed as argument 1, which is declared to never be null
24 // CHECK-NEXT: nullability.c:[[@LINE+1]]:23: note: _Nonnull type annotation specified here
25 void nonnull_arg(int *_Nonnull p
) {}
27 void nonnull_assign1(int *p
) {
29 // CHECK: nullability.c:[[@LINE+1]]:9: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
33 void nonnull_assign2(int *p
) {
35 // CHECK: nullability.c:[[@LINE+1]]:10: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
43 void nonnull_assign3(int *p
) {
45 // CHECK: nullability.c:[[@LINE+1]]:10: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
49 // CHECK: nullability.c:[[@LINE+1]]:52: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
50 void nonnull_init1(int *p
) { int *_Nonnull local
= p
; }
52 // CHECK: nullability.c:[[@LINE+2]]:53: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
53 // CHECK: nullability.c:[[@LINE+1]]:56: runtime error: _Nonnull binding to null pointer of type 'int * _Nonnull'
54 void nonnull_init2(int *p
) { int *_Nonnull arr
[] = {p
, p
}; }
56 int main(int argc
, char **argv
) {
57 int *p
= (argc
> 1) ? &argc
: ((int *)0);
61 nonnull_retval2(p
, p
, p
, p
, 0, 0, 0, 0);
71 // NOERROR-NOT: runtime error