diff --git a/dmd/mtype.c b/dmd/mtype.c index 4f38a0fd..0e5927b7 100644 --- a/dmd/mtype.c +++ b/dmd/mtype.c @@ -1769,18 +1769,8 @@ Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident) args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL)); adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort"); } - static FuncDeclaration *adSortBit_fd = NULL; - if(!adSortBit_fd) { - Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->arrayOf(), NULL, NULL)); - args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL)); - adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit"); - } - if(isBit) - ec = new VarExp(0, adSortBit_fd); - else - ec = new VarExp(0, adSort_fd); + ec = new VarExp(0, adSort_fd); e = e->castTo(sc, n->arrayOf()); // convert to dynamic array arguments = new Expressions(); @@ -2476,7 +2466,7 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) static FuncDeclaration *aaLen_fd = NULL; if(!aaLen_fd) { Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); + args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); // FIXME: Real parameter type is AA. aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen); } @@ -2497,7 +2487,7 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) static FuncDeclaration *aaKeys_fd = NULL; if(!aaKeys_fd) { Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); + args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); // FIXME: Real parameter type is AA. args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL)); aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys); } @@ -2518,7 +2508,7 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) static FuncDeclaration *aaValues_fd = NULL; if(!aaValues_fd) { Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); + args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); // FIXME: Real parameter type is AA. args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL)); args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL)); aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues); @@ -2543,7 +2533,7 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) static FuncDeclaration *aaRehash_fd = NULL; if(!aaRehash_fd) { Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); + args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); // FIXME: Real parameter type is AA*. args->push(new Parameter(STCin, Type::typeinfo->type, NULL, NULL)); aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash); } diff --git a/dmd/statement.c b/dmd/statement.c index b88c4761..bb64b66f 100644 --- a/dmd/statement.c +++ b/dmd/statement.c @@ -1801,21 +1801,21 @@ Statement *ForeachStatement::semantic(Scope *sc) Parameters* dgargs = new Parameters; dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); - aaApply2_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd)); + aaApply2_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tint32, 0, LINKd)); args->push(new Parameter(STCin, aaApply2_dg, NULL, NULL)); - aaApply2_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply2"); + aaApply2_fd = FuncDeclaration::genCfunc(args, Type::tint32, "_aaApply2"); } static FuncDeclaration *aaApply_fd = NULL; static TypeDelegate* aaApply_dg; if(!aaApply_fd) { Parameters* args = new Parameters; - args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); + args->push(new Parameter(STCin, Type::tvoid->pointerTo(), NULL, NULL)); // FIXME: Real parameter type is AA. args->push(new Parameter(STCin, Type::tsize_t, NULL, NULL)); Parameters* dgargs = new Parameters; dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); - aaApply_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd)); + aaApply_dg = new TypeDelegate(new TypeFunction(dgargs, Type::tint32, 0, LINKd)); args->push(new Parameter(STCin, aaApply_dg, NULL, NULL)); - aaApply_fd = FuncDeclaration::genCfunc(args, Type::tindex, "_aaApply"); + aaApply_fd = FuncDeclaration::genCfunc(args, Type::tint32, "_aaApply"); } FuncDeclaration *fdapply; if (dim == 2) { @@ -1840,7 +1840,7 @@ Statement *ForeachStatement::semantic(Scope *sc) } exps->push(flde); e = new CallExp(loc, ec, exps); - e->type = Type::tindex; // don't run semantic() on e + e->type = Type::tint32; // don't run semantic() on e } else if (tab->ty == Tarray || tab->ty == Tsarray) { @@ -1884,15 +1884,15 @@ Statement *ForeachStatement::semantic(Scope *sc) Parameters* dgargs = new Parameters; dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); - dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd)); + dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tint32, 0, LINKd)); args->push(new Parameter(STCin, dgty, NULL, NULL)); - fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname); + fdapply = FuncDeclaration::genCfunc(args, Type::tint32, fdname); } else { Parameters* dgargs = new Parameters; dgargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); - dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tindex, 0, LINKd)); + dgty = new TypeDelegate(new TypeFunction(dgargs, Type::tint32, 0, LINKd)); args->push(new Parameter(STCin, dgty, NULL, NULL)); - fdapply = FuncDeclaration::genCfunc(args, Type::tindex, fdname); + fdapply = FuncDeclaration::genCfunc(args, Type::tint32, fdname); } ec = new VarExp(0, fdapply); @@ -1909,7 +1909,7 @@ Statement *ForeachStatement::semantic(Scope *sc) } exps->push(flde); e = new CallExp(loc, ec, exps); - e->type = Type::tindex; // don't run semantic() on e + e->type = Type::tint32; // don't run semantic() on e } else if (tab->ty == Tdelegate) { @@ -3787,14 +3787,14 @@ Statement *SynchronizedStatement::semantic(Scope *sc) cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp))); Parameters* enterargs = new Parameters; - enterargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); + enterargs->push(new Parameter(STCin, ClassDeclaration::object->type, NULL, NULL)); FuncDeclaration *fdenter = FuncDeclaration::genCfunc(enterargs, Type::tvoid, Id::monitorenter); Expression *e = new CallExp(loc, new VarExp(loc, fdenter), new VarExp(loc, tmp)); e->type = Type::tvoid; // do not run semantic on e cs->push(new ExpStatement(loc, e)); Parameters* exitargs = new Parameters; - exitargs->push(new Parameter(STCin, Type::tvoidptr, NULL, NULL)); + exitargs->push(new Parameter(STCin, ClassDeclaration::object->type, NULL, NULL)); FuncDeclaration *fdexit = FuncDeclaration::genCfunc(exitargs, Type::tvoid, Id::monitorexit); e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp)); e->type = Type::tvoid; // do not run semantic on e diff --git a/gen/functions.cpp b/gen/functions.cpp index 94d63e22..5bfb8797 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -474,8 +474,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl) // construct function const llvm::FunctionType* functype = DtoFunctionType(fdecl); llvm::Function* func = vafunc ? vafunc : gIR->module->getFunction(mangled_name); - if (!func) + if (!func) { func = llvm::Function::Create(functype, DtoLinkage(fdecl), mangled_name, gIR->module); + } else if (func->getFunctionType() != functype) { + error(fdecl->loc, "Function type does not match previously declared function with the same mangled name: %s", fdecl->mangle()); + } if (Logger::enabled()) Logger::cout() << "func = " << *func << std::endl;