Skip to content

Commit 5fa92dc

Browse files
committed
[IRGen] Use ABI notion of function parameter flags to compute ‘has parameter flags’ bit.
There are some cases where the AST’s notion of what constitutes function parameter flags differ from the ABI notion. Specifically, these are @escaping and @autoclosure, which are both modeled as types in the ABI. Teach IRGen to look at the ABI’s version of function parameter flags when determining whether to pass parameter flags to swift_getFunctionType([0-3])?. Without this fix, we would end up with mismatches between the function types built by IRGen and those built from mangled names. Part of rdar://problem/37551850.
1 parent c5e226b commit 5fa92dc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,17 @@ namespace {
924924
auto params = type.getParams();
925925
auto numParams = params.size();
926926

927+
// Retrieve the ABI parameter flags from the type-level parameter
928+
// flags.
929+
auto getABIParameterFlags = [](ParameterTypeFlags flags) {
930+
return ParameterFlags()
931+
.withValueOwnership(flags.getValueOwnership())
932+
.withVariadic(flags.isVariadic());
933+
};
934+
927935
bool hasFlags = false;
928936
for (auto param : params) {
929-
if (!param.getParameterFlags().isNone()) {
937+
if (!getABIParameterFlags(param.getParameterFlags()).isNone()) {
930938
hasFlags = true;
931939
break;
932940
}
@@ -969,11 +977,7 @@ namespace {
969977
auto param = params[index];
970978
auto flags = param.getParameterFlags();
971979

972-
auto parameterFlags =
973-
ParameterFlags()
974-
.withValueOwnership(flags.getValueOwnership())
975-
.withVariadic(flags.isVariadic());
976-
980+
auto parameterFlags = getABIParameterFlags(flags);
977981
processor(index, getFunctionParameterRef(param), parameterFlags);
978982
}
979983
};

test/IRGen/function_metadata.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ func test_arch() {
5151
// CHECK: store %swift.type* @"$ss4Int8VN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]]
5252
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663300, %swift.type** {{%.*}}, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @parameter-flags.{{.*}}, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1))
5353
arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in })
54+
55+
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa"
56+
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1(i64 67108865
57+
arch({(x: @escaping () -> ()) -> () in })
5458
}

0 commit comments

Comments
 (0)