|
| 1 | +// RUN: %clang_cc1 -fbounds-safety -verify=bs %s |
| 2 | +// RUN: %clang_cc1 -fbounds-safety -x objective-c -fexperimental-bounds-safety-objc -verify=bs %s |
| 3 | +// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x c -verify=bsa %s |
| 4 | +// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x c++ -verify=bsa,bsa-cxx %s |
| 5 | +// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x objective-c -verify=bsa %s |
| 6 | +// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x objective-c++ -verify=bsa,bsa-cxx %s |
1 | 7 |
|
| 8 | +#include <ptrcheck.h> |
2 | 9 |
|
3 |
| -// RUN: %clang_cc1 -fbounds-safety -verify %s |
4 |
| -// RUN: %clang_cc1 -fbounds-safety -x objective-c -fexperimental-bounds-safety-objc -verify %s |
5 |
| -// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x c -verify %s |
6 |
| -// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x c++ -verify %s |
7 |
| -// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x objective-c -verify %s |
8 |
| -// RUN: %clang_cc1 -fexperimental-bounds-safety-attributes -x objective-c++ -verify %s |
| 10 | +void cb(int *__counted_by(len) ptr, int len) { |
| 11 | + // bs-error@+2{{passing '__counted_by' pointer as '__auto_type' initializer is not yet supported}} |
| 12 | + // bsa-warning@+1{{passing '__counted_by' pointer as '__auto_type' initializer is not yet supported}} |
| 13 | + __auto_type p = ptr; |
9 | 14 |
|
10 |
| -#include <ptrcheck.h> |
| 15 | +#ifdef __cplusplus |
| 16 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'auto' initializer is not yet supported}} |
| 17 | + auto q = ptr; |
| 18 | + |
| 19 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 20 | + decltype(auto) r = ptr; |
| 21 | +#endif |
| 22 | +} |
| 23 | + |
| 24 | +void cbn(int *__counted_by_or_null(len) ptr, int len) { |
| 25 | + // bs-error@+2{{passing '__counted_by_or_null' pointer as '__auto_type' initializer is not yet supported}} |
| 26 | + // bsa-warning@+1{{passing '__counted_by_or_null' pointer as '__auto_type' initializer is not yet supported}} |
| 27 | + __auto_type p = ptr; |
| 28 | + |
| 29 | +#ifdef __cplusplus |
| 30 | + // bsa-cxx-warning@+1{{passing '__counted_by_or_null' pointer as 'auto' initializer is not yet supported}} |
| 31 | + auto q = ptr; |
| 32 | + |
| 33 | + // bsa-cxx-warning@+1{{passing '__counted_by_or_null' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 34 | + decltype(auto) r = ptr; |
| 35 | +#endif |
| 36 | +} |
| 37 | + |
| 38 | +void sb(void *__sized_by(size) ptr, int size) { |
| 39 | + // bs-error@+2{{passing '__sized_by' pointer as '__auto_type' initializer is not yet supported}} |
| 40 | + // bsa-warning@+1{{passing '__sized_by' pointer as '__auto_type' initializer is not yet supported}} |
| 41 | + __auto_type p = ptr; |
| 42 | + |
| 43 | +#ifdef __cplusplus |
| 44 | + // bsa-cxx-warning@+1{{passing '__sized_by' pointer as 'auto' initializer is not yet supported}} |
| 45 | + auto q = ptr; |
| 46 | + |
| 47 | + // bsa-cxx-warning@+1{{passing '__sized_by' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 48 | + decltype(auto) r = ptr; |
| 49 | +#endif |
| 50 | +} |
| 51 | + |
| 52 | +void eb(void *__ended_by(e) ptr, void *e) { |
| 53 | + // bs-error@+2{{passing '__ended_by' pointer as '__auto_type' initializer is not yet supported}} |
| 54 | + // bsa-warning@+1{{passing '__ended_by' pointer as '__auto_type' initializer is not yet supported}} |
| 55 | + __auto_type p = ptr; |
| 56 | + |
| 57 | +#ifdef __cplusplus |
| 58 | + // bsa-cxx-warning@+1{{passing '__ended_by' pointer as 'auto' initializer is not yet supported}} |
| 59 | + auto q = ptr; |
11 | 60 |
|
12 |
| -void foo(int *__counted_by(len) ptr, int len) { |
13 |
| - __auto_type p = ptr; // expected-error{{passing '__counted_by' pointer as __auto_type initializer is not yet supported}} |
| 61 | + // bsa-cxx-warning@+1{{passing '__ended_by' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 62 | + decltype(auto) r = ptr; |
| 63 | +#endif |
14 | 64 | }
|
| 65 | + |
| 66 | +void eb_end(void *__ended_by(e) ptr, void *e) { |
| 67 | + // bs-error@+2{{passing end pointer as '__auto_type' initializer is not yet supported}} |
| 68 | + // bsa-warning@+1{{passing end pointer as '__auto_type' initializer is not yet supported}} |
| 69 | + __auto_type p = e; |
| 70 | + |
| 71 | +#ifdef __cplusplus |
| 72 | + // bsa-cxx-warning@+1{{passing end pointer as 'auto' initializer is not yet supported}} |
| 73 | + auto q = e; |
| 74 | + |
| 75 | + // bsa-cxx-warning@+1{{passing end pointer as 'decltype(auto)' initializer is not yet supported}} |
| 76 | + decltype(auto) r = e; |
| 77 | +#endif |
| 78 | +} |
| 79 | + |
| 80 | +void cb_const(int *__counted_by(42) ptr) { |
| 81 | + // bs-error@+2{{passing '__counted_by' pointer as '__auto_type' initializer is not yet supported}} |
| 82 | + // bsa-warning@+1{{passing '__counted_by' pointer as '__auto_type' initializer is not yet supported}} |
| 83 | + __auto_type p = ptr; |
| 84 | + |
| 85 | +#ifdef __cplusplus |
| 86 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'auto' initializer is not yet supported}} |
| 87 | + auto q = ptr; |
| 88 | + |
| 89 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 90 | + decltype(auto) r = ptr; |
| 91 | +#endif |
| 92 | +} |
| 93 | + |
| 94 | +#ifdef __cplusplus |
| 95 | +template<typename T> |
| 96 | +struct cxx_dep { |
| 97 | + int len; |
| 98 | + T __counted_by(len) ptr; |
| 99 | + |
| 100 | + void f() { |
| 101 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as '__auto_type' initializer is not yet supported}} |
| 102 | + __auto_type p = ptr; |
| 103 | + |
| 104 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'auto' initializer is not yet supported}} |
| 105 | + auto q = ptr; |
| 106 | + |
| 107 | + // bsa-cxx-warning@+1{{passing '__counted_by' pointer as 'decltype(auto)' initializer is not yet supported}} |
| 108 | + decltype(auto) r = ptr; |
| 109 | + } |
| 110 | +}; |
| 111 | + |
| 112 | +// bsa-cxx-note@+1{{in instantiation of member function 'cxx_dep<int *>::f' requested here}} |
| 113 | +template struct cxx_dep<int *>; |
| 114 | +#endif |
0 commit comments