Skip to content

Commit 2de2239

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2022-05-29
2 parents 41502a8 + e848b0f commit 2de2239

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

include/swift/Runtime/RuntimeFnWrappersGen.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ namespace swift {
2525
class AvailabilityContext;
2626
class ASTContext;
2727

28+
namespace irgen {
29+
class IRGenModule;
30+
}
31+
2832
enum class RuntimeAvailability {
2933
AlwaysAvailable,
3034
AvailableByCompatibilityLibrary,
@@ -39,7 +43,8 @@ llvm::Constant *getRuntimeFn(llvm::Module &Module, llvm::Constant *&cache,
3943
RuntimeAvailability availability,
4044
llvm::ArrayRef<llvm::Type *> retTypes,
4145
llvm::ArrayRef<llvm::Type *> argTypes,
42-
llvm::ArrayRef<llvm::Attribute::AttrKind> attrs);
46+
llvm::ArrayRef<llvm::Attribute::AttrKind> attrs,
47+
irgen::IRGenModule *IGM = nullptr);
4348

4449
} // namespace swift
4550
#endif

lib/IRGen/GenCall.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ void IRGenModule::addSwiftErrorAttributes(llvm::AttributeList &attrs,
349349
// We create a shadow stack location of the swifterror parameter for the
350350
// debugger on such platforms and so we can't mark the parameter with a
351351
// swifterror attribute.
352-
if (IsSwiftErrorInRegister)
352+
if (ShouldUseSwiftError)
353353
b.addAttribute(llvm::Attribute::SwiftError);
354354

355355
// The error result should not be aliased, captured, or pointed at invalid
@@ -4245,7 +4245,7 @@ Address IRGenFunction::createErrorResultSlot(SILType errorType, bool isAsync) {
42454245
// The slot for async callees cannot be annotated swifterror because those
42464246
// errors are never passed in registers but rather are always passed
42474247
// indirectly in the async context.
4248-
if (IGM.IsSwiftErrorInRegister && !isAsync)
4248+
if (IGM.ShouldUseSwiftError && !isAsync)
42494249
cast<llvm::AllocaInst>(addr.getAddress())->setSwiftError(true);
42504250

42514251
// Initialize at the alloca point.

lib/IRGen/IRGenModule.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,16 +577,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
577577
AtomicBoolSize = Size(ClangASTContext->getTypeSize(atomicBoolTy));
578578
AtomicBoolAlign = Alignment(ClangASTContext->getTypeSize(atomicBoolTy));
579579
}
580-
581-
// On WebAssembly, tail optional arguments are not allowed because wasm requires
582-
// callee and caller signature should be same. So LLVM adds dummy arguments for
583-
// swiftself and swifterror. If there is swiftself but there isn't swifterror in
584-
// a swiftcc function or invocation, then LLVM adds dummy swifterror parameter or
580+
// On WebAssembly, tail optional arguments are not allowed because Wasm requires
581+
// callee and caller signature to be the same. So LLVM adds dummy arguments for
582+
// `swiftself` and `swifterror`. If there is `swiftself` but is no `swifterror` in
583+
// a swiftcc function or invocation, then LLVM adds dummy `swifterror` parameter or
585584
// argument. To count up how many dummy arguments should be added, we need to mark
586-
// it as swifterror even though it's not in register.
587-
//
588-
// TODO: Before sending patch, please rename `IsSwiftErrorInRegister` to `ShouldUseSwiftError`
589-
IsSwiftErrorInRegister =
585+
// it as `swifterror` even though it's not in register.
586+
ShouldUseSwiftError =
590587
clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister(
591588
ClangCodeGen->CGM()) || TargetInfo.OutputObjectFormat == llvm::Triple::Wasm;
592589

@@ -889,7 +886,8 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
889886
RuntimeAvailability availability,
890887
llvm::ArrayRef<llvm::Type*> retTypes,
891888
llvm::ArrayRef<llvm::Type*> argTypes,
892-
ArrayRef<Attribute::AttrKind> attrs) {
889+
ArrayRef<Attribute::AttrKind> attrs,
890+
IRGenModule *IGM) {
893891

894892
if (cache)
895893
return cache;
@@ -966,14 +964,17 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
966964
// Add swiftself and swifterror attributes only when swift_willThrow
967965
// swift_willThrow is defined in RuntimeFunctions.def, but due to the
968966
// DSL limitation, arguments attributes are not set.
969-
// On the other hand, caller of swift_willThrow assumes that it's attributed
970-
// with swiftself and swifterror.
967+
// On the other hand, caller of `swift_willThrow` assumes that it's attributed
968+
// with `swiftself` and `swifterror`.
971969
// This mismatch of attributes would be issue when lowering to WebAssembly.
972-
// While lowering, LLVM count up how many dummy params are necssary to match
970+
// While lowering, LLVM counts how many dummy params are necessary to match
973971
// callee and caller signature. So we need to add them correctly.
974972
if (functionName == "swift_willThrow") {
973+
assert(IGM && "IGM is required for swift_willThrow.");
975974
fn->addParamAttr(0, Attribute::AttrKind::SwiftSelf);
976-
fn->addParamAttr(1, Attribute::AttrKind::SwiftError);
975+
if (IGM->ShouldUseSwiftError) {
976+
fn->addParamAttr(1, Attribute::AttrKind::SwiftError);
977+
}
977978
}
978979
}
979980

@@ -1018,7 +1019,7 @@ void IRGenModule::registerRuntimeEffect(ArrayRef<RuntimeEffect> effect,
10181019
registerRuntimeEffect(EFFECT, #NAME); \
10191020
return getRuntimeFn(Module, ID##Fn, #NAME, CC, \
10201021
AVAILABILITY(this->Context), \
1021-
RETURNS, ARGS, ATTRS); \
1022+
RETURNS, ARGS, ATTRS, this); \
10221023
}
10231024

10241025
#include "swift/Runtime/RuntimeFunctions.def"

lib/IRGen/IRGenModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ class IRGenModule {
628628
/// Should we add value names to local IR values?
629629
bool EnableValueNames = false;
630630

631-
// Is swifterror returned in a register by the target ABI.
632-
bool IsSwiftErrorInRegister;
631+
// Should `swifterror` attribute be explicitly added for the target ABI.
632+
bool ShouldUseSwiftError;
633633

634634
llvm::Type *VoidTy; /// void (usually {})
635635
llvm::IntegerType *Int1Ty; /// i1

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4812,7 +4812,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
48124812
DebugValueInst *DbgValue) {
48134813
// We don't need a shadow error variable for debugging on ABI's that return
48144814
// swifterror in a register.
4815-
if (IGM.IsSwiftErrorInRegister)
4815+
if (IGM.ShouldUseSwiftError)
48164816
return;
48174817
auto ErrorResultSlot = getCalleeErrorResultSlot(IGM.silConv.getSILType(
48184818
ErrorInfo, FnTy, IGM.getMaximalTypeExpansionContext()));

test/ModuleInterface/SilencePreconcurrency.swiftinterface

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// swift-interface-format-version: 1.0
2-
// swift-module-flags: -target x86_64-apple-macos10.9 -module-name SilencePreconcurrency
2+
// swift-module-flags: -module-name SilencePreconcurrency
33

44
// RUN: %empty-directory(%t)
55
// RUN: %target-swift-frontend -compile-module-from-interface -o %/t/SilencePreconcurrency.swiftmodule %s -verify

0 commit comments

Comments
 (0)