mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 15:40:55 +03:00
SWITCHED TO LLVM 2.5 !
Applied patch from ticket #129 to compile against latest LLVM. Thanks Frits van Bommel. Fixed implicit return by asm block at the end of a function on x86-32. Other architectures will produce an error at the moment. Adding support for new targets is fairly simple. Fixed return calling convention for complex numbers, ST and ST(1) were switched around. Added some testcases. I've run a dstress test and there are no regressions. However, the runtime does not seem to compile with symbolic debug information. -O3 -release -inline works well and is what I used for the dstress run. Tango does not compile, a small workaround is needed in tango.io.digest.Digest.Digest.hexDigest. See ticket #206 .
This commit is contained in:
parent
3f7c7c5327
commit
fc480b7fd8
29 changed files with 404 additions and 81 deletions
|
@ -907,6 +907,10 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
// output function body
|
||||
fd->fbody->toIR(gIR);
|
||||
|
||||
// TODO: clean up this mess
|
||||
|
||||
// std::cout << *func << std::endl;
|
||||
|
||||
// llvm requires all basic blocks to end with a TerminatorInst but DMD does not put a return statement
|
||||
// in automatically, so we do it here.
|
||||
if (!gIR->scopereturned()) {
|
||||
|
@ -917,12 +921,23 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
}
|
||||
else {
|
||||
if (!fd->isMain())
|
||||
llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
|
||||
{
|
||||
AsmBlockStatement* asmb = fd->fbody->endsWithAsm();
|
||||
if (asmb) {
|
||||
assert(asmb->abiret);
|
||||
llvm::ReturnInst::Create(asmb->abiret, gIR->scopebb());
|
||||
}
|
||||
else {
|
||||
llvm::ReturnInst::Create(llvm::UndefValue::get(func->getReturnType()), gIR->scopebb());
|
||||
}
|
||||
}
|
||||
else
|
||||
llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), gIR->scopebb());
|
||||
}
|
||||
}
|
||||
|
||||
// std::cout << *func << std::endl;
|
||||
|
||||
// erase alloca point
|
||||
allocaPoint->eraseFromParent();
|
||||
allocaPoint = 0;
|
||||
|
@ -934,28 +949,9 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
|||
assert(!func->getBasicBlockList().empty());
|
||||
func->getBasicBlockList().pop_back();
|
||||
|
||||
// if the last block is empty now, it must be unreachable or it's a bug somewhere else
|
||||
// would be nice to figure out how to assert that this is correct
|
||||
llvm::BasicBlock* lastbb = &func->getBasicBlockList().back();
|
||||
if (lastbb->empty())
|
||||
{
|
||||
new llvm::UnreachableInst(lastbb);
|
||||
}
|
||||
|
||||
// if the last block is not terminated we return a null value or void
|
||||
// for some unknown reason this is needed when a void main() has a inline asm block ...
|
||||
// this should be harmless for well formed code!
|
||||
lastbb = &func->getBasicBlockList().back();
|
||||
if (!lastbb->getTerminator())
|
||||
{
|
||||
Logger::println("adding missing return statement");
|
||||
if (func->getReturnType() == LLType::VoidTy)
|
||||
llvm::ReturnInst::Create(lastbb);
|
||||
else
|
||||
llvm::ReturnInst::Create(llvm::Constant::getNullValue(func->getReturnType()), lastbb);
|
||||
}
|
||||
|
||||
gIR->functions.pop_back();
|
||||
|
||||
// std::cout << *func << std::endl;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue