Skip to content

Commit 946b1d4

Browse files
committed
Fix issues with the AddressLowering pass
Override the current SILModuleConvention of the SILModule when we perform the address lowering.
1 parent 6402d3d commit 946b1d4

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,14 @@ class SILBuilder {
316316
&F, OpenedArchetypes));
317317
}
318318

319-
ApplyInst *createApply(SILLocation Loc, SILValue Fn, SubstitutionList Subs,
320-
ArrayRef<SILValue> Args, bool isNonThrowing) {
319+
ApplyInst *
320+
createApply(SILLocation Loc, SILValue Fn, SubstitutionList Subs,
321+
ArrayRef<SILValue> Args, bool isNonThrowing,
322+
Optional<SILModuleConventions> ModuleConventions = None) {
321323
return insert(ApplyInst::create(getSILDebugLocation(Loc), Fn,
322-
Subs, Args, isNonThrowing, F,
324+
Subs, Args, isNonThrowing,
325+
ModuleConventions,
326+
F,
323327
OpenedArchetypes));
324328
}
325329

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ class ApplyInst : public ApplyInstBase<ApplyInst, SILInstruction> {
13001300
static ApplyInst *create(SILDebugLocation DebugLoc, SILValue Callee,
13011301
SubstitutionList Substitutions,
13021302
ArrayRef<SILValue> Args, bool isNonThrowing,
1303+
Optional<SILModuleConventions> ModuleConventions,
13031304
SILFunction &F,
13041305
SILOpenedArchetypesState &OpenedArchetypes);
13051306

lib/SIL/SILInstructions.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,24 @@ ApplyInst::ApplyInst(SILDebugLocation Loc, SILValue Callee,
408408

409409
ApplyInst *ApplyInst::create(SILDebugLocation Loc, SILValue Callee,
410410
SubstitutionList Subs, ArrayRef<SILValue> Args,
411-
bool isNonThrowing, SILFunction &F,
411+
bool isNonThrowing,
412+
Optional<SILModuleConventions> ModuleConventions,
413+
SILFunction &F,
412414
SILOpenedArchetypesState &OpenedArchetypes) {
413-
SILType SubstCalleeTy =
415+
SILType SubstCalleeSILTy =
414416
Callee->getType().substGenericArgs(F.getModule(), Subs);
415-
SILFunctionConventions Conv(SubstCalleeTy.getAs<SILFunctionType>(),
416-
F.getModule());
417+
auto SubstCalleeTy = SubstCalleeSILTy.getAs<SILFunctionType>();
418+
SILFunctionConventions Conv(SubstCalleeTy,
419+
ModuleConventions.hasValue()
420+
? ModuleConventions.getValue()
421+
: SILModuleConventions(F.getModule()));
417422
SILType Result = Conv.getSILResultType();
418423

419424
SmallVector<SILValue, 32> TypeDependentOperands;
420425
collectTypeDependentOperands(TypeDependentOperands, OpenedArchetypes, F,
421-
SubstCalleeTy.getSwiftRValueType(), Subs);
426+
SubstCalleeSILTy.getSwiftRValueType(), Subs);
422427
void *Buffer = allocate(F, Subs, TypeDependentOperands, Args);
423-
return ::new(Buffer) ApplyInst(Loc, Callee, SubstCalleeTy,
428+
return ::new(Buffer) ApplyInst(Loc, Callee, SubstCalleeSILTy,
424429
Result, Subs, Args,
425430
TypeDependentOperands, isNonThrowing);
426431
}

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,8 @@ void ApplyRewriter::convertApplyWithIndirectResults() {
966966
case ValueKind::ApplyInst:
967967
newCallInst = callBuilder.createApply(
968968
loc, apply.getCallee(), apply.getSubstitutions(), newCallArgs,
969-
cast<ApplyInst>(origCallInst)->isNonThrowing());
969+
cast<ApplyInst>(origCallInst)->isNonThrowing(),
970+
SILModuleConventions::getLoweredAddressConventions());
970971
break;
971972
case ValueKind::TryApplyInst:
972973
// TODO: insert dealloc in the catch block.

0 commit comments

Comments
 (0)