Skip to content

Cherrypick fixes for issue 74866 to swift/release/5.10 #9478

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions clang/include/clang/CodeGen/CodeGenABITypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,25 @@ const CGFunctionInfo &arrangeCXXMethodType(CodeGenModule &CGM,
const FunctionProtoType *FTP,
const CXXMethodDecl *MD);

const CGFunctionInfo &arrangeFreeFunctionCall(CodeGenModule &CGM,
CanQualType returnType,
ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
RequiredArgs args);
const CGFunctionInfo &
arrangeCXXMethodCall(CodeGenModule &CGM, CanQualType returnType,
ArrayRef<CanQualType> argTypes, FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs args);

const CGFunctionInfo &arrangeFreeFunctionCall(
CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs args);

// An overload with an empty `paramInfos`
inline const CGFunctionInfo &
arrangeFreeFunctionCall(CodeGenModule &CGM, CanQualType returnType,
ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info, RequiredArgs args) {
return arrangeFreeFunctionCall(CGM, returnType, argTypes, info, {}, args);
}

/// Returns the implicit arguments to add to a complete, non-delegating C++
/// constructor call.
Expand Down
23 changes: 16 additions & 7 deletions clang/lib/CodeGen/CodeGenABITypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,24 @@ CodeGen::arrangeCXXMethodType(CodeGenModule &CGM,
return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
}

const CGFunctionInfo &
CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM,
CanQualType returnType,
ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
RequiredArgs args) {
const CGFunctionInfo &CodeGen::arrangeCXXMethodCall(
CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs args) {
return CGM.getTypes().arrangeLLVMFunctionInfo(
returnType, /*instanceMethod=*/true, /*chainCall=*/false, argTypes, info,
paramInfos, args);
}

const CGFunctionInfo &CodeGen::arrangeFreeFunctionCall(
CodeGenModule &CGM, CanQualType returnType, ArrayRef<CanQualType> argTypes,
FunctionType::ExtInfo info,
ArrayRef<FunctionProtoType::ExtParameterInfo> paramInfos,
RequiredArgs args) {
return CGM.getTypes().arrangeLLVMFunctionInfo(
returnType, /*instanceMethod=*/false, /*chainCall=*/false, argTypes,
info, {}, args);
info, paramInfos, args);
}

ImplicitCXXConstructorArgs
Expand Down
31 changes: 30 additions & 1 deletion llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,10 +1477,20 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
BuildMI(MBB, MBBI, DL, TII->get(AArch64::LOADgot), AArch64::X16)
.addExternalSymbol("swift_async_extendedFramePointerFlags",
AArch64II::MO_GOT);
if (NeedsWinCFI) {
BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
.setMIFlags(MachineInstr::FrameSetup);
HasWinCFI = true;
}
BuildMI(MBB, MBBI, DL, TII->get(AArch64::ORRXrs), AArch64::FP)
.addUse(AArch64::FP)
.addUse(AArch64::X16)
.addImm(Subtarget.isTargetILP32() ? 32 : 0);
if (NeedsWinCFI) {
BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
.setMIFlags(MachineInstr::FrameSetup);
HasWinCFI = true;
}
break;
}
[[fallthrough]];
Expand All @@ -1491,6 +1501,11 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
.addUse(AArch64::FP)
.addImm(0x1100)
.setMIFlag(MachineInstr::FrameSetup);
if (NeedsWinCFI) {
BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
.setMIFlags(MachineInstr::FrameSetup);
HasWinCFI = true;
}
break;

case SwiftAsyncFramePointerMode::Never:
Expand Down Expand Up @@ -1621,11 +1636,20 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
bool HaveInitialContext = Attrs.hasAttrSomewhere(Attribute::SwiftAsync);
if (HaveInitialContext)
MBB.addLiveIn(AArch64::X22);
Register Reg = HaveInitialContext ? AArch64::X22 : AArch64::XZR;
BuildMI(MBB, MBBI, DL, TII->get(AArch64::StoreSwiftAsyncContext))
.addUse(HaveInitialContext ? AArch64::X22 : AArch64::XZR)
.addUse(Reg)
.addUse(AArch64::SP)
.addImm(FPOffset - 8)
.setMIFlags(MachineInstr::FrameSetup);
if (NeedsWinCFI) {
// WinCFI and arm64e, where StoreSwiftAsyncContext is expanded
// to multiple instructions, should be mutually-exclusive.
assert(Subtarget.getTargetTriple().getArchName() != "arm64e");
BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
.setMIFlags(MachineInstr::FrameSetup);
HasWinCFI = true;
}
}

// Issue sub fp, sp, FPOffset or
Expand Down Expand Up @@ -2123,6 +2147,11 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
.addUse(AArch64::FP)
.addImm(0x10fe)
.setMIFlag(MachineInstr::FrameDestroy);
if (NeedsWinCFI) {
BuildMI(MBB, MBBI, DL, TII->get(AArch64::SEH_Nop))
.setMIFlags(MachineInstr::FrameDestroy);
HasWinCFI = true;
}
break;

case SwiftAsyncFramePointerMode::Never:
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/AArch64/swift-async-context-seh.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: rm -rf %t && mkdir -p %t
; RUN: llc -mtriple aarch64-unknown-windows-msvc %s -o - | FileCheck %s
; RUN: llc -mtriple aarch64-unknown-windows-msvc -filetype obj %s -o %t/a.o

; Check that the prologue/epilogue instructions for the swift async
; context have an associated SEH instruction and that it doesn't error
; when the output is an object file.

; CHECK: orr x29, x29, #0x1000000000000000
; CHECK-NEXT: .seh_nop
; CHECK: str x22, [sp, #16]
; CHECK-NEXT: .seh_nop
; CHECK: and x29, x29, #0xefffffffffffffff
; CHECK-NEXT: .seh_nop

declare ptr @llvm.swift.async.context.addr()

define internal swifttailcc void @test(ptr nocapture readonly swiftasync %0) {
entryresume.0:
%1 = load ptr, ptr %0, align 8
%2 = tail call ptr @llvm.swift.async.context.addr()
store ptr %1, ptr %2, align 8
ret void
}