| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s |
| 2 |
|
| 3 |
#define SWIFTCALL __attribute__((swiftcall)) |
| 4 |
#define SWIFTASYNCCALL __attribute__((swiftasynccall)) |
| 5 |
#define INDIRECT_RESULT __attribute__((swift_indirect_result)) |
| 6 |
#define ERROR_RESULT __attribute__((swift_error_result)) |
| 7 |
#define CONTEXT __attribute__((swift_context)) |
| 8 |
#define ASYNC_CONTEXT __attribute__((swift_async_context)) |
| 9 |
|
| 10 |
int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}} |
| 11 |
int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}} |
| 12 |
void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}} |
| 13 |
void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}} |
| 14 |
void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}} |
| 15 |
void multiple_ccs_async(int x) SWIFTASYNCCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftasynccall attributes are not compatible}} |
| 16 |
void (*functionPointer)(void) SWIFTCALL; |
| 17 |
void (*asyncFunctionPointer)(void) SWIFTASYNCCALL; |
| 18 |
|
| 19 |
void indirect_result_nonswift(INDIRECT_RESULT void *out); // expected-error {{'swift_indirect_result' parameter can only be used with swiftcall or swiftasynccall calling convention}} |
| 20 |
void indirect_result_bad_position(int first, INDIRECT_RESULT void *out) SWIFTCALL; // expected-error {{'swift_indirect_result' parameters must be first parameters of function}} |
| 21 |
void indirect_result_bad_type(INDIRECT_RESULT int out) SWIFTCALL; // expected-error {{'swift_indirect_result' parameter must have pointer type; type here is 'int'}} |
| 22 |
void indirect_result_single(INDIRECT_RESULT void *out) SWIFTCALL; |
| 23 |
void indirect_result_multiple(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTCALL; |
| 24 |
void indirect_result_single_async(INDIRECT_RESULT void *out) SWIFTASYNCCALL; |
| 25 |
void indirect_result_multiple_async(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTASYNCCALL; |
| 26 |
|
| 27 |
void error_result_nonswift(ERROR_RESULT void **error); // expected-error {{'swift_error_result' parameter can only be used with swiftcall calling convention}} expected-error{{'swift_error_result' parameter must follow 'swift_context' parameter}} |
| 28 |
void error_result_bad_position2(int first, ERROR_RESULT void **error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must follow 'swift_context' parameter}} |
| 29 |
void error_result_bad_type(CONTEXT void *context, ERROR_RESULT int error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int'}} |
| 30 |
void error_result_bad_type2(CONTEXT void *context, ERROR_RESULT int *error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must have pointer to unqualified pointer type; type here is 'int *'}} |
| 31 |
void error_result_okay(int a, int b, CONTEXT void *context, ERROR_RESULT void **error) SWIFTCALL; |
| 32 |
void error_result_okay(CONTEXT void *context, ERROR_RESULT void **error, void *selfType, char **selfWitnessTable) SWIFTCALL; |
| 33 |
|
| 34 |
void context_nonswift(CONTEXT void *context); // expected-error {{'swift_context' parameter can only be used with swiftcall or swiftasynccall calling convention}} |
| 35 |
void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}} |
| 36 |
void context_okay(CONTEXT void *context) SWIFTCALL; |
| 37 |
void context_okay(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL; |
| 38 |
void context_okay_async(CONTEXT void *context) SWIFTASYNCCALL; |
| 39 |
void context_okay2_async(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTASYNCCALL; |
| 40 |
|
| 41 |
void async_context_nonswift(ASYNC_CONTEXT void *context); // OK |
| 42 |
void async_context_bad_type(ASYNC_CONTEXT int context) SWIFTASYNCCALL; // expected-error {{'swift_async_context' parameter must have pointer type; type here is 'int'}} |
| 43 |
void async_context_okay(ASYNC_CONTEXT void *context) SWIFTASYNCCALL; |
| 44 |
void async_context_okay(void *someArg, ASYNC_CONTEXT void *context, void *otherArg) SWIFTASYNCCALL; |
| 45 |
|
| 46 |
template <class T> void indirect_result_temp_okay1(INDIRECT_RESULT T *out) SWIFTCALL; |
| 47 |
template <class T> void indirect_result_temp_okay2(INDIRECT_RESULT T out) SWIFTCALL; // expected-note {{candidate template ignored: substitution failure [with T = int]: 'swift_indirect_result' parameter must have pointer type; type here is 'int'}} |
| 48 |
void test_indirect_result_temp(void *out) { |
| 49 |
indirect_result_temp_okay1(out); |
| 50 |
indirect_result_temp_okay2(out); |
| 51 |
indirect_result_temp_okay2(1); // expected-error {{no matching function for call to 'indirect_result_temp_okay2'}} |
| 52 |
} |