diff --git a/driver/toobj.cpp b/driver/toobj.cpp index f95d5bdd8c..d19df8d56e 100644 --- a/driver/toobj.cpp +++ b/driver/toobj.cpp @@ -139,7 +139,7 @@ void emit_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostrea llvm::formatted_raw_ostream fout(out); if (Target.addPassesToEmitFile(Passes, fout, fileType, codeGenOptLevel())) - assert(0 && "no support for asm output"); + llvm_unreachable("no support for asm output"); Passes.doInitialization(); diff --git a/gen/abi-x86-64.cpp b/gen/abi-x86-64.cpp index 8da094d7c7..fb11b2487a 100644 --- a/gen/abi-x86-64.cpp +++ b/gen/abi-x86-64.cpp @@ -257,7 +257,7 @@ namespace { return const_cast(LLType::getX86_FP80Ty(gIR->context())); default: - assert(0 && "Unanticipated argument class"); + llvm_unreachable("Unanticipated argument class."); } switch(cl.classes[1]) { @@ -291,7 +291,7 @@ namespace { break; default: - assert(0 && "Unanticipated argument class for second half"); + llvm_unreachable("Unanticipated argument class for second half."); } return LLStructType::get(gIR->context(), parts); } diff --git a/gen/arrays.cpp b/gen/arrays.cpp index ee542ff5de..30a38f3f92 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -1207,8 +1207,7 @@ LLValue* DtoArrayLen(DValue* v) TypeSArray *sarray = static_cast(v->type->toBasetype()); return DtoConstSize_t(sarray->dim->toUInteger()); } - assert(0 && "unsupported array for len"); - return 0; + llvm_unreachable("unsupported array for len"); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1232,8 +1231,8 @@ LLValue* DtoArrayPtr(DValue* v) assert(!v->isNull()); return DtoGEPi(v->getRVal(), 0,0); } - assert(0); - return 0; + + llvm_unreachable("Unexpected array type."); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index fa9d6b7f27..2c02014709 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -275,12 +275,12 @@ AsmStatement::toIR(IRState * irs) case Mode_Input: cns = m_cns; break; case Mode_Output: cns = mw_cns; is_input = false; break; case Mode_Update: cns = mrw_cns; is_input = false; break; - default: assert(0); break; + default: llvm_unreachable("Unknown inline asm reference mode."); break; } break; case Arg_FrameRelative: -// FIXME -assert(0 && "asm fixme Arg_FrameRelative"); + // FIXME + llvm_unreachable("Arg_FrameRelative not supported."); /* if (arg->expr->op == TOKvar) arg_val = ((VarExp *) arg->expr)->var->toSymbol()->Stree; else @@ -296,15 +296,15 @@ assert(0 && "asm fixme Arg_FrameRelative"); clobbers_mem = true; break;*/ case Arg_LocalSize: -// FIXME -assert(0 && "asm fixme Arg_LocalSize"); + // FIXME + llvm_unreachable("Arg_LocalSize not supported."); /* var_frame_offset = cfun->x_frame_offset; if (var_frame_offset < 0) var_frame_offset = - var_frame_offset; arg_val = irs->integerConstant( var_frame_offset );*/ goto do_integer; default: - assert(0); + llvm_unreachable("Unknown inline asm reference type."); } if (is_input) { diff --git a/gen/complex.cpp b/gen/complex.cpp index 37d74556d7..b773557989 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -68,22 +68,6 @@ LLConstant* DtoConstComplex(Type* _ty, longdouble re, longdouble im) ////////////////////////////////////////////////////////////////////////////////////////// -LLValue* DtoRealPart(DValue* val) -{ - assert(0); - return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(0), "tmp"); -} - -////////////////////////////////////////////////////////////////////////////////////////// - -LLValue* DtoImagPart(DValue* val) -{ - assert(0); - return gIR->ir->CreateExtractElement(val->getRVal(), DtoConstUint(1), "tmp"); -} - -////////////////////////////////////////////////////////////////////////////////////////// - DValue* DtoComplex(Loc& loc, Type* to, DValue* val) { LLType* complexTy = DtoType(to); @@ -181,7 +165,7 @@ void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, DValue*& re, DValue*& i im = NULL; } else { - assert(0); + llvm_unreachable("Unexpected numeric type."); } } @@ -360,7 +344,7 @@ DValue* DtoComplexDiv(Loc& loc, Type* type, DValue* lhs, DValue* rhs) res_im = gIR->ir->CreateFMul(lhs_im, rhs_re, "imre"); } else - assert(0 && "lhs has neither real nor imaginary part"); + llvm_unreachable("lhs has neither real nor imaginary part"); tmp1 = gIR->ir->CreateFMul(rhs_re, rhs_re, "rhs_resq"); tmp2 = gIR->ir->CreateFMul(rhs_im, rhs_im, "rhs_imsq"); diff --git a/gen/complex.h b/gen/complex.h index abdffe6cf4..046d8c6600 100644 --- a/gen/complex.h +++ b/gen/complex.h @@ -21,8 +21,6 @@ LLConstant* DtoConstComplex(Type* t, longdouble re, longdouble im); LLConstant* DtoComplexShuffleMask(unsigned a, unsigned b); -LLValue* DtoRealPart(DValue* val); -LLValue* DtoImagPart(DValue* val); DValue* DtoComplex(Loc& loc, Type* to, DValue* val); void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im); diff --git a/gen/declarations.cpp b/gen/declarations.cpp index 7a5aed3c73..88b62a4053 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -137,10 +137,8 @@ void VarDeclaration::codegen(Ir* p) Logger::println("data segment"); #if DMDV2 && 0 // TODO: - if (storage_class & STCmanifest) - { - assert(0 && "manifest constant being codegened!!!"); - } + assert(!(storage_class & STCmanifest) && + "manifest constant being codegen'd!"); #endif // don't duplicate work diff --git a/gen/functions.cpp b/gen/functions.cpp index d8b2b7ccb0..549f2db392 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -444,7 +444,7 @@ llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl) } else { Logger::println("chars: %s type: %s kind: %s", fdecl->toChars(), fdecl->type->toChars(), fdecl->kind()); - assert(0); + llvm_unreachable("needThis, but invalid parent declaration."); } } else if (fdecl->isNested()) { diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 71e5058f65..8c2e0dbd25 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -477,9 +477,7 @@ void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPostblit) // T[n] = T[] - generally only generated by frontend in rare cases else if (t2->ty == Tarray && t->nextOf()->toBasetype()->equals(t2->nextOf()->toBasetype())) { DtoMemCpy(lhs->getLVal(), DtoArrayPtr(rhs), DtoArrayLen(rhs)); - } else { - assert(0 && "Unimplemented static array assign!"); - } + } else llvm_unreachable("Unimplemented static array assign!"); } else if (t->ty == Tdelegate) { LLValue* l = lhs->getLVal(); @@ -575,11 +573,7 @@ DValue* DtoNullValue(Type* type) return new DNullValue(type, LLConstant::getNullValue(lltype)); } - // unknown - error("unsupported: null value for %s", type->toChars()); - assert(0); - return 0; - + llvm_unreachable("null not known for this type."); } @@ -1009,8 +1003,7 @@ void DtoResolveDsymbol(Dsymbol* dsym) DtoResolveTypeInfo(fd); } else { - error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars()); - assert(0 && "unsupported dsymbol for DtoResolveDsymbol"); + llvm_unreachable("Unsupported DSymbol for DtoResolveDsymbol."); } } @@ -1256,11 +1249,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration) else if (TupleDeclaration* tupled = declaration->isTupleDeclaration()) { Logger::println("TupleDeclaration"); - if(!tupled->isexp) { - error(declaration->loc, "don't know how to handle non-expression tuple decls yet"); - assert(0); - } - + assert(tupled->isexp && "Non-expression tuple decls not handled yet."); assert(tupled->objects); for (unsigned i=0; i < tupled->objects->dim; ++i) { @@ -1274,13 +1263,10 @@ DValue* DtoDeclarationExp(Dsymbol* declaration) Logger::println("TemplateDeclaration"); // do nothing } - // unsupported declaration else { - error(declaration->loc, "Unimplemented Declaration type for DeclarationExp. kind: %s", declaration->kind()); - assert(0); + llvm_unreachable("Unimplemented Declaration type for DeclarationExp."); } - return NULL; } // does pretty much the same as DtoDeclarationExp, except it doesn't initialize, and only handles var declarations @@ -1462,14 +1448,14 @@ DValue* DtoInitializer(LLValue* target, Initializer* init) { // do nothing } - else if (init->isStructInitializer()) { + else if (init->isStructInitializer()) + { // TODO: again nothing ? } - else { - Logger::println("unsupported initializer: %s", init->toChars()); - assert(0); + else + { + llvm_unreachable("Unknown initializer type."); } - return 0; } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1538,8 +1524,9 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) Logger::println("type is a static array, building constant array initializer to single value"); return expand_to_sarray(base, exp); } + #if DMDV2 - else if (base->ty == Tvector) + if (base->ty == Tvector) { LLConstant* val = exp->toConstElem(gIR); TypeVector* tv = (TypeVector*)base; @@ -1551,13 +1538,10 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp) #endif } #endif - else - { - error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s", - exp->toChars(), exp->type->toChars(), type->toChars()); - fatal(); - } - assert(0); + + error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s", + exp->toChars(), exp->type->toChars(), type->toChars()); + llvm_unreachable("Unsupported default initializer."); } return exp->toConstElem(gIR); diff --git a/gen/module.cpp b/gen/module.cpp index f09157d871..c458101d55 100644 --- a/gen/module.cpp +++ b/gen/module.cpp @@ -658,14 +658,6 @@ void Module::genmoduleinfo() #endif - /*Logger::println("MODULE INFO INITIALIZERS"); - for (size_t i=0; igetType() != moduleinfoTy->getElementType(i)) - assert(0); - }*/ - // create and set initializer b.finalize(moduleInfoType, moduleInfoSymbol()); diff --git a/gen/runtime.cpp b/gen/runtime.cpp index 15d0d071f3..df3a87588b 100644 --- a/gen/runtime.cpp +++ b/gen/runtime.cpp @@ -89,11 +89,7 @@ llvm::Function* LLVM_D_GetRuntimeFunction(llvm::Module* target, const char* name return fn; fn = M->getFunction(name); - if (!fn) { - printf("Runtime function '%s' was not found\n", name); - assert(0); - //return NULL; - } + assert(fn && "Runtime function not found."); LLFunctionType* fnty = fn->getFunctionType(); LLFunction* resfn = llvm::cast(target->getOrInsertFunction(name, fnty)); diff --git a/gen/tocall.cpp b/gen/tocall.cpp index b918ff4d9b..6d99ddf7b1 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -52,8 +52,7 @@ TypeFunction* DtoTypeFunction(DValue* fnval) return static_cast(next); } - assert(0 && "cant get TypeFunction* from non lazy/function/delegate"); - return 0; + llvm_unreachable("Cannot get TypeFunction* from non lazy/function/delegate"); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -123,11 +122,8 @@ LLValue* DtoCallableValue(DValue* fn) return gIR->ir->CreateExtractValue(dg, 1, ".funcptr"); } } - else - { - assert(0 && "not a callable type"); - return NULL; - } + + llvm_unreachable("Not a callable type."); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/todebug.cpp b/gen/todebug.cpp index bb7e0784dd..6e0e80f2cd 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -101,7 +101,7 @@ static llvm::DIType dwarfBasicType(Type* type) } else { - assert(0 && "unsupported basictype for debug info"); + llvm_unreachable("unsupported basic type for debug info"); } return gIR->dibuilder.createBasicType( diff --git a/gen/toir.cpp b/gen/toir.cpp index aa8cc72571..995307481d 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -211,7 +211,7 @@ DValue* VarExp::toElem(IRState* p) else if (llvm::isa(vd->ir.getIrValue())) { return new DImValue(type, vd->ir.getIrValue()); } - else assert(0); + else llvm_unreachable("Unexpected parameter value."); } else { Logger::println("a normal variable"); @@ -271,7 +271,7 @@ DValue* VarExp::toElem(IRState* p) } else { - assert(0 && "Unimplemented VarExp type"); + llvm_unreachable("Unimplemented VarExp type"); } return 0; @@ -399,8 +399,8 @@ LLConstant* NullExp::toConstElem(IRState* p) else { return LLConstant::getNullValue(t); } - assert(0); - return NULL; + + llvm_unreachable("Unknown type for null constant."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -504,8 +504,7 @@ DValue* StringExp::toElem(IRState* p) return new DImValue(type, arrptr); } - assert(0); - return 0; + llvm_unreachable("Unknown type for StringExp."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -560,8 +559,7 @@ LLConstant* StringExp::toConstElem(IRState* p) return DtoConstSlice(clen, arrptr, type); } - assert(0); - return NULL; + llvm_unreachable("Unknown type for StringExp."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1229,8 +1227,7 @@ DValue* SymOffExp::toElem(IRState* p) Logger::print("SymOffExp::toElem: %s @ %s\n", toChars(), type->toChars()); LOG_SCOPE; - assert(0 && "SymOffExp::toElem should no longer be called :/"); - return 0; + llvm_unreachable("SymOffExp::toElem should no longer be called."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1454,7 +1451,7 @@ DValue* DotVarExp::toElem(IRState* p) arrptr = DtoIndexClass(l->getRVal(), tc->sym, vd); } else - assert(0); + llvm_unreachable("Unknown DotVarExp type for VarDeclaration."); //Logger::cout() << "mem: " << *arrptr << '\n'; return new DVarValue(type, vd, arrptr); @@ -1513,12 +1510,8 @@ DValue* DotVarExp::toElem(IRState* p) return new DFuncValue(fdecl, funcval, passedThis); } - else { - printf("unsupported dotvarexp: %s\n", var->toChars()); - } - assert(0); - return 0; + llvm_unreachable("Unknown target for VarDeclaration."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1557,9 +1550,7 @@ DValue* ThisExp::toElem(IRState* p) return new DVarValue(type, vd, v); } - // anything we're not yet handling ? - assert(0 && "no var in ThisExp"); - return 0; + llvm_unreachable("No VarDeclaration in ThisExp."); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -1611,8 +1602,8 @@ DValue* IndexExp::toElem(IRState* p) return DtoAAIndex(loc, type, l, r, modifiable); } else { - Logger::println("invalid index exp! e1type: %s", e1type->toChars()); - assert(0); + Logger::println("e1type: %s", e1type->toChars()); + llvm_unreachable("Unknown IndexExp target."); } return new DVarValue(type, arrptr); } @@ -1762,7 +1753,7 @@ DValue* CmpExp::toElem(IRState* p) cmpop = llvm::FCmpInst::FCMP_ORD;break; default: - assert(0); + llvm_unreachable("Unsupported floating point comparison operator."); } eval = p->ir->CreateFCmp(cmpop, l->getRVal(), r->getRVal(), "tmp"); } @@ -1821,7 +1812,7 @@ DValue* CmpExp::toElem(IRState* p) } else { - assert(0 && "Unsupported CmpExp type"); + llvm_unreachable("Unsupported CmpExp type"); } return new DImValue(type, eval); @@ -1858,7 +1849,7 @@ DValue* EqualExp::toElem(IRState* p) cmpop = llvm::ICmpInst::ICMP_NE; break; default: - assert(0); + llvm_unreachable("Unsupported integral type equality comparison."); } if (rv->getType() != lv->getType()) { rv = DtoBitCast(rv, lv->getType()); @@ -1897,7 +1888,7 @@ DValue* EqualExp::toElem(IRState* p) } else { - assert(0 && "Unsupported EqualExp type"); + llvm_unreachable("Unsupported EqualExp type."); } return new DImValue(type, eval); @@ -1997,7 +1988,7 @@ DValue* NewExp::toElem(IRState* p) // new static array else if (ntype->ty == Tsarray) { - assert(0); + llvm_unreachable("Static array new should decay to dynamic array."); } // new struct else if (ntype->ty == Tstruct) @@ -2062,7 +2053,7 @@ DValue* NewExp::toElem(IRState* p) return new DImValue(type, mem); } - assert(0); + llvm_unreachable(0); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -2127,7 +2118,7 @@ DValue* DeleteExp::toElem(IRState* p) // unknown/invalid else { - assert(0 && "invalid delete"); + llvm_unreachable("Unsupported DeleteExp target."); } // no value to return @@ -2442,9 +2433,9 @@ DValue* DelegateExp::toElem(IRState* p) if (e1->op != TOKsuper && e1->op != TOKdottype && func->isVirtual() && !func->isFinal()) castfptr = DtoVirtualFunctionPointer(u, func, toChars()); else if (func->isAbstract()) - assert(0 && "TODO delegate to abstract method"); + llvm_unreachable("Delegate to abstract method not implemented."); else if (func->toParent()->isInterfaceDeclaration()) - assert(0 && "TODO delegate to interface method"); + llvm_unreachable("Delegate to interface method not implemented."); else { func->codegen(Type::sir); diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index 28ce5d961d..97593570ad 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -74,6 +74,9 @@ llvm::Attributes DtoShouldExtend(Type* type) #else return llvm::Attribute::ZExt; #endif + default: + // Do not extend. + break; } } #if LDC_LLVM_VER >= 303 @@ -221,8 +224,7 @@ LLType* DtoType(Type* t) */ default: - printf("trying to convert unknown type '%s' with value %d\n", t->toChars(), t->ty); - assert(0); + llvm_unreachable("Unknown class of D Type!"); } return 0; } @@ -363,7 +365,7 @@ LLGlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym) } else { - assert(0 && "not global/function"); + llvm_unreachable("not global/function"); } // If the function needs to be defined in the current module, check if it @@ -463,40 +465,6 @@ llvm::GlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym) ////////////////////////////////////////////////////////////////////////////////////////// -LLValue* DtoPointedType(LLValue* ptr, LLValue* val) -{ - LLType* ptrTy = ptr->getType()->getContainedType(0); - LLType* valTy = val->getType(); - // ptr points to val's type - if (ptrTy == valTy) - { - return val; - } - // ptr is integer pointer - else if (ptrTy->isIntegerTy()) - { - // val is integer - assert(valTy->isIntegerTy()); - LLIntegerType* pt = llvm::cast(ptrTy); - LLIntegerType* vt = llvm::cast(valTy); - if (pt->getBitWidth() < vt->getBitWidth()) { - return new llvm::TruncInst(val, pt, "tmp", gIR->scopebb()); - } - else - assert(0); - } - // something else unsupported - else - { - if (Logger::enabled()) - Logger::cout() << *ptrTy << '|' << *valTy << '\n'; - assert(0); - } - return 0; -} - -////////////////////////////////////////////////////////////////////////////////////////// - LLIntegerType* DtoSize_t() { // the type of size_t does not change once set @@ -686,9 +654,9 @@ LLConstant* DtoConstFP(Type* t, longdouble value) #else return LLConstantFP::get(gIR->context(), APFloat(APInt(128, 2, bits))); #endif - } else { - assert(0 && "Unknown floating point type encountered"); } + + llvm_unreachable("Unknown floating point type encountered"); } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/gen/tollvm.h b/gen/tollvm.h index 1e5539311a..3b0ef8a9c8 100644 --- a/gen/tollvm.h +++ b/gen/tollvm.h @@ -54,9 +54,6 @@ LLGlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym); LLGlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym); LLGlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym); -// TODO: this one should be removed!!! -LLValue* DtoPointedType(LLValue* ptr, LLValue* val); - // some types LLIntegerType* DtoSize_t(); LLStructType* DtoInterfaceInfoType(); diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 5928089c37..e539305885 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -787,7 +787,7 @@ void TypeInfoClassDeclaration::codegen(Ir*i) void TypeInfoClassDeclaration::llvmDefine() { #if DMDV2 - assert(0); + llvm_unreachable("TypeInfoClassDeclaration should not be called for D2"); #endif Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars()); LOG_SCOPE; diff --git a/ir/irtype.cpp b/ir/irtype.cpp index 3797af1076..743f0d65dd 100644 --- a/ir/irtype.cpp +++ b/ir/irtype.cpp @@ -139,8 +139,7 @@ llvm::Type * IrTypeBasic::basic2llvm(Type* t) case Tbool: return llvm::Type::getInt1Ty(ctx); default: - assert(0 && "not basic type"); - return NULL; + llvm_unreachable("Unknown basic type."); } }