From b15588ed15fdd83db98b6e923ae48118524077a9 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Mon, 17 Jun 2013 02:40:13 +0200 Subject: [PATCH] Finally fix the _d_invariant declaration on x86. --- gen/runtime.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 65affd3f..c6e4af34 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -22,6 +22,7 @@ #include "gen/logger.h" #include "gen/tollvm.h" #include "ir/irtype.h" +#include "ir/irtypefunction.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MemoryBuffer.h" @@ -94,6 +95,7 @@ llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name LLFunctionType* fnty = fn->getFunctionType(); LLFunction* resfn = llvm::cast(target->getOrInsertFunction(name, fnty)); resfn->setAttributes(fn->getAttributes()); + resfn->setCallingConv(fn->getCallingConv()); return resfn; } @@ -902,10 +904,23 @@ static void LLVM_D_BuildRuntimeModule() // void invariant._d_invariant(Object o) { + // KLUDGE: _d_invariant is actually extern(D) in the upstream runtime, possibly + // for more efficient parameter passing on x86. This complicates our code here + // quite a bit, though. llvm::StringRef fname("_D9invariant12_d_invariantFC6ObjectZv"); - LLType *types[] = { objectTy }; - LLFunctionType* fty = llvm::FunctionType::get(voidTy, types, false); - llvm::Function* fn = llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M); + Parameters* params = new Parameters(); + params->push(new Parameter(STCin, ClassDeclaration::object->type, NULL, NULL)); + TypeFunction* dty = new TypeFunction(params, Type::tvoid, 0, LINKd); + llvm::Function* fn = llvm::Function::Create(llvm::cast(DtoType(dty)), + llvm::GlobalValue::ExternalLinkage, fname, M); + gABI->newFunctionType(dty); + gABI->rewriteFunctionType(dty); + gABI->doneWithFunctionType(); +#if LDC_LLVM_VER < 303 + fn->addAttribute(1, dty->fty.args[0]->attrs); +#else + fn->addAttributes(1, llvm::AttributeSet::get(gIR->context(), 1, dty->fty.args[0]->attrs)); +#endif fn->setCallingConv(gABI->callingConv(LINKd)); }