xref: /minix3/external/bsd/llvm/dist/clang/test/Sema/attr-ownership.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -verify
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc void f1(void) __attribute__((ownership_takes("foo"))); // expected-error {{'ownership_takes' attribute requires parameter 1 to be an identifier}}
4*0a6a1f1dSLionel Sambuc void *f2(void) __attribute__((ownership_returns(foo, 1, 2)));  // expected-error {{'ownership_returns' attribute takes no more than 1 argument}}
5f4a2713aSLionel Sambuc void f3(void) __attribute__((ownership_holds(foo, 1))); // expected-error {{'ownership_holds' attribute parameter 1 is out of bounds}}
6f4a2713aSLionel Sambuc void *f4(void) __attribute__((ownership_returns(foo)));
7*0a6a1f1dSLionel Sambuc void f5(void) __attribute__((ownership_holds(foo)));  // expected-error {{'ownership_holds' attribute takes at least 2 arguments}}
8f4a2713aSLionel Sambuc void f6(void) __attribute__((ownership_holds(foo, 1, 2, 3)));  // expected-error {{'ownership_holds' attribute parameter 1 is out of bounds}}
9*0a6a1f1dSLionel Sambuc void f7(void) __attribute__((ownership_takes(foo)));  // expected-error {{'ownership_takes' attribute takes at least 2 arguments}}
10f4a2713aSLionel Sambuc void f8(int *i, int *j, int k) __attribute__((ownership_holds(foo, 1, 2, 4)));  // expected-error {{'ownership_holds' attribute parameter 3 is out of bounds}}
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc int f9 __attribute__((ownership_takes(foo, 1)));  // expected-warning {{'ownership_takes' attribute only applies to functions}}
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc void f10(int i) __attribute__((ownership_holds(foo, 1)));  // expected-error {{'ownership_holds' attribute only applies to pointer arguments}}
15f4a2713aSLionel Sambuc void *f11(float i) __attribute__((ownership_returns(foo, 1)));  // expected-error {{'ownership_returns' attribute only applies to integer arguments}}
16f4a2713aSLionel Sambuc void *f12(float i, int k, int f, int *j) __attribute__((ownership_returns(foo, 4)));  // expected-error {{'ownership_returns' attribute only applies to integer arguments}}
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc void f13(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_takes(foo, 2)));
19f4a2713aSLionel Sambuc void f14(int i, int j, int *k) __attribute__((ownership_holds(foo, 3))) __attribute__((ownership_takes(foo, 3)));  // expected-error {{'ownership_holds' and 'ownership_takes' attributes are not compatible}}
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc void f15(int, int)
22*0a6a1f1dSLionel Sambuc   __attribute__((ownership_returns(foo, 1)))  // expected-note {{declared with index 1 here}}
23*0a6a1f1dSLionel Sambuc   __attribute__((ownership_returns(foo, 2))); // expected-error {{'ownership_returns' attribute index does not match; here it is 2}}
24*0a6a1f1dSLionel Sambuc void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) __attribute__((ownership_holds(foo, 1))); // OK, same index
25