Skip to content

IRGen: Fix witness-table accessors for conditional conformances #15397

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

Merged
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
6 changes: 4 additions & 2 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ static llvm::Value *emitWitnessTableAccessorCall(
// If the conformance is generic, the accessor takes the metatype plus
// possible conditional conformances arguments.
llvm::CallInst *call;
bool requiresMemoryArguments = false;
if (conformance->witnessTableAccessorRequiresArguments()) {
// Emit the source metadata if we haven't yet.
if (!*srcMetadataCache) {
Expand All @@ -1051,13 +1052,14 @@ static llvm::Value *emitWitnessTableAccessorCall(

call = IGF.Builder.CreateCall(accessor,
{*srcMetadataCache, conditionalTables});

requiresMemoryArguments = true;
} else {
call = IGF.Builder.CreateCall(accessor, {});
}

call->setCallingConv(IGF.IGM.DefaultCC);
call->setDoesNotAccessMemory();
if (!requiresMemoryArguments)
call->setDoesNotAccessMemory();
call->setDoesNotThrow();

return call;
Expand Down
3 changes: 2 additions & 1 deletion test/Inputs/conditional_conformance_basic_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public func single_concrete() {
// CHECK-NEXT: [[A_P2_PTR:%.*]] = getelementptr inbounds i8**, i8*** [[CONDITIONAL_REQUIREMENTS]], i32 0
// CHECK-NEXT: store i8** getelementptr inbounds ([1 x i8*], [1 x i8*]* @"$S42conditional_conformance_basic_conformances4IsP2VAA0F0AAWP", i32 0, i32 0), i8*** [[A_P2_PTR]], align 8

// CHECK-NEXT: [[Single_P1:%.*]] = call i8** @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWa"(%swift.type* [[Single_TYPE]], i8*** [[CONDITIONAL_REQUIREMENTS]])
// CHECK-NEXT: [[Single_P1:%.*]] = call i8** @"$S42conditional_conformance_basic_conformances6SingleVyxGAA2P1A2A2P2RzlWa"(%swift.type* [[Single_TYPE]], i8*** [[CONDITIONAL_REQUIREMENTS]]) [[ATTRS:#[0-9]+]]
// CHECK-NEXT: store atomic i8** [[Single_P1]], i8*** @"$S42conditional_conformance_basic_conformances6SingleVyAA4IsP2VGACyxGAA2P1A2A0G0RzlWL" release, align 8
// CHECK-NEXT: br label %cont

Expand Down Expand Up @@ -304,3 +304,4 @@ protocol P5 {}
struct SR7101<T> {}
extension SR7101 : P5 where T == P4Typealias {}

// CHECK: attributes [[ATTRS]] = { nounwind }