1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 3 struct S { method_returns_retainedS4 __attribute__((os_returns_retained)) S* method_returns_retained() { 5 return nullptr; 6 } 7 8 __attribute__((os_consumes_this)) void method_consumes_this(); 9 10 __attribute__((os_consumes_this)) static void rejected_on_static(); // expected-warning{{'os_consumes_this' attribute only applies to non-static member functions}} 11 }; ret_retained()12__attribute__((os_returns_retained)) S *ret_retained() { 13 return nullptr; 14 } 15 ret_retained_value()16__attribute__((os_returns_retained)) S ret_retained_value() { // expected-warning{{'os_returns_retained' attribute only applies to functions that return a pointer}} 17 return {}; 18 } 19 ret_not_retained()20__attribute__((os_returns_not_retained)) S *ret_not_retained() { 21 return nullptr; 22 } 23 ret_not_retained_value()24__attribute__((os_returns_not_retained)) S ret_not_retained_value() { // expected-warning{{'os_returns_not_retained' attribute only applies to functions that return a pointer}} 25 return {}; 26 } 27 accept_consumed_arg(S * arg)28void accept_consumed_arg(__attribute__((os_consumed)) S *arg) {} 29 accept_consumed_arg_by_value(S arg)30void accept_consumed_arg_by_value(__attribute__((os_consumed)) S arg) {} // expected-warning{{os_consumed attribute only applies to pointer parameters}} 31 accept_consumed_arg_no_extra_arg(S * arg)32void accept_consumed_arg_no_extra_arg(__attribute__((os_consumed(10))) S *arg) {} // expected-error{{'os_consumed' attribute takes no arguments}} 33 34 struct __attribute__((os_consumed)) NoAttrOnStruct {}; // expected-warning{{'os_consumed' attribute only applies to parameters}} 35 returns_retained_no_extra_arg()36__attribute__((os_returns_retained(10))) S* returns_retained_no_extra_arg() { // expected-error{{'os_returns_retained' attribute takes no arguments}} 37 return nullptr; 38 } 39 40 struct __attribute__((os_returns_retained)) NoRetainAttrOnStruct {}; // expected-warning{{'os_returns_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} 41 os_returns_no_retained_no_extra_args(S * arg)42__attribute__((os_returns_not_retained(10))) S* os_returns_no_retained_no_extra_args( S *arg) { // expected-error{{'os_returns_not_retained' attribute takes no arguments}} 43 return nullptr; 44 } 45 46 struct __attribute__((os_returns_not_retained)) NoNotRetainedAttrOnStruct {}; // expected-warning{{'os_returns_not_retained' attribute only applies to functions, Objective-C methods, Objective-C properties, and parameters}} 47 no_consumes_this_on_function()48__attribute__((os_consumes_this)) void no_consumes_this_on_function() {} // expected-warning{{'os_consumes_this' attribute only applies to non-static member functions}} 49 write_into_out_parameter(S ** out)50void write_into_out_parameter(__attribute__((os_returns_retained)) S** out) {} 51 write_into_out_parameter_on_nonzero(S ** out)52bool write_into_out_parameter_on_nonzero(__attribute__((os_returns_retained_on_non_zero)) S** out) {} 53 write_into_out_parameter_on_nonzero_invalid(S * out)54bool write_into_out_parameter_on_nonzero_invalid(__attribute__((os_returns_retained_on_non_zero)) S* out) {} // expected-warning{{'os_returns_retained_on_non_zero' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} 55 write_into_out_parameter_on_zero(S ** out)56bool write_into_out_parameter_on_zero(__attribute__((os_returns_retained_on_zero)) S** out) {} 57 write_into_out_parameter_on_zero_invalid(S * out)58bool write_into_out_parameter_on_zero_invalid(__attribute__((os_returns_retained_on_zero)) S* out) {} // expected-warning{{'os_returns_retained_on_zero' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} 59 write_into_out_parameter_ref(S * & out)60void write_into_out_parameter_ref(__attribute__((os_returns_retained)) S*& out) {} 61 62 typedef S* SPtr; 63 write_into_out_parameter_typedef(SPtr * out)64void write_into_out_parameter_typedef(__attribute__((os_returns_retained)) SPtr* out) {} 65 write_into_out_parameter_invalid(S * out)66void write_into_out_parameter_invalid(__attribute__((os_returns_retained)) S* out) {} // expected-warning{{'os_returns_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} 67 write_into_out_parameter_not_retained(S ** out)68void write_into_out_parameter_not_retained(__attribute__((os_returns_not_retained)) S **out) {} 69 write_into_out_parameter_not_retained(S volatile * const * const out)70void write_into_out_parameter_not_retained(__attribute__((os_returns_not_retained)) S volatile * const * const out) {} 71 write_into_not_retainedout_parameter_invalid(S * out)72void write_into_not_retainedout_parameter_invalid(__attribute__((os_returns_not_retained)) S* out) {} // expected-warning{{'os_returns_not_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} 73 write_into_not_retainedout_parameter_too_many_pointers(S *** out)74void write_into_not_retainedout_parameter_too_many_pointers(__attribute__((os_returns_not_retained)) S*** out) {} // expected-warning{{'os_returns_not_retained' attribute only applies to pointer/reference-to-OSObject-pointer parameters}} 75