Skip to content

Commit 3e0ddba

Browse files
committed
Merge pull request #2628 from bitjammer/capture-descriptor-param-count-26404583
SwiftRemoteMirror: Fix crash emitting capture descriptors involving i…
2 parents e500692 + aa86d1d commit 3e0ddba

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,6 @@ void irgen::emitFunctionPartialApplication(IRGenFunction &IGF,
11201120
argConventions.push_back(ParameterConvention::Direct_Unowned);
11211121
}
11221122

1123-
// For capture descriptors, we need to know where the capture list begins
1124-
// in the lowered SIL type of the callee.
1125-
unsigned firstCaptureIndex = origType->getNumSILArguments() - params.size();
1126-
11271123
// Collect the type infos for the context parameters.
11281124
for (auto param : params) {
11291125
SILType argType = param.getSILType();
@@ -1305,8 +1301,7 @@ void irgen::emitFunctionPartialApplication(IRGenFunction &IGF,
13051301

13061302
auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, origType,
13071303
substType, subs,
1308-
layout,
1309-
firstCaptureIndex);
1304+
layout);
13101305

13111306
llvm::Value *data;
13121307
if (layout.isKnownEmpty()) {

lib/IRGen/GenReflection.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,20 +525,18 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
525525
CanSILFunctionType SubstCalleeType;
526526
ArrayRef<Substitution> Subs;
527527
HeapLayout &Layout;
528-
unsigned FirstCaptureIndex;
529528
public:
530529
CaptureDescriptorBuilder(IRGenModule &IGM,
531530
llvm::SetVector<CanType> &BuiltinTypes,
532531
SILFunction &Caller,
533532
CanSILFunctionType OrigCalleeType,
534533
CanSILFunctionType SubstCalleeType,
535534
ArrayRef<Substitution> Subs,
536-
HeapLayout &Layout,
537-
unsigned FirstCaptureIndex)
535+
HeapLayout &Layout)
538536
: ReflectionMetadataBuilder(IGM, BuiltinTypes),
539537
Caller(Caller), OrigCalleeType(OrigCalleeType),
540538
SubstCalleeType(SubstCalleeType), Subs(Subs),
541-
Layout(Layout), FirstCaptureIndex(FirstCaptureIndex) {}
539+
Layout(Layout) {}
542540

543541
using MetadataSourceMap
544542
= std::vector<std::pair<CanType, const reflection::MetadataSource*>>;
@@ -617,15 +615,6 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
617615
// dereferencing an isa pointer or a generic argument). Record
618616
// the path. We assume captured values map 1-1 with function
619617
// parameters.
620-
auto ParamIndex = ConventionSource.getParamIndex();
621-
auto Index = ParamIndex - FirstCaptureIndex;
622-
623-
auto ParamType = SubstCalleeType->getParameters()[ParamIndex].getSILType();
624-
auto CaptureType = getElementTypes()[Index];
625-
assert(ParamType == CaptureType);
626-
(void) ParamType;
627-
(void) CaptureType;
628-
629618
auto Root = ConventionSource.getMetadataSource(SourceBuilder);
630619
auto Src = Fulfillment->Path.getMetadataSource(SourceBuilder, Root);
631620

@@ -772,15 +761,14 @@ IRGenModule::getAddrOfCaptureDescriptor(SILFunction &Caller,
772761
CanSILFunctionType OrigCalleeType,
773762
CanSILFunctionType SubstCalleeType,
774763
ArrayRef<Substitution> Subs,
775-
HeapLayout &Layout,
776-
unsigned FirstCaptureIndex) {
764+
HeapLayout &Layout) {
777765
if (!IRGen.Opts.EnableReflectionMetadata)
778766
return llvm::Constant::getNullValue(CaptureDescriptorPtrTy);
779767

780768
llvm::SetVector<CanType> BuiltinTypes;
781769
CaptureDescriptorBuilder builder(*this, BuiltinTypes, Caller,
782770
OrigCalleeType, SubstCalleeType, Subs,
783-
Layout, FirstCaptureIndex);
771+
Layout);
784772

785773
auto var = builder.emit();
786774
if (var)

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ class IRGenModule {
629629
CanSILFunctionType origCalleeType,
630630
CanSILFunctionType substCalleeType,
631631
ArrayRef<Substitution> subs,
632-
HeapLayout &layout,
633-
unsigned firstCaptureIndex);
632+
HeapLayout &layout);
634633
std::string getBuiltinTypeMetadataSectionName();
635634
std::string getFieldTypeMetadataSectionName();
636635
std::string getAssociatedTypeMetadataSectionName();

0 commit comments

Comments
 (0)