From: Arnold Schwaighofer Date: Tue, 11 Oct 2016 20:34:06 +0000 (+0000) Subject: Swift Calling Convention: Parameters are allowed after the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00d311a51369c41efbdae2e4935713fa10bb0e91;p=clang Swift Calling Convention: Parameters are allowed after the swift_error/swift_context parameter We need to be able to decelare witness functions which append the self type and the self witness tables at the end of the parameter list. rdar://28720996 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283933 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index b0f18fd1bd..0f2ec79ba3 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -2400,28 +2400,16 @@ static void checkExtParameterInfos(Sema &S, ArrayRef paramTypes, } continue; - // swift_context parameters must be the last parameter except for - // a possible swift_error parameter. case ParameterABI::SwiftContext: checkForSwiftCC(paramIndex); - if (!(paramIndex == numParams - 1 || - (paramIndex == numParams - 2 && - EPI.ExtParameterInfos[numParams - 1].getABI() - == ParameterABI::SwiftErrorResult))) { - S.Diag(getParamLoc(paramIndex), - diag::err_swift_context_not_before_swift_error_result); - } continue; - // swift_error parameters must be the last parameter. + // swift_error parameters must be preceded by a swift_context parameter. case ParameterABI::SwiftErrorResult: checkForSwiftCC(paramIndex); - if (paramIndex != numParams - 1) { - S.Diag(getParamLoc(paramIndex), - diag::err_swift_error_result_not_last); - } else if (paramIndex == 0 || - EPI.ExtParameterInfos[paramIndex - 1].getABI() - != ParameterABI::SwiftContext) { + if (paramIndex == 0 || + EPI.ExtParameterInfos[paramIndex - 1].getABI() != + ParameterABI::SwiftContext) { S.Diag(getParamLoc(paramIndex), diag::err_swift_error_result_not_after_swift_context); } diff --git a/test/Sema/attr-swiftcall.c b/test/Sema/attr-swiftcall.c index 3458167cf2..1720612290 100644 --- a/test/Sema/attr-swiftcall.c +++ b/test/Sema/attr-swiftcall.c @@ -18,13 +18,13 @@ void indirect_result_single(INDIRECT_RESULT void *out) SWIFTCALL; void indirect_result_multiple(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTCALL; 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}} -void error_result_bad_position(ERROR_RESULT void **error, int last) SWIFTCALL; // expected-error {{'swift_error_result' parameter must be last parameter of function}} void error_result_bad_position2(int first, ERROR_RESULT void **error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must follow 'swift_context' parameter}} 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'}} 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 *'}} void error_result_okay(int a, int b, CONTEXT void *context, ERROR_RESULT void **error) SWIFTCALL; +void error_result_okay2(CONTEXT void *context, ERROR_RESULT void **error, void *selfType, char **selfWitnessTable) SWIFTCALL; void context_nonswift(CONTEXT void *context); // expected-error {{'swift_context' parameter can only be used with swiftcall calling convention}} -void context_bad_position(CONTEXT void *context, int x) SWIFTCALL; // expected-error {{'swift_context' parameter can only be followed by 'swift_error_result' parameter}} void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}} void context_okay(CONTEXT void *context) SWIFTCALL; +void context_okay2(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL; diff --git a/test/SemaCXX/attr-swiftcall.cpp b/test/SemaCXX/attr-swiftcall.cpp index fd17aae185..eb9538e310 100644 --- a/test/SemaCXX/attr-swiftcall.cpp +++ b/test/SemaCXX/attr-swiftcall.cpp @@ -17,16 +17,16 @@ void indirect_result_single(INDIRECT_RESULT void *out) SWIFTCALL; void indirect_result_multiple(INDIRECT_RESULT void *out1, INDIRECT_RESULT void *out2) SWIFTCALL; 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}} -void error_result_bad_position(ERROR_RESULT void **error, int last) SWIFTCALL; // expected-error {{'swift_error_result' parameter must be last parameter of function}} void error_result_bad_position2(int first, ERROR_RESULT void **error) SWIFTCALL; // expected-error {{'swift_error_result' parameter must follow 'swift_context' parameter}} 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'}} 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 *'}} void error_result_okay(int a, int b, CONTEXT void *context, ERROR_RESULT void **error) SWIFTCALL; +void error_result_okay(CONTEXT void *context, ERROR_RESULT void **error, void *selfType, char **selfWitnessTable) SWIFTCALL; void context_nonswift(CONTEXT void *context); // expected-error {{'swift_context' parameter can only be used with swiftcall calling convention}} -void context_bad_position(CONTEXT void *context, int x) SWIFTCALL; // expected-error {{'swift_context' parameter can only be followed by 'swift_error_result' parameter}} void context_bad_type(CONTEXT int context) SWIFTCALL; // expected-error {{'swift_context' parameter must have pointer type; type here is 'int'}} void context_okay(CONTEXT void *context) SWIFTCALL; +void context_okay(CONTEXT void *context, void *selfType, char **selfWitnessTable) SWIFTCALL; template void indirect_result_temp_okay1(INDIRECT_RESULT T *out) SWIFTCALL; template 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'}}