From 882e81ec1cde25f15945c435ea098145c0c93d21 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 1 May 2011 01:16:36 +0200 Subject: [PATCH 1/2] Explicitly add %st as second argument to fucomip. It should really be assumed implicitly, but the GNU as shipping with Mac OS X 10.6 (Apple Inc version cctools-800~26, GNU assembler version 1.38) chokes on the instruction otherwise. --- gen/asm-x86-64.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gen/asm-x86-64.h b/gen/asm-x86-64.h index 32b783d3..e2c3ecd3 100644 --- a/gen/asm-x86-64.h +++ b/gen/asm-x86-64.h @@ -1897,6 +1897,20 @@ namespace AsmParserx8664 else stmt->error("instruction allows only ST as second argument"); } + + if ( op == Op_FCmpFlgP ) + { + // Explicitly add %st as second argument to fucomip – it should + // be implicit, but the GNU as shipping with Mac OS X (Apple Inc + // version cctools-800~26, GNU assembler version 1.38) chokes on + // it otherwise. + assert ( nOperands == 1 ); + nOperands = 2; + operands[1] = operands[0]; + memset ( operands, 0, sizeof( Operand ) ); + operands[0].cls = Opr_Reg; + operands[0].reg = Reg_ST; + } if ( opInfo->needsType ) { From 15c5316e26539ec377059e65a5bff3aaaf6118c0 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 27 Jul 2011 23:01:22 +0200 Subject: [PATCH 2/2] Prevent two function with same mangled name but different types from being declared. Previously, LDC would crash in the backend due to the fact that the IR is typed in such cases (we recently had such an instance with Tango, where an extern( C ) function was declared once with int and once with size_t). --- dmd/mtype.c | 20 +++++--------------- dmd/statement.c | 26 +++++++++++++------------- gen/functions.cpp | 5 ++++- 3 files changed, 22 insertions(+), 29 deletions(-) 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;