mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-10 21:06:33 +03:00
Fixed forward reference problem in struct methods on x86-64.
This commit is contained in:
parent
e61562033d
commit
740cdaa588
3 changed files with 27 additions and 0 deletions
|
@ -303,6 +303,16 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
|||
return; // ignore declaration completely
|
||||
}
|
||||
|
||||
if (AggregateDeclaration* ad = fdecl->isMember())
|
||||
{
|
||||
ad->codegen(Type::sir);
|
||||
if (ad->isStructDeclaration() && llvm::isa<llvm::OpaqueType>(DtoType(ad->type)))
|
||||
{
|
||||
ad->ir.irStruct->structFuncs.push_back(fdecl);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//printf("resolve function: %s\n", fdecl->toPrettyChars());
|
||||
|
||||
if (fdecl->parent)
|
||||
|
@ -434,6 +444,8 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
|
|||
|
||||
void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||
{
|
||||
DtoResolveFunction(fdecl);
|
||||
|
||||
if (fdecl->ir.declared) return;
|
||||
fdecl->ir.declared = true;
|
||||
|
||||
|
@ -478,6 +490,9 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
|||
if (!func)
|
||||
func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module);
|
||||
|
||||
if (Logger::enabled())
|
||||
Logger::cout() << "func = " << *func << std::endl;
|
||||
|
||||
// add func to IRFunc
|
||||
fdecl->ir.irFunc->func = func;
|
||||
|
||||
|
@ -594,6 +609,8 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
|||
|
||||
void DtoDefineFunction(FuncDeclaration* fd)
|
||||
{
|
||||
DtoDeclareFunction(fd);
|
||||
|
||||
if (fd->ir.defined) return;
|
||||
fd->ir.defined = true;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "gen/logger.h"
|
||||
#include "gen/structs.h"
|
||||
#include "gen/dvalue.h"
|
||||
#include "gen/functions.h"
|
||||
|
||||
#include "ir/irstruct.h"
|
||||
|
||||
|
@ -583,6 +584,14 @@ void DtoResolveStruct(StructDeclaration* sd)
|
|||
gIR->module->addTypeName(sd->mangle(),ST);
|
||||
}
|
||||
|
||||
// emit functions
|
||||
size_t n = irstruct->structFuncs.size();
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
DtoResolveFunction(irstruct->structFuncs[i]);
|
||||
}
|
||||
irstruct->structFuncs.clear();
|
||||
|
||||
gIR->structs.pop_back();
|
||||
|
||||
DtoDeclareStruct(sd);
|
||||
|
|
|
@ -152,6 +152,7 @@ struct IrStruct : IrBase
|
|||
llvm::DICompositeType diCompositeType;
|
||||
|
||||
std::vector<VarDeclaration*> staticVars;
|
||||
std::vector<FuncDeclaration*> structFuncs;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue