-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add frontend flag for explicitly setting ccc #66072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also want to change:
lib/IRGen/GenHeap.cpp: metadata->setCallingConv(llvm::CallingConv::C);
lib/IRGen/IRGenModule.cpp: C_CC = llvm::CallingConv::C;
include/swift/AST/IRGenOptions.h
Outdated
@@ -477,6 +478,9 @@ class IRGenOptions { | |||
/// function instead of to trap instructions. | |||
std::string TrapFuncName = ""; | |||
|
|||
/// The calling convention used to perform non-swift calls. | |||
llvm::CallingConv::ID ExperimentalPlatformCCallingConvention; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets drop the word Experimental
.
Adds a new swift-frontend flag to allow users to choose which calling convention is used to make c function calls. This hidden flag is called `-experimental-platform-c-calling-convention`. This behavior is needed to workaround rdar://109431863 (Swift-frontend produces trapping llvm ir for non-trapping sil). The root cause of this issue is that IRGen always emits c function calls with llvm's default C calling convention. However clang may select a different (incompatible) calling convention for the function, eventually resulting--via InstCombine and SimplifyCFG--in a trap instead of the function call. This failure mode is most readily seen with the triple `armv7em-apple-none-macho` when attempting to call functions taking struct arguments. Example unoptimized ir below: ```llvm-ir call void @bar([4 x i32] %17, i32 2), !dbg !109 ... define internal arm_aapcs_vfpcc void @bar( [4 x i32] %bar.coerce, i32 noundef %x) ``` In the future it would be better to use the clang importer or some other tool to determine the calling convention for each function instead of setting the calling convention frontend invocation wide. Note: I don't know for sure whether or not clang should be explicitly annotating these functions with a calling convention instead of aliasing C to mean ARM_AAPCS_VFP for this particular combination of `-target`, `-mfloat-abi`, and `-mcpu`.
- Renames ExperimentalPlatformCCallingConvention to PlatformCCallingConvention. - Removes non-arm calling convention support as this feature is working around a clang bug for some arm triples which we hope to see resolved. - Removes misleading MetaVarName from platform-c-calling-convention argument. - Replaces other uses of LLVM::CallingConv::C with IGM.getOptions().PlatformCCallingConvention().
@swift-ci please test |
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
Adds a new swift-frontend flag to allow users to choose which calling convention is used to make c function calls. This hidden flag is called
-experimental-platform-c-calling-convention
.This behavior is needed to workaround rdar://109431863 (Swift-frontend produces trapping llvm ir for non-trapping sil). The root cause of this issue is that IRGen always emits c function calls with llvm's default C calling convention. However clang may select a different (incompatible) calling convention for the function, eventually resulting--via InstCombine and SimplifyCFG--in a trap instead of the function call. This failure mode is most readily seen with the triple
armv7em-apple-none-macho
when attempting to call functions taking struct arguments. Example unoptimized ir below:In the future it would be better to use the clang importer or some other tool to determine the calling convention for each function instead of setting the calling convention frontend invocation wide.
Note: I don't know for sure whether or not clang should be explicitly annotating these functions with a calling convention instead of aliasing C to mean ARM_AAPCS_VFP for this particular combination of
-target
,-mfloat-abi
, and-mcpu
.