SILGen: Fix dynamic replacement before original function

Creating a @_dynamicReplacement function requires the creation of a
reference to the original function. We need to call SILGenModule's
getFunction to satisfy all the assertions in place.

rdar://59774606
This commit is contained in:
Arnold Schwaighofer
2020-02-26 09:37:30 -08:00
parent c1edc2c31c
commit cae695e81b
4 changed files with 47 additions and 21 deletions

View File

@@ -80,10 +80,16 @@ class SILFunctionBuilder {
SubclassScope subclassScope = SubclassScope::NotApplicable);
/// Return the declaration of a function, or create it if it doesn't exist.
SILFunction *
getOrCreateFunction(SILLocation loc, SILDeclRef constant,
ForDefinition_t forDefinition,
ProfileCounter entryCount = ProfileCounter());
/// Creating a function that references another function (a dynamic
/// replacement) requires getting/creating a SIL function for this reference.
/// In this case the function will call the \p getOrCreateDeclaration
/// callback.
SILFunction *getOrCreateFunction(
SILLocation loc, SILDeclRef constant, ForDefinition_t forDefinition,
llvm::function_ref<SILFunction *(SILLocation loc, SILDeclRef constant)>
getOrCreateDeclaration = [](SILLocation loc, SILDeclRef constant)
-> SILFunction * { return nullptr; },
ProfileCounter entryCount = ProfileCounter());
/// Create a function declaration.
///
@@ -104,8 +110,11 @@ class SILFunctionBuilder {
SILFunction *InsertBefore = nullptr,
const SILDebugScope *DebugScope = nullptr);
void addFunctionAttributes(SILFunction *F, DeclAttributes &Attrs,
SILModule &M, SILDeclRef constant = SILDeclRef());
void addFunctionAttributes(
SILFunction *F, DeclAttributes &Attrs, SILModule &M,
llvm::function_ref<SILFunction *(SILLocation loc, SILDeclRef constant)>
getOrCreateDeclaration,
SILDeclRef constant = SILDeclRef());
/// We do not expose this to everyone, instead we allow for our users to opt
/// into this if they need to. Please do not do this in general! We only want