Skip to content

Commit e1989dd

Browse files
committed
[interop][SwiftToCxx] verify that lowered function signature represented all LLVM IR params
1 parent c351f3a commit e1989dd

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,7 @@ SignatureExpansionABIDetails Signature::getUncachedABIDetails(
19861986
SignatureExpansion expansion(IGM, formalType, kind);
19871987
SignatureExpansionABIDetails result;
19881988
expansion.expandFunctionType(&result);
1989+
result.numParamIRTypesInSignature = expansion.ParamIRTypes.size();
19891990
return result;
19901991
}
19911992

lib/IRGen/IRABIDetailsProvider.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ class IRABIDetailsProviderImpl {
188188
result.metadataSourceTypes.push_back(canType);
189189
});
190190
}
191+
// Verify that the signature param count matches the IR param count.
192+
size_t signatureParamCount = 0;
193+
result.visitParameterList(
194+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
195+
IndirectResultValue &indirectResult) { ++signatureParamCount; },
196+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
197+
DirectParameter &param) {
198+
param.enumerateRecordMembers([&](clang::CharUnits, clang::CharUnits,
199+
Type) { ++signatureParamCount; });
200+
},
201+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
202+
IndirectParameter &param) { ++signatureParamCount; },
203+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
204+
GenericRequirementParameter &genericRequirementParam) {
205+
++signatureParamCount;
206+
},
207+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
208+
MetadataSourceParameter &metadataSrcParam) {
209+
++signatureParamCount;
210+
},
211+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
212+
ContextParameter &) { ++signatureParamCount; },
213+
[&](const IRABIDetailsProvider::LoweredFunctionSignature::
214+
ErrorResultValue &) { ++signatureParamCount; });
215+
// Return nothing if we were unable to represent the exact signature
216+
// parameters.
217+
if (signatureParamCount != abiDetails->numParamIRTypesInSignature)
218+
return None;
219+
191220
return result;
192221
}
193222

lib/IRGen/Signature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class SignatureExpansionABIDetails {
163163
bool hasContextParam = false;
164164
/// True if an error result value indirect parameter is passed to the call.
165165
bool hasErrorResult = false;
166+
/// The number of LLVM IR parameters in the LLVM IR function signature.
167+
size_t numParamIRTypesInSignature = 0;
166168
};
167169

168170
/// A signature represents something which can actually be called.

0 commit comments

Comments
 (0)