From 282f60e4a08ad6331ecf56fcefd531148bac9b9f Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Mon, 26 Nov 2007 06:45:13 +0100 Subject: [PATCH] [svn r123] Fixed some typeinfo module name mismatches. Fixed D-style varargs returning through pointer. Fixed converting nested function to delegate. Added std.string and std.format to Phobos. --- gen/functions.cpp | 26 ++++++++++---------------- gen/toir.cpp | 20 +++++++++++++++++--- llvmdc.kdevelop.filelist | 2 ++ lphobos/phobos.d | 5 ++--- lphobos/typeinfo1/ti_cdouble.d | 2 +- lphobos/typeinfo1/ti_cfloat.d | 2 +- lphobos/typeinfo1/ti_creal.d | 2 +- lphobos/typeinfo2/ti_AC.d | 2 +- lphobos/typeinfo2/ti_C.d | 2 +- test/bug74.d | 12 ++++++++++++ test/bug75.d | 13 +++++++++++++ 11 files changed, 61 insertions(+), 27 deletions(-) create mode 100644 test/bug74.d create mode 100644 test/bug75.d diff --git a/gen/functions.cpp b/gen/functions.cpp index 5faf4269..3c2d0b8c 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -396,9 +396,16 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) assert(fdecl->llvmThisVar); ++iarg; } - int varargs = -1; - if (f->linkage == LINKd && f->varargs == 1) - varargs = 0; + + if (f->linkage == LINKd && f->varargs == 1) { + iarg->setName("_arguments"); + fdecl->llvmArguments = iarg; + ++iarg; + iarg->setName("_argptr"); + fdecl->llvmArgPtr = iarg; + ++iarg; + } + for (; iarg != func->arg_end(); ++iarg) { Argument* arg = Argument::getNth(f->parameters, k++); @@ -410,19 +417,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) } iarg->setName(arg->ident->toChars()); } - else if (!arg && varargs >= 0) { - if (varargs == 0) { - iarg->setName("_arguments"); - fdecl->llvmArguments = iarg; - } - else if (varargs == 1) { - iarg->setName("_argptr"); - fdecl->llvmArgPtr = iarg; - } - else - assert(0); - varargs++; - } else { iarg->setName("unnamed"); } diff --git a/gen/toir.cpp b/gen/toir.cpp index 74e2bfa1..2de44404 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2088,17 +2088,31 @@ DValue* DelegateExp::toElem(IRState* p) lval = new llvm::AllocaInst(DtoType(type), "tmpdelegate", p->topallocapoint()); } + llvm::Value* uval; + if (DFuncValue* f = u->isFunc()) { + //assert(f->vthis); + //uval = f->vthis; + llvm::Value* nestvar = p->func()->decl->llvmNested; + if (nestvar) + uval = nestvar; + else + uval = llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty)); + } + else { + uval = u->getRVal(); + } + llvm::Value* context = DtoGEP(lval,zero,zero,"tmp",p->scopebb()); - llvm::Value* castcontext = new llvm::BitCastInst(u->getRVal(),int8ptrty,"tmp",p->scopebb()); + llvm::Value* castcontext = DtoBitCast(uval,int8ptrty); new llvm::StoreInst(castcontext, context, p->scopebb()); llvm::Value* fptr = DtoGEP(lval,zero,one,"tmp",p->scopebb()); assert(func->llvmValue); - llvm::Value* castfptr = new llvm::BitCastInst(func->llvmValue,fptr->getType()->getContainedType(0),"tmp",p->scopebb()); + llvm::Value* castfptr = DtoBitCast(func->llvmValue,fptr->getType()->getContainedType(0)); new llvm::StoreInst(castfptr, fptr, p->scopebb()); - return new DImValue(type, u->getRVal(), true); + return new DVarValue(type, lval, true); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/llvmdc.kdevelop.filelist b/llvmdc.kdevelop.filelist index 9dc7ead6..6f60cd20 100644 --- a/llvmdc.kdevelop.filelist +++ b/llvmdc.kdevelop.filelist @@ -323,6 +323,8 @@ test/bug70.d test/bug71.d test/bug72.d test/bug73.d +test/bug74.d +test/bug75.d test/bug8.d test/bug9.d test/c.d diff --git a/lphobos/phobos.d b/lphobos/phobos.d index b8e0cf26..7c5818ca 100644 --- a/lphobos/phobos.d +++ b/lphobos/phobos.d @@ -3,6 +3,7 @@ module phobos; import std.array, std.ctype, +std.format, std.intrinsic, std.math, std.moduleinit, @@ -10,12 +11,10 @@ std.outofmemory, std.stdint, std.stdio, std.stdarg, +std.string, std.uni, std.utf, -//std.format, -//std.string, - std.c.fenv, std.c.locale, std.c.math, diff --git a/lphobos/typeinfo1/ti_cdouble.d b/lphobos/typeinfo1/ti_cdouble.d index 82ac4c93..84d5d024 100644 --- a/lphobos/typeinfo1/ti_cdouble.d +++ b/lphobos/typeinfo1/ti_cdouble.d @@ -1,7 +1,7 @@ // cdouble -module std.typeinfo.ti_cdouble; +module typeinfo1.ti_cdouble; class TypeInfo_r : TypeInfo { diff --git a/lphobos/typeinfo1/ti_cfloat.d b/lphobos/typeinfo1/ti_cfloat.d index dc6b9cd8..b1281eba 100644 --- a/lphobos/typeinfo1/ti_cfloat.d +++ b/lphobos/typeinfo1/ti_cfloat.d @@ -1,7 +1,7 @@ // cfloat -module std.typeinfo.ti_cfloat; +module typeinfo1.ti_cfloat; class TypeInfo_q : TypeInfo { diff --git a/lphobos/typeinfo1/ti_creal.d b/lphobos/typeinfo1/ti_creal.d index 1beebe09..e877f602 100644 --- a/lphobos/typeinfo1/ti_creal.d +++ b/lphobos/typeinfo1/ti_creal.d @@ -1,7 +1,7 @@ // creal -module std.typeinfo.ti_creal; +module typeinfo1.ti_creal; class TypeInfo_c : TypeInfo { diff --git a/lphobos/typeinfo2/ti_AC.d b/lphobos/typeinfo2/ti_AC.d index 1dfbbb1d..c36ac386 100644 --- a/lphobos/typeinfo2/ti_AC.d +++ b/lphobos/typeinfo2/ti_AC.d @@ -1,4 +1,4 @@ -module std.typeinfo.ti_AC; +module typeinfo2.ti_AC; // Object[] diff --git a/lphobos/typeinfo2/ti_C.d b/lphobos/typeinfo2/ti_C.d index bce4706b..2b56392b 100644 --- a/lphobos/typeinfo2/ti_C.d +++ b/lphobos/typeinfo2/ti_C.d @@ -21,7 +21,7 @@ * distribution. */ -module std.typeinfo.ti_C; +module typeinfo2.ti_C; // Object diff --git a/test/bug74.d b/test/bug74.d new file mode 100644 index 00000000..b02edbf5 --- /dev/null +++ b/test/bug74.d @@ -0,0 +1,12 @@ +module bug74; + +char[] sformat(char[] s, ...) +{ + TypeInfo[] ti = _arguments; + void* args = _argptr; + return ""; +} + +void main() +{ +} diff --git a/test/bug75.d b/test/bug75.d new file mode 100644 index 00000000..978286e2 --- /dev/null +++ b/test/bug75.d @@ -0,0 +1,13 @@ +module bug75; + +void func(void delegate() dg) +{ +} + +void main() +{ + void nested() { + } + //func(&nested); + void delegate() dg = &nested; +}