From 280be5ef8e095525ddc4890829f8c39c37fbec71 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 3 Feb 2009 23:48:47 +0100 Subject: [PATCH 1/6] Fixed dstress/run/a/array_initialization_17_A.d regression. default initialized static array elements in a constant static array initializer was getting incorrect values. Fixed minor version problem in mini/naked_asm4.d test case. --- gen/arrays.cpp | 2 +- gen/toir.cpp | 2 ++ tests/mini/naked_asm4.d | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index c310abee..43645f73 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -290,7 +290,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) // fill out any null entries still left with default values // element default initializer - LLConstant* defelem = elemty->defaultInit(arrinit->loc)->toConstElem(gIR); + LLConstant* defelem = DtoConstExpInit(arrinit->loc, elemty, elemty->defaultInit(arrinit->loc)); bool mismatch2 = (defelem->getType() != llelemty); for (size_t i = 0; i < arrlen; i++) diff --git a/gen/toir.cpp b/gen/toir.cpp index b3b10392..7cffd4cc 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1632,6 +1632,8 @@ DValue* NewExp::toElem(IRState* p) DVarValue tmpvar(newtype, mem); // default initialize + // FIXME: should this use DtoConstExpInit instead ? + // or is static arrays the only troublemaker? Expression* exp = newtype->defaultInit(loc); DValue* iv = exp->toElem(gIR); DtoAssign(loc, &tmpvar, iv); diff --git a/tests/mini/naked_asm4.d b/tests/mini/naked_asm4.d index 5303dc66..116a92c9 100644 --- a/tests/mini/naked_asm4.d +++ b/tests/mini/naked_asm4.d @@ -8,7 +8,7 @@ void foo() hlt; pass: ret; } - version(X86_64) + else version(X86_64) asm { naked; From bd4f7ec7311688a504492e7a7633028758e76b10 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Wed, 4 Feb 2009 00:04:09 +0100 Subject: [PATCH 2/6] Replace assertion with errormessage for unsupported calling conventions. like Pascal. See dstress/run/e/extern_10_A.d --- gen/functions.cpp | 2 +- gen/llvmhelpers.h | 2 +- gen/tocall.cpp | 9 ++++++--- gen/toobj.cpp | 12 ++++++------ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index 4a09ea3f..7896865e 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -528,7 +528,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) // calling convention if (!vafunc && fdecl->llvmInternal != LLVMintrinsic) - func->setCallingConv(DtoCallingConv(f->linkage)); + func->setCallingConv(DtoCallingConv(fdecl->loc, f->linkage)); else // fall back to C, it should be the right thing to do func->setCallingConv(llvm::CallingConv::C); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index 6764f7a9..cd959c6e 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -113,7 +113,7 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s //////////////////////////////////////////// /// convert DMD calling conv to LLVM -unsigned DtoCallingConv(LINK l); +unsigned DtoCallingConv(Loc loc, LINK l); /// TypeFunction* DtoTypeFunction(DValue* fnval); diff --git a/gen/tocall.cpp b/gen/tocall.cpp index a3af9fa3..faecfbe6 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -33,7 +33,7 @@ TypeFunction* DtoTypeFunction(DValue* fnval) ////////////////////////////////////////////////////////////////////////////////////////// -unsigned DtoCallingConv(LINK l) +unsigned DtoCallingConv(Loc loc, LINK l) { if (l == LINKc || l == LINKcpp || l == LINKintrinsic) return llvm::CallingConv::C; @@ -50,7 +50,10 @@ unsigned DtoCallingConv(LINK l) else if (l == LINKwindows) return llvm::CallingConv::X86_StdCall; else - assert(0 && "Unsupported calling convention"); + { + error(loc, "unsupported calling convention"); + fatal(); + } } ////////////////////////////////////////////////////////////////////////////////////////// @@ -235,7 +238,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions* bool nestedcall = tf->usesNest; bool dvarargs = (tf->linkage == LINKd && tf->varargs == 1); - unsigned callconv = DtoCallingConv(tf->linkage); + unsigned callconv = DtoCallingConv(loc, tf->linkage); // get callee llvm value LLValue* callable = DtoCallableValue(fnval); diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 64472570..cf9c12f6 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -417,7 +417,7 @@ llvm::Function* build_module_ctor() const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); - fn->setCallingConv(DtoCallingConv(LINKd)); + fn->setCallingConv(DtoCallingConv(0, LINKd)); llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); IRBuilder<> builder(bb); @@ -432,7 +432,7 @@ llvm::Function* build_module_ctor() for (size_t i=0; ictors[i]->ir.irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); - call->setCallingConv(DtoCallingConv(LINKd)); + call->setCallingConv(DtoCallingConv(0, LINKd)); } // debug info end @@ -462,7 +462,7 @@ static llvm::Function* build_module_dtor() const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); - fn->setCallingConv(DtoCallingConv(LINKd)); + fn->setCallingConv(DtoCallingConv(0, LINKd)); llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); IRBuilder<> builder(bb); @@ -477,7 +477,7 @@ static llvm::Function* build_module_dtor() for (size_t i=0; idtors[i]->ir.irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); - call->setCallingConv(DtoCallingConv(LINKd)); + call->setCallingConv(DtoCallingConv(0, LINKd)); } // debug info end @@ -507,7 +507,7 @@ static llvm::Function* build_module_unittest() const llvm::FunctionType* fnTy = llvm::FunctionType::get(LLType::VoidTy,argsTy,false); assert(gIR->module->getFunction(name) == NULL); llvm::Function* fn = llvm::Function::Create(fnTy, llvm::GlobalValue::InternalLinkage, name, gIR->module); - fn->setCallingConv(DtoCallingConv(LINKd)); + fn->setCallingConv(DtoCallingConv(0, LINKd)); llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry", fn); IRBuilder<> builder(bb); @@ -522,7 +522,7 @@ static llvm::Function* build_module_unittest() for (size_t i=0; iunitTests[i]->ir.irFunc->func; llvm::CallInst* call = builder.CreateCall(f,""); - call->setCallingConv(DtoCallingConv(LINKd)); + call->setCallingConv(DtoCallingConv(0, LINKd)); } // debug info end From 584911ad4e21f3789c56bf30afc00dfda38c5b02 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Wed, 4 Feb 2009 00:50:04 +0100 Subject: [PATCH 3/6] Fixed problem with static ctors, in templated imported classes, not begin run. Fixes #203 --- gen/functions.cpp | 12 ++++++++---- gen/llvmhelpers.cpp | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gen/functions.cpp b/gen/functions.cpp index 7896865e..8646d53b 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -546,12 +546,16 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) } // static ctor - if (fdecl->isStaticCtorDeclaration() && fdecl->getModule() == gIR->dmodule) { - gIR->ctors.push_back(fdecl); + if (fdecl->isStaticCtorDeclaration()) { + if (fdecl->getModule() == gIR->dmodule || fdecl->inTemplateInstance()) { + gIR->ctors.push_back(fdecl); + } } // static dtor - else if (fdecl->isStaticDtorDeclaration() && fdecl->getModule() == gIR->dmodule) { - gIR->dtors.push_back(fdecl); + else if (fdecl->isStaticDtorDeclaration()) { + if (fdecl->getModule() == gIR->dmodule || fdecl->inTemplateInstance()) { + gIR->dtors.push_back(fdecl); + } } // we never reference parameters of function prototypes diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 82f565e1..c4b954da 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -826,6 +826,7 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to) // TEMPLATE HELPERS ////////////////////////////////////////////////////////////////////////////////////////*/ +// FIXME: when is this the right one to use instead of Dsymbol::inTemplateInstance() ? bool DtoIsTemplateInstance(Dsymbol* s) { if (!s) return false; From 6cd6ddd237767752490d3160687c09e5045f836f Mon Sep 17 00:00:00 2001 From: Kelly Wilson Date: Tue, 3 Feb 2009 17:27:01 -0700 Subject: [PATCH 4/6] Fixed an accidental code removal for osx --- gen/asm-x86-64.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gen/asm-x86-64.h b/gen/asm-x86-64.h index dd3a12d0..46e065b9 100644 --- a/gen/asm-x86-64.h +++ b/gen/asm-x86-64.h @@ -1558,6 +1558,10 @@ struct AsmProcessor break; } + // osx needs an extra underscore + if (global.params.os == OSMacOSX) + insnTemplate->writestring("_"); + // print out the mangle insnTemplate->writestring(vd->mangle()); vd->nakedUse = true; From 7d2a0a84a741ff3308dee6f43aa1c17ee64bde67 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Wed, 4 Feb 2009 02:10:23 +0100 Subject: [PATCH 5/6] Removed some dead code. Fixed assertion filenames for imported template instances. Fixes #152 . --- gen/llvmhelpers.cpp | 9 +++++++-- gen/llvmhelpers.h | 2 +- gen/toir.cpp | 4 ++-- gen/toobj.cpp | 5 +++-- ir/irfunction.cpp | 3 --- ir/irfunction.h | 3 --- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index c4b954da..18dd481b 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -109,7 +109,7 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std: // ASSERT HELPER ////////////////////////////////////////////////////////////////////////////////////////*/ -void DtoAssert(Loc* loc, DValue* msg) +void DtoAssert(Module* M, Loc* loc, DValue* msg) { std::vector args; @@ -124,7 +124,12 @@ void DtoAssert(Loc* loc, DValue* msg) } // file param - args.push_back(DtoLoad(gIR->dmodule->ir.irModule->fileName)); + + // we might be generating for an imported template function + if (!M->ir.irModule) + M->ir.irModule = new IrModule(M, M->srcfile->toChars()); + + args.push_back(DtoLoad(M->ir.irModule->fileName)); // line param LLConstant* c = DtoConstUint(loc->linnum); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index cd959c6e..5363d96f 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -16,7 +16,7 @@ llvm::AllocaInst* DtoAlloca(const LLType* lltype, const std::string& name = ""); llvm::AllocaInst* DtoAlloca(const LLType* lltype, LLValue* arraysize, const std::string& name = ""); // assertion generator -void DtoAssert(Loc* loc, DValue* msg); +void DtoAssert(Module* M, Loc* loc, DValue* msg); // return the LabelStatement from the current function with the given identifier or NULL if not found LabelStatement* DtoLabelStatement(Identifier* ident); diff --git a/gen/toir.cpp b/gen/toir.cpp index 7cffd4cc..6ee7d329 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1768,7 +1768,7 @@ DValue* AssertExp::toElem(IRState* p) // call assert runtime functions p->scope() = IRScope(assertbb,endbb); - DtoAssert(&loc, msg ? msg->toElem(p) : NULL); + DtoAssert(p->func()->decl->getModule(), &loc, msg ? msg->toElem(p) : NULL); // rewrite the scope p->scope() = IRScope(endbb,oldend); @@ -1943,7 +1943,7 @@ DValue* HaltExp::toElem(IRState* p) // FIXME: DMD inserts a trap here... we probably should as well !?! #if 1 - DtoAssert(&loc, NULL); + DtoAssert(p->func()->decl->getModule(), &loc, NULL); #else // call the new (?) trap intrinsic p->ir->CreateCall(GET_INTRINSIC_DECL(trap),""); diff --git a/gen/toobj.cpp b/gen/toobj.cpp index cf9c12f6..c6bedfb0 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -99,8 +99,9 @@ void Module::genobjfile(int multiobj) ir.module = new llvm::Module(mname); // module ir state - // might already exist via import, just overwrite... - //FIXME: is there a good reason for overwriting? + // might already exist via import, just overwrite since + // the global created for the filename must belong to the right llvm module + // FIXME: but shouldn't this always get reset between modules? like other IrSymbols this->ir.irModule = new IrModule(this, srcfile->toChars()); // set target stuff diff --git a/ir/irfunction.cpp b/ir/irfunction.cpp index 37258854..8c139ada 100644 --- a/ir/irfunction.cpp +++ b/ir/irfunction.cpp @@ -33,9 +33,6 @@ IrFunction::IrFunction(FuncDeclaration* fd) dwarfSubProg = NULL; - srcfileArg = NULL; - msgArg = NULL; - nextUnique.push(0); } diff --git a/ir/irfunction.h b/ir/irfunction.h index e611a84d..bd1a4296 100644 --- a/ir/irfunction.h +++ b/ir/irfunction.h @@ -30,9 +30,6 @@ struct IrFunction : IrBase llvm::Constant* dwarfSubProg; - llvm::AllocaInst* srcfileArg; - llvm::AllocaInst* msgArg; - // pushes a unique label scope of the given name void pushUniqueLabelScope(const char* name); // pops a label scope From 1e8eae2e5d9b32dd10f66ac5c52865fade2551f7 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Wed, 4 Feb 2009 16:02:05 +0100 Subject: [PATCH 6/6] Fixed warning on osx as per request from mwarning. --- dmd/func.c | 2 +- dmd2/func.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dmd/func.c b/dmd/func.c index 9414d978..a18651ea 100644 --- a/dmd/func.c +++ b/dmd/func.c @@ -2566,7 +2566,7 @@ void StaticDtorDeclaration::semantic(Scope *sc) Statement *s = new DeclarationStatement(0, v); sa->push(s); Expression *e = new IdentifierExp(0, id); - e = new AddAssignExp(0, e, new IntegerExp(-1)); + e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1)); e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0)); s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); sa->push(s); diff --git a/dmd2/func.c b/dmd2/func.c index 62967637..1b468986 100644 --- a/dmd2/func.c +++ b/dmd2/func.c @@ -2722,7 +2722,7 @@ void StaticDtorDeclaration::semantic(Scope *sc) Statement *s = new DeclarationStatement(0, v); sa->push(s); Expression *e = new IdentifierExp(0, id); - e = new AddAssignExp(0, e, new IntegerExp(-1)); + e = new AddAssignExp(0, e, new IntegerExp((uint64_t)-1)); e = new EqualExp(TOKnotequal, 0, e, new IntegerExp(0)); s = new IfStatement(0, NULL, e, new ReturnStatement(0, NULL), NULL); sa->push(s);