diff --git a/ctx.cpp b/ctx.cpp index 0554485f..4e357873 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -284,7 +284,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, llvm::Constant *offFunc = m->module->getOrInsertFunction(buf, LLVMTypes::VoidType, NULL); - Assert(llvm::isa(offFunc)); + AssertPos(currentPos, llvm::isa(offFunc)); llvm::BasicBlock *offBB = llvm::BasicBlock::Create(*g->ctx, "entry", (llvm::Function *)offFunc, 0); @@ -302,18 +302,18 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, /* If debugging is enabled, tell the debug information emission code about this new function */ diFile = funcStartPos.GetDIFile(); - Assert(diFile.Verify()); + AssertPos(currentPos, diFile.Verify()); llvm::DIScope scope = llvm::DIScope(m->diBuilder->getCU()); - Assert(scope.Verify()); + AssertPos(currentPos, scope.Verify()); const FunctionType *functionType = function->GetType(); llvm::DIType diSubprogramType; if (functionType == NULL) - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); else { diSubprogramType = functionType->GetDIType(scope); - Assert(diSubprogramType.Verify()); + AssertPos(currentPos, diSubprogramType.Verify()); } std::string mangledName = llvmFunction->getName(); @@ -335,7 +335,7 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, #endif // !LLVM_3_0 flags, isOptimized, llvmFunction); - Assert(diSubprogram.Verify()); + AssertPos(currentPos, diSubprogram.Verify()); /* And start a scope representing the initial function scope */ StartScope(); @@ -344,8 +344,8 @@ FunctionEmitContext::FunctionEmitContext(Function *func, Symbol *funSym, FunctionEmitContext::~FunctionEmitContext() { - Assert(controlFlowInfo.size() == 0); - Assert(debugScopes.size() == (m->diBuilder ? 1 : 0)); + AssertPos(currentPos, controlFlowInfo.size() == 0); + AssertPos(currentPos, debugScopes.size() == (m->diBuilder ? 1 : 0)); } @@ -439,7 +439,7 @@ FunctionEmitContext::SetInternalMaskAndNot(llvm::Value *oldMask, llvm::Value *te void FunctionEmitContext::BranchIfMaskAny(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { - Assert(bblock != NULL); + AssertPos(currentPos, bblock != NULL); llvm::Value *any = Any(GetFullMask()); BranchInst(btrue, bfalse, any); // It's illegal to add any additional instructions to the basic block @@ -450,7 +450,7 @@ FunctionEmitContext::BranchIfMaskAny(llvm::BasicBlock *btrue, llvm::BasicBlock * void FunctionEmitContext::BranchIfMaskAll(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { - Assert(bblock != NULL); + AssertPos(currentPos, bblock != NULL); llvm::Value *all = All(GetFullMask()); BranchInst(btrue, bfalse, all); // It's illegal to add any additional instructions to the basic block @@ -461,7 +461,7 @@ FunctionEmitContext::BranchIfMaskAll(llvm::BasicBlock *btrue, llvm::BasicBlock * void FunctionEmitContext::BranchIfMaskNone(llvm::BasicBlock *btrue, llvm::BasicBlock *bfalse) { - Assert(bblock != NULL); + AssertPos(currentPos, bblock != NULL); // switch sense of true/false bblocks BranchIfMaskAny(bfalse, btrue); // It's illegal to add any additional instructions to the basic block @@ -486,7 +486,7 @@ void FunctionEmitContext::EndIf() { CFInfo *ci = popCFState(); // Make sure we match up with a Start{Uniform,Varying}If(). - Assert(ci->IsIf()); + AssertPos(currentPos, ci->IsIf()); // 'uniform' ifs don't change the mask so we only need to restore the // mask going into the if for 'varying' if statements @@ -575,7 +575,7 @@ FunctionEmitContext::StartLoop(llvm::BasicBlock *bt, llvm::BasicBlock *ct, void FunctionEmitContext::EndLoop() { CFInfo *ci = popCFState(); - Assert(ci->IsLoop()); + AssertPos(currentPos, ci->IsLoop()); if (!ci->IsUniform()) // If the loop had a 'uniform' test, then it didn't make any @@ -609,7 +609,7 @@ FunctionEmitContext::StartForeach() { void FunctionEmitContext::EndForeach() { CFInfo *ci = popCFState(); - Assert(ci->IsForeach()); + AssertPos(currentPos, ci->IsForeach()); } @@ -654,7 +654,7 @@ FunctionEmitContext::Break(bool doCoherenceCheck) { "for/while/do loops and \"switch\" statements."); return; } - Assert(controlFlowInfo.size() > 0); + AssertPos(currentPos, controlFlowInfo.size() > 0); if (bblock == NULL) return; @@ -664,7 +664,7 @@ FunctionEmitContext::Break(bool doCoherenceCheck) { ifsInCFAllUniform(CFInfo::Switch)) { // We know that all program instances are executing the break, so // just jump to the block immediately after the switch. - Assert(breakTarget != NULL); + AssertPos(currentPos, breakTarget != NULL); BranchInst(breakTarget); bblock = NULL; return; @@ -689,7 +689,7 @@ FunctionEmitContext::Break(bool doCoherenceCheck) { // break. In these cases, we need to update the mask of the lanes // that have executed a 'break' statement: // breakLanes = breakLanes | mask - Assert(breakLanesPtr != NULL); + AssertPos(currentPos, breakLanesPtr != NULL); llvm::Value *mask = GetInternalMask(); llvm::Value *breakMask = LoadInst(breakLanesPtr, "break_mask"); @@ -728,7 +728,7 @@ FunctionEmitContext::Continue(bool doCoherenceCheck) { "for/while/do/foreach loops."); return; } - Assert(controlFlowInfo.size() > 0); + AssertPos(currentPos, controlFlowInfo.size() > 0); if (ifsInCFAllUniform(CFInfo::Loop) || GetInternalMask() == LLVMMaskAllOn) { // Similarly to 'break' statements, we can immediately jump to the @@ -744,7 +744,7 @@ FunctionEmitContext::Continue(bool doCoherenceCheck) { else { // Otherwise update the stored value of which lanes have 'continue'd. // continueLanes = continueLanes | mask - Assert(continueLanesPtr); + AssertPos(currentPos, continueLanesPtr); llvm::Value *mask = GetInternalMask(); llvm::Value *continueMask = LoadInst(continueLanesPtr, "continue_mask"); @@ -772,7 +772,7 @@ FunctionEmitContext::Continue(bool doCoherenceCheck) { */ bool FunctionEmitContext::ifsInCFAllUniform(int type) const { - Assert(controlFlowInfo.size() > 0); + AssertPos(currentPos, controlFlowInfo.size() > 0); // Go backwards through controlFlowInfo, since we add new nested scopes // to the back. Stop once we come to the first enclosing control flow // structure of the desired type. @@ -783,7 +783,7 @@ FunctionEmitContext::ifsInCFAllUniform(int type) const { return false; --i; } - Assert(i >= 0); // else we didn't find the expected control flow type! + AssertPos(currentPos, i >= 0); // else we didn't find the expected control flow type! return true; } @@ -791,7 +791,7 @@ FunctionEmitContext::ifsInCFAllUniform(int type) const { void FunctionEmitContext::jumpIfAllLoopLanesAreDone(llvm::BasicBlock *target) { llvm::Value *allDone = NULL; - Assert(continueLanesPtr != NULL); + AssertPos(currentPos, continueLanesPtr != NULL); if (breakLanesPtr == NULL) { // In a foreach loop, break and return are illegal, and // breakLanesPtr is NULL. In this case, the mask is guaranteed to @@ -884,7 +884,7 @@ FunctionEmitContext::StartSwitch(bool cfIsUniform, llvm::BasicBlock *bbBreak) { void FunctionEmitContext::EndSwitch() { - Assert(bblock != NULL); + AssertPos(currentPos, bblock != NULL); CFInfo *ci = popCFState(); if (ci->IsVarying() && bblock != NULL) @@ -903,7 +903,7 @@ FunctionEmitContext::addSwitchMaskCheck(llvm::Value *mask) { // Find the basic block for the case or default label immediately after // the current one in the switch statement--that's where we want to // jump if the mask is all off at this label. - Assert(nextBlocks->find(bblock) != nextBlocks->end()); + AssertPos(currentPos, nextBlocks->find(bblock) != nextBlocks->end()); llvm::BasicBlock *bbNext = nextBlocks->find(bblock)->second; // Jump to the next one of the mask is all off; otherwise jump to the @@ -917,11 +917,11 @@ FunctionEmitContext::addSwitchMaskCheck(llvm::Value *mask) { statement. */ llvm::Value * FunctionEmitContext::getMaskAtSwitchEntry() { - Assert(controlFlowInfo.size() > 0); + AssertPos(currentPos, controlFlowInfo.size() > 0); int i = controlFlowInfo.size() - 1; while (i >= 0 && controlFlowInfo[i]->type != CFInfo::Switch) --i; - Assert(i != -1); + AssertPos(currentPos, i != -1); return controlFlowInfo[i]->savedMask; } @@ -936,7 +936,7 @@ FunctionEmitContext::EmitDefaultLabel(bool checkMask, SourcePos pos) { // If there's a default label in the switch, a basic block for it // should have been provided in the previous call to SwitchInst(). - Assert(defaultBlock != NULL); + AssertPos(currentPos, defaultBlock != NULL); if (bblock != NULL) // The previous case in the switch fell through, or we're in a @@ -998,13 +998,13 @@ FunctionEmitContext::EmitCaseLabel(int value, bool checkMask, SourcePos pos) { // Find the basic block for this case statement. llvm::BasicBlock *bbCase = NULL; - Assert(caseBlocks != NULL); + AssertPos(currentPos, caseBlocks != NULL); for (int i = 0; i < (int)caseBlocks->size(); ++i) if ((*caseBlocks)[i].first == value) { bbCase = (*caseBlocks)[i].second; break; } - Assert(bbCase != NULL); + AssertPos(currentPos, bbCase != NULL); if (bblock != NULL) // fall through from the previous case @@ -1047,7 +1047,7 @@ FunctionEmitContext::SwitchInst(llvm::Value *expr, llvm::BasicBlock *bbDefault, const std::map &bbNext) { // The calling code should have called StartSwitch() before calling // SwitchInst(). - Assert(controlFlowInfo.size() && + AssertPos(currentPos, controlFlowInfo.size() && controlFlowInfo.back()->IsSwitch()); switchExpr = expr; @@ -1066,7 +1066,7 @@ FunctionEmitContext::SwitchInst(llvm::Value *expr, llvm::BasicBlock *bbDefault, if (expr->getType() == LLVMTypes::Int32Type) s->addCase(LLVMInt32(bbCases[i].first), bbCases[i].second); else { - Assert(expr->getType() == LLVMTypes::Int64Type); + AssertPos(currentPos, expr->getType() == LLVMTypes::Int64Type); s->addCase(LLVMInt64(bbCases[i].first), bbCases[i].second); } } @@ -1085,7 +1085,7 @@ FunctionEmitContext::SwitchInst(llvm::Value *expr, llvm::BasicBlock *bbDefault, // anyone. std::map::const_iterator iter; iter = nextBlocks->find(NULL); - Assert(iter != nextBlocks->end()); + AssertPos(currentPos, iter != nextBlocks->end()); llvm::BasicBlock *bbFirst = iter->second; BranchInst(bbFirst); bblock = NULL; @@ -1282,10 +1282,10 @@ FunctionEmitContext::LaneMask(llvm::Value *v) { std::vector mm; m->symbolTable->LookupFunction("__movmsk", &mm); if (g->target.maskBitCount == 1) - Assert(mm.size() == 1); + AssertPos(currentPos, mm.size() == 1); else // There should be one with signed int signature, one unsigned int. - Assert(mm.size() == 2); + AssertPos(currentPos, mm.size() == 2); // We can actually call either one, since both are i32s as far as // LLVM's type system is concerned... llvm::Function *fmm = mm[0]->function; @@ -1337,7 +1337,7 @@ FunctionEmitContext::CreateBasicBlock(const char *name) { llvm::Value * FunctionEmitContext::I1VecToBoolVec(llvm::Value *b) { if (b == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1385,7 +1385,7 @@ lGetStringAsValue(llvm::BasicBlock *bblock, const char *s) { void FunctionEmitContext::AddInstrumentationPoint(const char *note) { - Assert(note != NULL); + AssertPos(currentPos, note != NULL); if (!g->emitInstrumentation) return; @@ -1445,7 +1445,7 @@ FunctionEmitContext::StartScope() { m->diBuilder->createLexicalBlock(parentScope, diFile, currentPos.first_line, currentPos.first_column); - Assert(lexicalBlock.Verify()); + AssertPos(currentPos, lexicalBlock.Verify()); debugScopes.push_back(lexicalBlock); } } @@ -1454,7 +1454,7 @@ FunctionEmitContext::StartScope() { void FunctionEmitContext::EndScope() { if (m->diBuilder != NULL) { - Assert(debugScopes.size() > 0); + AssertPos(currentPos, debugScopes.size() > 0); debugScopes.pop_back(); } } @@ -1462,7 +1462,7 @@ FunctionEmitContext::EndScope() { llvm::DIScope FunctionEmitContext::GetDIScope() const { - Assert(debugScopes.size() > 0); + AssertPos(currentPos, debugScopes.size() > 0); return debugScopes.back(); } @@ -1474,7 +1474,7 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { llvm::DIScope scope = GetDIScope(); llvm::DIType diType = sym->type->GetDIType(scope); - Assert(diType.Verify()); + AssertPos(currentPos, diType.Verify()); llvm::DIVariable var = m->diBuilder->createLocalVariable(llvm::dwarf::DW_TAG_auto_variable, scope, @@ -1483,7 +1483,7 @@ FunctionEmitContext::EmitVariableDebugInfo(Symbol *sym) { sym->pos.first_line, diType, true /* preserve through opts */); - Assert(var.Verify()); + AssertPos(currentPos, var.Verify()); llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, bblock); AddDebugPos(declareInst, &sym->pos, &scope); @@ -1497,7 +1497,7 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) { llvm::DIScope scope = diSubprogram; llvm::DIType diType = sym->type->GetDIType(scope); - Assert(diType.Verify()); + AssertPos(currentPos, diType.Verify()); int flags = 0; llvm::DIVariable var = @@ -1510,7 +1510,7 @@ FunctionEmitContext::EmitFunctionParameterDebugInfo(Symbol *sym, int argNum) { true /* preserve through opts */, flags, argNum+1); - Assert(var.Verify()); + AssertPos(currentPos, var.Verify()); llvm::Instruction *declareInst = m->diBuilder->insertDeclare(sym->storagePtr, var, bblock); AddDebugPos(declareInst, &sym->pos, &scope); @@ -1545,11 +1545,11 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst, llvm::Value *v0, llvm::Value *v1, const char *name) { if (v0 == NULL || v1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } - Assert(v0->getType() == v1->getType()); + AssertPos(currentPos, v0->getType() == v1->getType()); llvm::Type *type = v0->getType(); int arraySize = lArrayVectorWidth(type); if (arraySize == 0) { @@ -1577,7 +1577,7 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst, llvm::Value * FunctionEmitContext::NotOperator(llvm::Value *v, const char *name) { if (v == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1632,11 +1632,11 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst, llvm::Value *v0, llvm::Value *v1, const char *name) { if (v0 == NULL || v1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } - Assert(v0->getType() == v1->getType()); + AssertPos(currentPos, v0->getType() == v1->getType()); llvm::Type *type = v0->getType(); int arraySize = lArrayVectorWidth(type); if (arraySize == 0) { @@ -1663,7 +1663,7 @@ FunctionEmitContext::CmpInst(llvm::Instruction::OtherOps inst, llvm::Value * FunctionEmitContext::SmearUniform(llvm::Value *value, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1697,7 +1697,7 @@ llvm::Value * FunctionEmitContext::BitCastInst(llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1713,7 +1713,7 @@ FunctionEmitContext::BitCastInst(llvm::Value *value, llvm::Type *type, llvm::Value * FunctionEmitContext::PtrToIntInst(llvm::Value *value, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1734,7 +1734,7 @@ llvm::Value * FunctionEmitContext::PtrToIntInst(llvm::Value *value, llvm::Type *toType, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1750,7 +1750,7 @@ FunctionEmitContext::PtrToIntInst(llvm::Value *value, llvm::Type *toType, else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits()) return TruncInst(value, toType, name); else { - Assert(fromType->getScalarSizeInBits() < + AssertPos(currentPos, fromType->getScalarSizeInBits() < toType->getScalarSizeInBits()); return ZExtInst(value, toType, name); } @@ -1766,7 +1766,7 @@ llvm::Value * FunctionEmitContext::IntToPtrInst(llvm::Value *value, llvm::Type *toType, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1782,7 +1782,7 @@ FunctionEmitContext::IntToPtrInst(llvm::Value *value, llvm::Type *toType, else if (fromType->getScalarSizeInBits() > toType->getScalarSizeInBits()) return TruncInst(value, toType, name); else { - Assert(fromType->getScalarSizeInBits() < + AssertPos(currentPos, fromType->getScalarSizeInBits() < toType->getScalarSizeInBits()); return ZExtInst(value, toType, name); } @@ -1799,7 +1799,7 @@ llvm::Instruction * FunctionEmitContext::TruncInst(llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1818,7 +1818,7 @@ llvm::Instruction * FunctionEmitContext::CastInst(llvm::Instruction::CastOps op, llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1838,7 +1838,7 @@ llvm::Instruction * FunctionEmitContext::FPCastInst(llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1857,7 +1857,7 @@ llvm::Instruction * FunctionEmitContext::SExtInst(llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1876,7 +1876,7 @@ llvm::Instruction * FunctionEmitContext::ZExtInst(llvm::Value *value, llvm::Type *type, const char *name) { if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -1953,7 +1953,7 @@ FunctionEmitContext::applyVaryingGEP(llvm::Value *basePtr, llvm::Value *index, // index must be varying for this method to be called. bool baseIsUniform = (llvm::isa(basePtr->getType())); - Assert(baseIsUniform == false || indexIsVarying == true); + AssertPos(currentPos, baseIsUniform == false || indexIsVarying == true); llvm::Value *varyingPtr = baseIsUniform ? SmearUniform(basePtr) : basePtr; // newPtr = ptr + offset @@ -2057,7 +2057,7 @@ llvm::Value * FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, const Type *ptrRefType, const char *name) { if (basePtr == NULL || index == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -2067,11 +2067,11 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, ptrType = PointerType::GetUniform(ptrRefType->GetReferenceTarget()); else { ptrType = CastType(ptrRefType); - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); } if (ptrType->IsSlice()) { - Assert(llvm::isa(basePtr->getType())); + AssertPos(currentPos, llvm::isa(basePtr->getType())); llvm::Value *ptrSliceOffset = ExtractInst(basePtr, 1); if (ptrType->IsFrozenSlice() == false) { @@ -2099,9 +2099,9 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index, // Double-check consistency between the given pointer type and its LLVM // type. if (ptrType->IsUniformType()) - Assert(llvm::isa(basePtr->getType())); + AssertPos(currentPos, llvm::isa(basePtr->getType())); else if (ptrType->IsVaryingType()) - Assert(llvm::isa(basePtr->getType())); + AssertPos(currentPos, llvm::isa(basePtr->getType())); bool indexIsVaryingType = llvm::isa(index->getType()); @@ -2127,7 +2127,7 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0 llvm::Value *index1, const Type *ptrRefType, const char *name) { if (basePtr == NULL || index0 == NULL || index1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -2137,14 +2137,14 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0 ptrType = PointerType::GetUniform(ptrRefType->GetReferenceTarget()); else { ptrType = CastType(ptrRefType); - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); } if (ptrType->IsSlice()) { // Similar to the 1D GEP implementation above, for non-frozen slice // pointers we do the two-step indexing calculation and then pass // the new major index on to a recursive GEP call. - Assert(llvm::isa(basePtr->getType())); + AssertPos(currentPos, llvm::isa(basePtr->getType())); llvm::Value *ptrSliceOffset = ExtractInst(basePtr, 1); if (ptrType->IsFrozenSlice() == false) { llvm::Value *newSliceOffset; @@ -2185,7 +2185,7 @@ FunctionEmitContext::GetElementPtrInst(llvm::Value *basePtr, llvm::Value *index0 // out the type of ptr0. const Type *baseType = ptrType->GetBaseType(); const SequentialType *st = CastType(baseType); - Assert(st != NULL); + AssertPos(currentPos, st != NULL); bool ptr0IsUniform = llvm::isa(ptr0->getType()); @@ -2204,7 +2204,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, const Type *ptrRefType, const char *name, const PointerType **resultPtrType) { if (resultPtrType != NULL) - Assert(ptrRefType != NULL); + AssertPos(currentPos, ptrRefType != NULL); llvm::PointerType *llvmPtrType = llvm::dyn_cast(fullBasePtr->getType()); @@ -2212,7 +2212,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, llvm::StructType *llvmStructType = llvm::dyn_cast(llvmPtrType->getElementType()); if (llvmStructType != NULL && llvmStructType->isSized() == false) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } } @@ -2226,7 +2226,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, ptrType = PointerType::GetUniform(ptrRefType->GetReferenceTarget()); else ptrType = CastType(ptrRefType); - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); } // Similarly, we have to see if the pointer type is a struct to see if @@ -2237,7 +2237,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, llvm::isa(fullBasePtr->getType()); const PointerType *rpt; if (baseIsSlicePtr) { - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); // Update basePtr to just be the part that actually points to the // start of an soa<> struct for now; the element offset computation // doesn't change the slice offset, so we'll incorporate that into @@ -2250,10 +2250,10 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, // Return the pointer type of the result of this call, for callers that // want it. if (resultPtrType != NULL) { - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); const CollectionType *ct = CastType(ptrType->GetBaseType()); - Assert(ct != NULL); + AssertPos(currentPos, ct != NULL); *resultPtrType = new PointerType(ct->GetElementType(elementNum), ptrType->GetVariability(), ptrType->IsConstType(), @@ -2285,7 +2285,7 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, // type of the vector. const SequentialType *st = CastType(ptrType->GetBaseType()); - Assert(st != NULL); + AssertPos(currentPos, st != NULL); llvm::Value *size = g->target.SizeOf(st->GetElementType()->LLVMType(g->ctx), bblock); llvm::Value *scale = (g->target.is32Bit || g->opt.force32BitAddressing) ? @@ -2317,13 +2317,13 @@ FunctionEmitContext::AddElementOffset(llvm::Value *fullBasePtr, int elementNum, llvm::Value * FunctionEmitContext::LoadInst(llvm::Value *ptr, const char *name) { if (ptr == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } llvm::PointerType *pt = llvm::dyn_cast(ptr->getType()); - Assert(pt != NULL); + AssertPos(currentPos, pt != NULL); if (name == NULL) name = LLVMGetName(ptr, "_load"); @@ -2419,11 +2419,11 @@ llvm::Value * FunctionEmitContext::LoadInst(llvm::Value *ptr, llvm::Value *mask, const Type *ptrRefType, const char *name) { if (ptr == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } - Assert(ptrRefType != NULL && mask != NULL); + AssertPos(currentPos, ptrRefType != NULL && mask != NULL); if (name == NULL) name = LLVMGetName(ptr, "_load"); @@ -2433,7 +2433,7 @@ FunctionEmitContext::LoadInst(llvm::Value *ptr, llvm::Value *mask, ptrType = PointerType::GetUniform(ptrRefType->GetReferenceTarget()); else { ptrType = CastType(ptrRefType); - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); } if (ptrType->IsUniformType()) { @@ -2476,7 +2476,7 @@ llvm::Value * FunctionEmitContext::gather(llvm::Value *ptr, const PointerType *ptrType, llvm::Value *mask, const char *name) { // We should have a varying pointer if we get here... - Assert(ptrType->IsVaryingType()); + AssertPos(currentPos, ptrType->IsVaryingType()); const Type *returnType = ptrType->GetBaseType()->GetAsVaryingType(); llvm::Type *llvmReturnType = returnType->LLVMType(g->ctx); @@ -2534,13 +2534,13 @@ FunctionEmitContext::gather(llvm::Value *ptr, const PointerType *ptrType, funcName = g->target.is32Bit ? "__pseudo_gather32_16" : "__pseudo_gather64_16"; else { - Assert(llvmReturnType == LLVMTypes::Int8VectorType); + AssertPos(currentPos, llvmReturnType == LLVMTypes::Int8VectorType); funcName = g->target.is32Bit ? "__pseudo_gather32_8" : "__pseudo_gather64_8"; } llvm::Function *gatherFunc = m->module->getFunction(funcName); - Assert(gatherFunc != NULL); + AssertPos(currentPos, gatherFunc != NULL); llvm::Value *call = CallInst(gatherFunc, NULL, ptr, mask, name); @@ -2591,7 +2591,7 @@ FunctionEmitContext::AllocaInst(llvm::Type *llvmType, const char *name, int align, bool atEntryBlock) { if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -2600,7 +2600,7 @@ FunctionEmitContext::AllocaInst(llvm::Type *llvmType, // We usually insert it right before the jump instruction at the // end of allocaBlock llvm::Instruction *retInst = allocaBlock->getTerminator(); - Assert(retInst); + AssertPos(currentPos, retInst); inst = new llvm::AllocaInst(llvmType, name ? name : "", retInst); } else @@ -2636,12 +2636,12 @@ void FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr, const Type *ptrType, llvm::Value *mask) { if (value == NULL || ptr == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return; } - Assert(CastType(ptrType) != NULL); - Assert(ptrType->IsUniformType()); + AssertPos(currentPos, CastType(ptrType) != NULL); + AssertPos(currentPos, ptrType->IsUniformType()); const Type *valueType = ptrType->GetBaseType(); const CollectionType *collectionType = CastType(valueType); @@ -2662,7 +2662,7 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr, // We must have a regular atomic, enumerator, or pointer type at this // point. - Assert(Type::IsBasicType(valueType)); + AssertPos(currentPos, Type::IsBasicType(valueType)); valueType = valueType->GetAsNonConstType(); // Figure out if we need a 8, 16, 32 or 64-bit masked store. @@ -2672,7 +2672,7 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr, if (pt != NULL) { if (pt->IsSlice()) { // Masked store of (varying) slice pointer. - Assert(pt->IsVaryingType()); + AssertPos(currentPos, pt->IsVaryingType()); // First, extract the pointer from the slice struct and masked // store that. @@ -2742,7 +2742,7 @@ FunctionEmitContext::maskedStore(llvm::Value *value, llvm::Value *ptr, ptr = BitCastInst(ptr, LLVMTypes::Int8VectorPointerType, LLVMGetName(ptr, "_to_int8vecptr")); } - Assert(maskedStoreFunc != NULL); + AssertPos(currentPos, maskedStoreFunc != NULL); std::vector args; args.push_back(ptr); @@ -2764,8 +2764,8 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr, const Type *valueType, const Type *origPt, llvm::Value *mask) { const PointerType *ptrType = CastType(origPt); - Assert(ptrType != NULL); - Assert(ptrType->IsVaryingType()); + AssertPos(currentPos, ptrType != NULL); + AssertPos(currentPos, ptrType->IsVaryingType()); const CollectionType *srcCollectionType = CastType(valueType); @@ -2780,7 +2780,7 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr, // instances of the struct type, etc. const CollectionType *dstCollectionType = CastType(ptrType->GetBaseType()); - Assert(dstCollectionType != NULL); + AssertPos(currentPos, dstCollectionType != NULL); // Scatter the collection elements individually for (int i = 0; i < srcCollectionType->GetElementCount(); ++i) { @@ -2827,7 +2827,7 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr, const PointerType *pt = CastType(valueType); // And everything should be a pointer or atomic from here on out... - Assert(pt != NULL || CastType(valueType) != NULL); + AssertPos(currentPos, pt != NULL || CastType(valueType) != NULL); llvm::Type *type = value->getType(); const char *funcName = NULL; @@ -2854,7 +2854,7 @@ FunctionEmitContext::scatter(llvm::Value *value, llvm::Value *ptr, "__pseudo_scatter64_8"; llvm::Function *scatterFunc = m->module->getFunction(funcName); - Assert(scatterFunc != NULL); + AssertPos(currentPos, scatterFunc != NULL); AddInstrumentationPoint("scatter"); @@ -2873,7 +2873,7 @@ void FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr) { if (value == NULL || ptr == NULL) { // may happen due to error elsewhere - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return; } @@ -2898,7 +2898,7 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr, const Type *ptrRefType) { if (value == NULL || ptr == NULL) { // may happen due to error elsewhere - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return; } @@ -2907,7 +2907,7 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr, ptrType = PointerType::GetUniform(ptrRefType->GetReferenceTarget()); else { ptrType = CastType(ptrRefType); - Assert(ptrType != NULL); + AssertPos(currentPos, ptrType != NULL); } // Figure out what kind of store we're doing here @@ -2926,7 +2926,7 @@ FunctionEmitContext::StoreInst(llvm::Value *value, llvm::Value *ptr, maskedStore(value, ptr, ptrType, mask); } else { - Assert(ptrType->IsVaryingType()); + AssertPos(currentPos, ptrType->IsVaryingType()); // We have a varying ptr (an array of pointers), so it's time to // scatter scatter(value, ptr, valueType, ptrType, GetFullMask()); @@ -2940,7 +2940,7 @@ void FunctionEmitContext::storeUniformToSOA(llvm::Value *value, llvm::Value *ptr, llvm::Value *mask, const Type *valueType, const PointerType *ptrType) { - Assert(Type::EqualIgnoringConst(ptrType->GetBaseType()->GetAsUniformType(), + AssertPos(currentPos, Type::EqualIgnoringConst(ptrType->GetBaseType()->GetAsUniformType(), valueType)); const CollectionType *ct = CastType(valueType); @@ -2959,7 +2959,7 @@ FunctionEmitContext::storeUniformToSOA(llvm::Value *value, llvm::Value *ptr, else { // We're finally at a leaf SOA array; apply the slice offset and // then we can do a final regular store - Assert(Type::IsBasicType(valueType)); + AssertPos(currentPos, Type::IsBasicType(valueType)); ptr = lFinalSliceOffset(this, ptr, &ptrType); StoreInst(value, ptr); } @@ -2972,7 +2972,7 @@ FunctionEmitContext::MemcpyInst(llvm::Value *dest, llvm::Value *src, dest = BitCastInst(dest, LLVMTypes::VoidPointerType); src = BitCastInst(src, LLVMTypes::VoidPointerType); if (count->getType() != LLVMTypes::Int64Type) { - Assert(count->getType() == LLVMTypes::Int32Type); + AssertPos(currentPos, count->getType() == LLVMTypes::Int32Type); count = ZExtInst(count, LLVMTypes::Int64Type, "count_to_64"); } if (align == NULL) @@ -2983,8 +2983,8 @@ FunctionEmitContext::MemcpyInst(llvm::Value *dest, llvm::Value *src, LLVMTypes::VoidType, LLVMTypes::VoidPointerType, LLVMTypes::VoidPointerType, LLVMTypes::Int64Type, LLVMTypes::Int32Type, LLVMTypes::BoolType, NULL); - Assert(mcFunc != NULL); - Assert(llvm::isa(mcFunc)); + AssertPos(currentPos, mcFunc != NULL); + AssertPos(currentPos, llvm::isa(mcFunc)); std::vector args; args.push_back(dest); @@ -3008,7 +3008,7 @@ FunctionEmitContext::BranchInst(llvm::BasicBlock *trueBlock, llvm::BasicBlock *falseBlock, llvm::Value *test) { if (test == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return; } @@ -3021,7 +3021,7 @@ FunctionEmitContext::BranchInst(llvm::BasicBlock *trueBlock, llvm::Value * FunctionEmitContext::ExtractInst(llvm::Value *v, int elt, const char *name) { if (v == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -3045,7 +3045,7 @@ llvm::Value * FunctionEmitContext::InsertInst(llvm::Value *v, llvm::Value *eltVal, int elt, const char *name) { if (v == NULL || eltVal == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -3080,7 +3080,7 @@ llvm::Instruction * FunctionEmitContext::SelectInst(llvm::Value *test, llvm::Value *val0, llvm::Value *val1, const char *name) { if (test == NULL || val0 == NULL || val1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -3123,7 +3123,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, const std::vector &args, const char *name) { if (func == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } @@ -3132,7 +3132,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, // isn't the case for things like intrinsics, builtins, and extern "C" // functions from the application. Add the mask if it's needed. unsigned int calleeArgCount = lCalleeArgCount(func, funcType); - Assert(argVals.size() + 1 == calleeArgCount || + AssertPos(currentPos, argVals.size() + 1 == calleeArgCount || argVals.size() == calleeArgCount); if (argVals.size() + 1 == calleeArgCount) argVals.push_back(GetFullMask()); @@ -3197,7 +3197,7 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, llvm::Value *currentMask = LoadInst(maskPtr); llvm::Function *cttz = m->module->getFunction("__count_trailing_zeros_i32"); - Assert(cttz != NULL); + AssertPos(currentPos, cttz != NULL); llvm::Value *firstLane = CallInst(cttz, NULL, LaneMask(currentMask), "first_lane"); @@ -3245,12 +3245,12 @@ FunctionEmitContext::CallInst(llvm::Value *func, const FunctionType *funcType, // accumulate the result using the call mask. if (callResult != NULL && callResult->getType() != LLVMTypes::VoidType) { - Assert(resultPtr != NULL); + AssertPos(currentPos, resultPtr != NULL); StoreInst(callResult, resultPtr, callMask, returnType, PointerType::GetUniform(returnType)); } else - Assert(resultPtr == NULL); + AssertPos(currentPos, resultPtr == NULL); // Update the mask to turn off the program instances for which // we just called the function. @@ -3310,7 +3310,7 @@ FunctionEmitContext::ReturnInst() { rinst = llvm::ReturnInst::Create(*g->ctx, retVal, bblock); } else { - Assert(Type::Equal(function->GetReturnType(), AtomicType::Void)); + AssertPos(currentPos, Type::Equal(function->GetReturnType(), AtomicType::Void)); rinst = llvm::ReturnInst::Create(*g->ctx, bblock); } @@ -3325,25 +3325,25 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, std::vector &argVals, llvm::Value *launchCount) { if (callee == NULL) { - Assert(m->errorCount > 0); + AssertPos(currentPos, m->errorCount > 0); return NULL; } launchedTasks = true; - Assert(llvm::isa(callee)); + AssertPos(currentPos, llvm::isa(callee)); llvm::Type *argType = (llvm::dyn_cast(callee))->arg_begin()->getType(); - Assert(llvm::PointerType::classof(argType)); + AssertPos(currentPos, llvm::PointerType::classof(argType)); llvm::PointerType *pt = llvm::dyn_cast(argType); - Assert(llvm::StructType::classof(pt->getElementType())); + AssertPos(currentPos, llvm::StructType::classof(pt->getElementType())); llvm::StructType *argStructType = static_cast(pt->getElementType()); - Assert(argStructType->getNumElements() == argVals.size() + 1); + AssertPos(currentPos, argStructType->getNumElements() == argVals.size() + 1); llvm::Function *falloc = m->module->getFunction("ISPCAlloc"); - Assert(falloc != NULL); + AssertPos(currentPos, falloc != NULL); llvm::Value *structSize = g->target.SizeOf(argStructType, bblock); if (structSize->getType() != LLVMTypes::Int64Type) // ISPCAlloc expects the size as an uint64_t, but on 32-bit @@ -3378,7 +3378,7 @@ FunctionEmitContext::LaunchInst(llvm::Value *callee, // argument block we just filled in llvm::Value *fptr = BitCastInst(callee, LLVMTypes::VoidPointerType); llvm::Function *flaunch = m->module->getFunction("ISPCLaunch"); - Assert(flaunch != NULL); + AssertPos(currentPos, flaunch != NULL); std::vector args; args.push_back(launchGroupHandlePtr); args.push_back(fptr); @@ -3427,7 +3427,7 @@ FunctionEmitContext::addVaryingOffsetsIfNeeded(llvm::Value *ptr, const Type *ptrType) { // This should only be called for varying pointers const PointerType *pt = CastType(ptrType); - Assert(pt && pt->IsVaryingType()); + AssertPos(currentPos, pt && pt->IsVaryingType()); const Type *baseType = ptrType->GetBaseType(); if (Type::IsBasicType(baseType) == false) @@ -3464,7 +3464,7 @@ FunctionEmitContext::addVaryingOffsetsIfNeeded(llvm::Value *ptr, CFInfo * FunctionEmitContext::popCFState() { - Assert(controlFlowInfo.size() > 0); + AssertPos(currentPos, controlFlowInfo.size() > 0); CFInfo *ci = controlFlowInfo.back(); controlFlowInfo.pop_back(); @@ -3488,7 +3488,7 @@ FunctionEmitContext::popCFState() { loopMask = ci->savedLoopMask; } else { - Assert(ci->IsIf()); + AssertPos(currentPos, ci->IsIf()); // nothing to do } diff --git a/decl.cpp b/decl.cpp index 728206fd..7cf2b5fb 100644 --- a/decl.cpp +++ b/decl.cpp @@ -231,7 +231,7 @@ Declarator::InitFromDeclSpecs(DeclSpecs *ds) { InitFromType(baseType, ds); if (type == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -319,8 +319,8 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { if (kind == DK_BASE) { // All of the type qualifiers should be in the DeclSpecs for the // base declarator - Assert(typeQualifiers == 0); - Assert(child == NULL); + AssertPos(pos, typeQualifiers == 0); + AssertPos(pos, child == NULL); type = baseType; } else if (kind == DK_POINTER) { @@ -398,7 +398,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { Declaration *d = functionParams[i]; if (d == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); continue; } if (d->declarators.size() == 0) { @@ -408,10 +408,10 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { d->declarators[0]->InitFromDeclSpecs(d->declSpecs); } - Assert(d->declarators.size() == 1); + AssertPos(pos, d->declarators.size() == 1); Declarator *decl = d->declarators[0]; if (decl == NULL || decl->type == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); continue; } @@ -446,7 +446,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { // significant problem.) const Type *targetType = at->GetElementType(); if (targetType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -525,7 +525,7 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { } if (child == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } diff --git a/expr.cpp b/expr.cpp index e5d0050c..3eaaa96f 100644 --- a/expr.cpp +++ b/expr.cpp @@ -148,7 +148,7 @@ lMaybeIssuePrecisionWarning(const AtomicType *toAtomicType, static Expr * lArrayToPointer(Expr *expr) { - Assert(expr && CastType(expr->GetType())); + AssertPos(expr->pos, expr && CastType(expr->GetType())); Expr *zero = new ConstExpr(AtomicType::UniformInt32, 0, expr->pos); Expr *index = new IndexExpr(expr, zero, expr->pos); @@ -189,7 +189,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, bool failureOk, const char *errorMsgBase, SourcePos pos) { /* This function is way too long and complex. Is type conversion stuff always this messy, or can this be cleaned up somehow? */ - Assert(failureOk || errorMsgBase != NULL); + AssertPos(pos, failureOk || errorMsgBase != NULL); if (toType == NULL || fromType == NULL) return false; @@ -465,7 +465,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, fromArrayType->GetElementType())) { // the case of different element counts should have returned // successfully earlier, yes?? - Assert(toArrayType->GetElementCount() != fromArrayType->GetElementCount()); + AssertPos(pos, toArrayType->GetElementCount() != fromArrayType->GetElementCount()); goto typecast_ok; } else if (Type::Equal(toArrayType->GetElementType(), @@ -521,7 +521,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, // enum -> atomic (integer, generally...) is always ok if (fromEnumType != NULL) { - Assert(toAtomicType != NULL || toVectorType != NULL); + AssertPos(pos, toAtomicType != NULL || toVectorType != NULL); goto typecast_ok; } @@ -643,7 +643,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, // pointer we have. llvm::Type *llvmType = symType->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -757,7 +757,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, collectionType ? collectionType->GetElementType(i) : symType->GetAsUniformType(); if (elementType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -776,7 +776,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, // rest as zero. llvm::Type *llvmType = elementType->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -1082,7 +1082,7 @@ lEmitNegate(Expr *arg, SourcePos pos, FunctionEmitContext *ctx) { return ctx->BinaryOperator(llvm::Instruction::FSub, zero, argVal, LLVMGetName(argVal, "_negate")); else { - Assert(type->IsIntType()); + AssertPos(pos, type->IsIntType()); return ctx->BinaryOperator(llvm::Instruction::Sub, zero, argVal, LLVMGetName(argVal, "_negate")); } @@ -1217,7 +1217,7 @@ UnaryExpr::Optimize() { FATAL("unexpected type in UnaryExpr::Optimize() / BitNot case"); } case LogicalNot: { - Assert(Type::EqualIgnoringConst(type, AtomicType::UniformBool) || + AssertPos(pos, Type::EqualIgnoringConst(type, AtomicType::UniformBool) || Type::EqualIgnoringConst(type, AtomicType::VaryingBool)); bool v[ISPC_MAX_NVEC]; int count = constExpr->AsBool(v); @@ -1410,7 +1410,7 @@ lEmitBinaryPointerArith(BinaryExpr::Op op, llvm::Value *value0, break; case BinaryExpr::Sub: { if (CastType(type1) != NULL) { - Assert(Type::Equal(type0, type1)); + AssertPos(pos, Type::Equal(type0, type1)); if (ptrType->IsSlice()) { llvm::Value *p0 = ctx->ExtractInst(value0, 0); @@ -1421,7 +1421,7 @@ lEmitBinaryPointerArith(BinaryExpr::Op op, llvm::Value *value0, ctx, pos); int soaWidth = ptrType->GetBaseType()->GetSOAWidth(); - Assert(soaWidth > 0); + AssertPos(pos, soaWidth > 0); llvm::Value *soaScale = LLVMIntAsType(soaWidth, majorDelta->getType()); @@ -1509,7 +1509,7 @@ lEmitBinaryArith(BinaryExpr::Op op, llvm::Value *value0, llvm::Value *value1, return lEmitBinaryPointerArith(op, value0, value1, type0, type1, ctx, pos); else { - Assert(Type::EqualIgnoringConst(type0, type1)); + AssertPos(pos, Type::EqualIgnoringConst(type0, type1)); llvm::Instruction::BinaryOps inst; bool isFloatOp = type0->IsFloatType(); @@ -1632,7 +1632,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, const Type *type0 = arg0->GetType(), *type1 = arg1->GetType(); if (type0 == NULL || type1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1650,17 +1650,17 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, // promote the uniform one to varying if (type0->IsUniformType() && type1->IsVaryingType()) { arg0 = TypeConvertExpr(arg0, AtomicType::VaryingBool, lOpString(op)); - Assert(arg0 != NULL); + AssertPos(pos, arg0 != NULL); } if (type1->IsUniformType() && type0->IsVaryingType()) { arg1 = TypeConvertExpr(arg1, AtomicType::VaryingBool, lOpString(op)); - Assert(arg1 != NULL); + AssertPos(pos, arg1 != NULL); } llvm::Value *value0 = arg0->GetValue(ctx); llvm::Value *value1 = arg1->GetValue(ctx); if (value0 == NULL || value1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1668,7 +1668,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, return ctx->BinaryOperator(llvm::Instruction::And, value0, value1, "logical_and"); else { - Assert(op == BinaryExpr::LogicalOr); + AssertPos(pos, op == BinaryExpr::LogicalOr); return ctx->BinaryOperator(llvm::Instruction::Or, value0, value1, "logical_or"); } @@ -1686,7 +1686,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, // Evaluate the first operand llvm::Value *value0 = arg0->GetValue(ctx); if (value0 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1710,7 +1710,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, ctx->BranchInst(bbLogicalDone); } else { - Assert(op == BinaryExpr::LogicalAnd); + AssertPos(pos, op == BinaryExpr::LogicalAnd); // Conversely, for &&, if value0 is false, we skip evaluating // value1. @@ -1732,12 +1732,12 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, ctx->SetCurrentBasicBlock(bbEvalValue1); if (type1->IsUniformType() && retType->IsVaryingType()) { arg1 = TypeConvertExpr(arg1, AtomicType::VaryingBool, "logical op"); - Assert(arg1 != NULL); + AssertPos(pos, arg1 != NULL); } llvm::Value *value1 = arg1->GetValue(ctx); if (value1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } ctx->StoreInst(value1, retPtr); @@ -1759,7 +1759,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, // perform logical vector ops with its value. if (type1->IsUniformType()) { arg1 = TypeConvertExpr(arg1, AtomicType::VaryingBool, "logical op"); - Assert(arg1 != NULL); + AssertPos(pos, arg1 != NULL); type1 = arg1->GetType(); } @@ -1794,7 +1794,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, llvm::Value *value1 = arg1->GetValue(ctx); if (value1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1812,7 +1812,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, ctx->BranchInst(bbLogicalDone); } else { - Assert(op == BinaryExpr::LogicalAnd); + AssertPos(pos, op == BinaryExpr::LogicalAnd); // If value0 is false for all currently running lanes, the // overall result must be false: this corresponds to checking @@ -1843,7 +1843,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, llvm::Value *value1 = arg1->GetValue(ctx); if (value1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1875,7 +1875,7 @@ lEmitLogicalOp(BinaryExpr::Op op, Expr *arg0, Expr *arg1, llvm::Value * BinaryExpr::GetValue(FunctionEmitContext *ctx) const { if (!arg0 || !arg1) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1886,7 +1886,7 @@ BinaryExpr::GetValue(FunctionEmitContext *ctx) const { llvm::Value *value0 = arg0->GetValue(ctx); llvm::Value *value1 = arg1->GetValue(ctx); if (value0 == NULL || value1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -1942,7 +1942,7 @@ BinaryExpr::GetType() const { // and will fail type checking and (int + ptr) should be canonicalized // into (ptr + int) by type checking. if (op == Add) - Assert(CastType(type1) == NULL); + AssertPos(pos, CastType(type1) == NULL); if (op == Comma) return arg1->GetType(); @@ -1967,14 +1967,14 @@ BinaryExpr::GetType() const { } // otherwise fall through for these... - Assert(op == Lt || op == Gt || op == Le || op == Ge || + AssertPos(pos, op == Lt || op == Gt || op == Le || op == Ge || op == Equal || op == NotEqual); } const Type *exprType = Type::MoreGeneralType(type0, type1, pos, lOpString(op)); // I don't think that MoreGeneralType should be able to fail after the // checks done in BinaryExpr::TypeCheck(). - Assert(exprType != NULL); + AssertPos(pos, exprType != NULL); switch (op) { case Add: @@ -2159,7 +2159,7 @@ BinaryExpr::Optimize() { std::vector rcpFuns; m->symbolTable->LookupFunction("rcp", &rcpFuns); if (rcpFuns.size() > 0) { - Assert(rcpFuns.size() == 2); + AssertPos(pos, rcpFuns.size() == 2); Expr *rcpSymExpr = new FunctionSymbolExpr("rcp", rcpFuns, pos); ExprList *args = new ExprList(arg1, arg1->pos); Expr *rcpCall = new FunctionCallExpr(rcpSymExpr, args, @@ -2189,7 +2189,7 @@ BinaryExpr::Optimize() { if (constArg0 == NULL || constArg1 == NULL) return this; - Assert(Type::EqualIgnoringConst(arg0->GetType(), arg1->GetType())); + AssertPos(pos, Type::EqualIgnoringConst(arg0->GetType(), arg1->GetType())); const Type *type = arg0->GetType()->GetAsNonConstType(); if (Type::Equal(type, AtomicType::UniformFloat) || Type::Equal(type, AtomicType::VaryingFloat)) { @@ -2280,12 +2280,12 @@ BinaryExpr::TypeCheck() { if (CastType(type0) != NULL) { arg0 = new RefDerefExpr(arg0, arg0->pos); type0 = arg0->GetType(); - Assert(type0 != NULL); + AssertPos(pos, type0 != NULL); } if (CastType(type1) != NULL) { arg1 = new RefDerefExpr(arg1, arg1->pos); type1 = arg1->GetType(); - Assert(type1 != NULL); + AssertPos(pos, type1 != NULL); } // Convert arrays to pointers to their first elements @@ -2362,7 +2362,7 @@ BinaryExpr::TypeCheck() { std::swap(pt0, pt1); } - Assert(pt0 != NULL); + AssertPos(pos, pt0 != NULL); if (PointerType::IsVoidPointer(pt0)) { Error(pos, "Illegal to perform pointer arithmetic " @@ -2383,7 +2383,7 @@ BinaryExpr::TypeCheck() { arg0 = TypeConvertExpr(arg0, type0->GetAsVaryingType(), "pointer addition"); offsetType = offsetType->GetAsVaryingType(); - Assert(arg0 != NULL); + AssertPos(pos, arg0 != NULL); } arg1 = TypeConvertExpr(arg1, offsetType, lOpString(op)); @@ -2721,13 +2721,13 @@ AssignExpr::GetValue(FunctionEmitContext *ctx) const { const Type *ptrType = lvalue->GetLValueType(); const Type *valueType = rvalue->GetType(); if (ptrType == NULL || valueType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } llvm::Value *value = rvalue->GetValue(ctx); if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -2748,7 +2748,7 @@ AssignExpr::GetValue(FunctionEmitContext *ctx) const { case XorAssign: case OrAssign: { // This should be caught during type checking - Assert(!CastType(type) && + AssertPos(pos, !CastType(type) && !CastType(type)); return lEmitOpAssign(op, lvalue, rvalue, type, baseSym, pos, ctx); } @@ -2841,7 +2841,7 @@ AssignExpr::TypeCheck() { const Type *lhsType = lvalue->GetType(); if (lhsType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -2992,7 +2992,7 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const { const Type *testType = test->GetType()->GetAsNonConstType(); // This should be taken care of during typechecking - Assert(Type::Equal(testType->GetBaseType(), AtomicType::UniformBool) || + AssertPos(pos, Type::Equal(testType->GetBaseType(), AtomicType::UniformBool) || Type::Equal(testType->GetBaseType(), AtomicType::VaryingBool)); const Type *type = expr1->GetType(); @@ -3032,7 +3032,7 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const { else if (CastType(testType) == NULL) { // the test is a varying bool type llvm::Value *testVal = test->GetValue(ctx); - Assert(testVal->getType() == LLVMTypes::MaskType); + AssertPos(pos, testVal->getType() == LLVMTypes::MaskType); llvm::Value *oldMask = ctx->GetInternalMask(); llvm::Value *fullMask = ctx->GetFullMask(); @@ -3095,8 +3095,8 @@ SelectExpr::GetValue(FunctionEmitContext *ctx) const { ctx->SetDebugPos(pos); const VectorType *vt = CastType(type); // Things that typechecking should have caught - Assert(vt != NULL); - Assert(CastType(testType) != NULL && + AssertPos(pos, vt != NULL); + AssertPos(pos, CastType(testType) != NULL && (CastType(testType)->GetElementCount() == vt->GetElementCount())); @@ -3137,7 +3137,7 @@ SelectExpr::GetType() const { CastType(testType)->GetElementCount() : 0; int expr1VecSize = CastType(expr1Type) != NULL ? CastType(expr1Type)->GetElementCount() : 0; - Assert(!(testVecSize != 0 && expr1VecSize != 0 && testVecSize != expr1VecSize)); + AssertPos(pos, !(testVecSize != 0 && expr1VecSize != 0 && testVecSize != expr1VecSize)); int vectorSize = std::max(testVecSize, expr1VecSize); return Type::MoreGeneralType(expr1Type, expr2Type, Union(expr1->pos, expr2->pos), @@ -3182,9 +3182,9 @@ SelectExpr::Optimize() { if (constExpr1 == NULL || constExpr2 == NULL) return this; - Assert(Type::Equal(constExpr1->GetType(), constExpr2->GetType())); + AssertPos(pos, Type::Equal(constExpr1->GetType(), constExpr2->GetType())); const Type *exprType = constExpr1->GetType()->GetAsNonConstType(); - Assert(exprType->IsVaryingType()); + AssertPos(pos, exprType->IsVaryingType()); // FIXME: it's annoying to have to have all of this replicated code. if (Type::Equal(exprType, AtomicType::VaryingInt32) || @@ -3348,12 +3348,12 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const { llvm::Value *callee = func->GetValue(ctx); if (callee == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } const FunctionType *ft = lGetFunctionType(func); - Assert(ft != NULL); + AssertPos(pos, ft != NULL); bool isVoidFunc = Type::Equal(ft->GetReturnType(), AtomicType::Void); // Automatically convert function call args to references if needed. @@ -3366,7 +3366,7 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const { // Specifically, this can happen if there's an error earlier during // overload resolution. if ((int)callargs.size() > ft->GetNumParameters()) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -3433,7 +3433,7 @@ FunctionCallExpr::GetValue(FunctionEmitContext *ctx) const { llvm::Value *retVal = NULL; ctx->SetDebugPos(pos); if (ft->isTask) { - Assert(launchCountExpr != NULL); + AssertPos(pos, launchCountExpr != NULL); llvm::Value *launchCount = launchCountExpr->GetValue(ctx); if (launchCount != NULL) ctx->LaunchInst(callee, argVals, launchCount); @@ -3527,7 +3527,7 @@ FunctionCallExpr::TypeCheck() { if (isLaunch) Error(pos, "\"launch\" expression illegal with non-\"task\"-" "qualified function."); - Assert(launchCountExpr == NULL); + AssertPos(pos, launchCountExpr == NULL); } } else { @@ -3583,7 +3583,7 @@ FunctionCallExpr::TypeCheck() { // Otherwise the parameter default saves us. It should // be there for sure, given the check right above the // for loop. - Assert(funcType->GetParameterDefault(i) != NULL); + AssertPos(pos, funcType->GetParameterDefault(i) != NULL); } if (fptrType->IsVaryingType()) { @@ -3715,7 +3715,7 @@ ExprList::GetConstant(const Type *type) const { // conversion machinery handle it. expr = TypeConvertExpr(exprs[i], elementType, "initializer list"); if (expr == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } // Re-establish const-ness if possible @@ -3734,13 +3734,13 @@ ExprList::GetConstant(const Type *type) const { for (int i = (int)exprs.size(); i < collectionType->GetElementCount(); ++i) { const Type *elementType = collectionType->GetElementType(i); if (elementType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } llvm::Type *llvmType = elementType->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -3751,7 +3751,7 @@ ExprList::GetConstant(const Type *type) const { if (CastType(type) != NULL) { llvm::StructType *llvmStructType = llvm::dyn_cast(collectionType->LLVMType(g->ctx)); - Assert(llvmStructType != NULL); + AssertPos(pos, llvmStructType != NULL); return llvm::ConstantStruct::get(llvmStructType, cv); } else { @@ -3762,11 +3762,11 @@ ExprList::GetConstant(const Type *type) const { return llvm::ConstantArray::get(lat, cv); else { // uniform short vector type - Assert(type->IsUniformType() && + AssertPos(pos, type->IsUniformType() && CastType(type) != NULL); llvm::VectorType *lvt = llvm::dyn_cast(lt); - Assert(lvt != NULL); + AssertPos(pos, lvt != NULL); // Uniform short vectors are stored as vectors of length // rounded up to the native vector width. So we add additional @@ -3900,7 +3900,7 @@ lVaryingStructHasUniformMember(const Type *type, SourcePos pos) { for (int i = 0; i < st->GetElementCount(); ++i) { const Type *eltType = st->GetElementType(i); if (eltType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); continue; } @@ -3932,7 +3932,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { if (baseExpr == NULL || index == NULL || ((indexType = index->GetType()) == NULL) || ((returnType = GetType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -3955,7 +3955,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { const Type *baseExprType = baseExpr->GetType(); llvm::Value *val = baseExpr->GetValue(ctx); if (baseExprType == NULL || val == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } ctx->SetDebugPos(pos); @@ -3965,7 +3965,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { // Get a pointer type to the underlying elements const SequentialType *st = CastType(baseExprType); - Assert(st != NULL); + AssertPos(pos, st != NULL); lvType = PointerType::GetUniform(st->GetElementType()); // And do the indexing calculation into the temporary array in memory @@ -3977,7 +3977,7 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { } else { Symbol *baseSym = GetBaseSymbol(); - Assert(baseSym != NULL); + AssertPos(pos, baseSym != NULL); mask = lMaskForSymbol(baseSym, ctx); } @@ -4007,7 +4007,7 @@ IndexExpr::GetType() const { const SequentialType *sequentialType = CastType(baseExprType->GetReferenceTarget()); // Typechecking should have caught this... - Assert(sequentialType != NULL); + AssertPos(pos, sequentialType != NULL); elementType = sequentialType->GetElementType(); } @@ -4120,14 +4120,14 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const { const Type *baseExprType; if (baseExpr == NULL || index == NULL || ((baseExprType = baseExpr->GetType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } ctx->SetDebugPos(pos); llvm::Value *indexValue = index->GetValue(ctx); if (indexValue == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4136,7 +4136,7 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const { // We're indexing off of a pointer llvm::Value *basePtrValue = baseExpr->GetValue(ctx); if (basePtrValue == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } ctx->SetDebugPos(pos); @@ -4159,11 +4159,11 @@ IndexExpr::GetLValue(FunctionEmitContext *ctx) const { CastType(baseExprType)) { basePtr = baseExpr->GetLValue(ctx); basePtrType = CastType(baseExpr->GetLValueType()); - if (baseExpr->GetLValueType()) Assert(basePtrType != NULL); + if (baseExpr->GetLValueType()) AssertPos(pos, basePtrType != NULL); } else { baseExprType = baseExprType->GetReferenceTarget(); - Assert(CastType(baseExprType) || + AssertPos(pos, CastType(baseExprType) || CastType(baseExprType)); basePtr = baseExpr->GetValue(ctx); basePtrType = PointerType::GetUniform(baseExprType); @@ -4205,7 +4205,7 @@ IndexExpr::GetLValueType() const { const Type *refTarget = baseExprLValueType->GetReferenceTarget(); baseExprLValueType = PointerType::GetUniform(refTarget); } - Assert(CastType(baseExprLValueType) != NULL); + AssertPos(pos, CastType(baseExprLValueType) != NULL); // Find the type of thing that we're indexing into const Type *elementType; @@ -4216,7 +4216,7 @@ IndexExpr::GetLValueType() const { else { const PointerType *pt = CastType(baseExprLValueType->GetBaseType()); - Assert(pt != NULL); + AssertPos(pos, pt != NULL); elementType = pt->GetBaseType(); } @@ -4258,13 +4258,13 @@ IndexExpr::TypeCheck() { const Type *indexType; if (baseExpr == NULL || index == NULL || ((indexType = index->GetType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } const Type *baseExprType = baseExpr->GetType(); if (baseExprType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4395,7 +4395,7 @@ StructMemberExpr::GetType() const { ((exprType = expr->GetType()) == NULL) || ((structType = getStructType()) == NULL) || ((lvalueType = GetLValueType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4407,14 +4407,14 @@ StructMemberExpr::GetType() const { getCandidateNearMatches().c_str()); return NULL; } - Assert(Type::Equal(lvalueType->GetBaseType(), elementType)); + AssertPos(pos, Type::Equal(lvalueType->GetBaseType(), elementType)); bool isSlice = (CastType(lvalueType) && CastType(lvalueType)->IsSlice()); if (isSlice) { // FIXME: not true if we allow bound unif/varying for soa<> // structs?... - Assert(elementType->IsSOAType()); + AssertPos(pos, elementType->IsSOAType()); // If we're accessing a member of an soa structure via a uniform // slice pointer, then the result type is the uniform variant of @@ -4440,14 +4440,14 @@ StructMemberExpr::GetLValueType() const { return lvalueType; if (expr == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } const Type *exprLValueType = dereferenceExpr ? expr->GetType() : expr->GetLValueType(); if (exprLValueType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4514,12 +4514,12 @@ StructMemberExpr::getStructType() const { structType = rt->GetReferenceTarget(); else { const PointerType *pt = CastType(type); - Assert(pt != NULL); + AssertPos(pos, pt != NULL); structType = pt->GetBaseType(); } const StructType *ret = CastType(structType); - Assert(ret != NULL); + AssertPos(pos, ret != NULL); return ret; } @@ -4557,11 +4557,11 @@ VectorMemberExpr::VectorMemberExpr(Expr *e, const char *id, SourcePos p, if (pt != NULL) exprVectorType = CastType(pt->GetBaseType()); else { - Assert(CastType(exprType) != NULL); + AssertPos(pos, CastType(exprType) != NULL); exprVectorType = CastType(exprType->GetReferenceTarget()); } - Assert(exprVectorType != NULL); + AssertPos(pos, exprVectorType != NULL); } memberType = new VectorType(exprVectorType->GetElementType(), identifier.length()); @@ -4586,7 +4586,7 @@ VectorMemberExpr::GetType() const { bool isSlice = (CastType(lvType) && CastType(lvType)->IsSlice()); if (isSlice) { -//CO Assert(type->IsSOAType()); +//CO AssertPos(pos, type->IsSOAType()); if (lvType->IsUniformType()) type = type->GetAsUniformType(); } @@ -4616,7 +4616,7 @@ VectorMemberExpr::GetLValueType() const { if (identifier.length() == 1) { if (expr == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4630,7 +4630,7 @@ VectorMemberExpr::GetLValueType() const { vt = CastType(exprLValueType->GetReferenceTarget()); else vt = CastType(exprLValueType->GetBaseType()); - Assert(vt != NULL); + AssertPos(pos, vt != NULL); // we don't want to report that it's e.g. a pointer to a float<1>, // but a pointer to a float, etc. @@ -4683,7 +4683,7 @@ VectorMemberExpr::GetValue(FunctionEmitContext *ctx) const { } if (basePtr == NULL || basePtrType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4825,7 +4825,7 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const { // so that we can index from there... llvm::Value *val = expr->GetValue(ctx); if (!val) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } ctx->SetDebugPos(pos); @@ -4845,7 +4845,7 @@ MemberExpr::GetValue(FunctionEmitContext *ctx) const { } else { Symbol *baseSym = GetBaseSymbol(); - Assert(baseSym != NULL); + AssertPos(pos, baseSym != NULL); mask = lMaskForSymbol(baseSym, ctx); } @@ -4897,7 +4897,7 @@ MemberExpr::GetLValue(FunctionEmitContext *ctx) const { exprLValueType, basePtr->getName().str().c_str()); if (ptr == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -4975,7 +4975,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt8->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->GetAsConstType())); int8Val[0] = i; } @@ -4984,7 +4984,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t *i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt8->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingInt8->GetAsConstType())); for (int j = 0; j < Count(); ++j) int8Val[j] = i[j]; @@ -4995,7 +4995,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType())); uint8Val[0] = u; } @@ -5004,7 +5004,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t *u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingUInt8->GetAsConstType())); for (int j = 0; j < Count(); ++j) uint8Val[j] = u[j]; @@ -5015,7 +5015,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt16->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->GetAsConstType())); int16Val[0] = i; } @@ -5024,7 +5024,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t *i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt16->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingInt16->GetAsConstType())); for (int j = 0; j < Count(); ++j) int16Val[j] = i[j]; @@ -5035,7 +5035,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType())); uint16Val[0] = u; } @@ -5044,7 +5044,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t *u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingUInt16->GetAsConstType())); for (int j = 0; j < Count(); ++j) uint16Val[j] = u[j]; @@ -5055,7 +5055,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt32->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->GetAsConstType())); int32Val[0] = i; } @@ -5064,7 +5064,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t *i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt32->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingInt32->GetAsConstType())); for (int j = 0; j < Count(); ++j) int32Val[j] = i[j]; @@ -5075,7 +5075,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || (CastType(type) != NULL && type->IsUniformType())); uint32Val[0] = u; @@ -5086,7 +5086,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t *u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingUInt32->GetAsConstType()) || (CastType(type) != NULL)); for (int j = 0; j < Count(); ++j) @@ -5098,7 +5098,7 @@ ConstExpr::ConstExpr(const Type *t, float f, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformFloat->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->GetAsConstType())); floatVal[0] = f; } @@ -5107,7 +5107,7 @@ ConstExpr::ConstExpr(const Type *t, float *f, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformFloat->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingFloat->GetAsConstType())); for (int j = 0; j < Count(); ++j) floatVal[j] = f[j]; @@ -5118,7 +5118,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt64->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->GetAsConstType())); int64Val[0] = i; } @@ -5127,7 +5127,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t *i, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformInt64->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingInt64->GetAsConstType())); for (int j = 0; j < Count(); ++j) int64Val[j] = i[j]; @@ -5138,7 +5138,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType())); uint64Val[0] = u; } @@ -5147,7 +5147,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t *u, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingUInt64->GetAsConstType())); for (int j = 0; j < Count(); ++j) uint64Val[j] = u[j]; @@ -5158,7 +5158,7 @@ ConstExpr::ConstExpr(const Type *t, double f, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformDouble->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->GetAsConstType())); doubleVal[0] = f; } @@ -5167,7 +5167,7 @@ ConstExpr::ConstExpr(const Type *t, double *f, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformDouble->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingDouble->GetAsConstType())); for (int j = 0; j < Count(); ++j) doubleVal[j] = f[j]; @@ -5178,7 +5178,7 @@ ConstExpr::ConstExpr(const Type *t, bool b, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformBool->GetAsConstType())); + AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->GetAsConstType())); boolVal[0] = b; } @@ -5187,7 +5187,7 @@ ConstExpr::ConstExpr(const Type *t, bool *b, SourcePos p) : Expr(p) { type = t; type = type->GetAsConstType(); - Assert(Type::Equal(type, AtomicType::UniformBool->GetAsConstType()) || + AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->GetAsConstType()) || Type::Equal(type, AtomicType::VaryingBool->GetAsConstType())); for (int j = 0; j < Count(); ++j) boolVal[j] = b[j]; @@ -5301,7 +5301,7 @@ ConstExpr::getBasicType() const { if (at != NULL) return at->basicType; else { - Assert(CastType(type) != NULL); + AssertPos(pos, CastType(type) != NULL); return AtomicType::TYPE_UINT32; } } @@ -5653,7 +5653,7 @@ ConstExpr::GetConstant(const Type *type) const { // Caller shouldn't be trying to stuff a varying value here into a // constant type. if (type->IsUniformType()) - Assert(Count() == 1); + AssertPos(pos, Count() == 1); type = type->GetAsNonConstType(); if (Type::Equal(type, AtomicType::UniformBool) || @@ -5762,7 +5762,7 @@ ConstExpr::GetConstant(const Type *type) const { // appropriate type. llvm::Type *llvmType = type->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -6430,7 +6430,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { ctx->SetDebugPos(pos); const Type *toType = GetType(), *fromType = expr->GetType(); if (toType == NULL || fromType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -6481,11 +6481,11 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { } else { // Uniform -> varying pointer conversion - Assert(fromType->IsUniformType() && toType->IsVaryingType()); + AssertPos(pos, fromType->IsUniformType() && toType->IsVaryingType()); if (fromPointerType->IsSlice()) { // For slice pointers, we need to smear out both the // pointer and the offset vector - Assert(toPointerType->IsSlice()); + AssertPos(pos, toPointerType->IsSlice()); llvm::Value *ptr = ctx->ExtractInst(value, 0); llvm::Value *offset = ctx->ExtractInst(value, 1); ptr = ctx->PtrToIntInst(ptr); @@ -6502,7 +6502,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { } } else { - Assert(CastType(toType) != NULL); + AssertPos(pos, CastType(toType) != NULL); if (toType->IsBoolType()) { // convert pointer to bool llvm::Type *lfu = @@ -6554,21 +6554,21 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { // implicit array to pointer to first element Expr *arrayAsPtr = lArrayToPointer(expr); if (Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType) == false) { - Assert(PointerType::IsVoidPointer(toPointerType) || + AssertPos(pos, PointerType::IsVoidPointer(toPointerType) || Type::EqualIgnoringConst(arrayAsPtr->GetType()->GetAsVaryingType(), toPointerType) == true); arrayAsPtr = new TypeCastExpr(toPointerType, arrayAsPtr, pos); arrayAsPtr = ::TypeCheck(arrayAsPtr); - Assert(arrayAsPtr != NULL); + AssertPos(pos, arrayAsPtr != NULL); arrayAsPtr = ::Optimize(arrayAsPtr); - Assert(arrayAsPtr != NULL); + AssertPos(pos, arrayAsPtr != NULL); } - Assert(Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType)); + AssertPos(pos, Type::EqualIgnoringConst(arrayAsPtr->GetType(), toPointerType)); return arrayAsPtr->GetValue(ctx); } // This also should be caught during typechecking - Assert(!(toType->IsUniformType() && fromType->IsVaryingType())); + AssertPos(pos, !(toType->IsUniformType() && fromType->IsVaryingType())); if (toArrayType != NULL && fromArrayType != NULL) { // cast array pointer from [n x foo] to [0 x foo] if needed to be able @@ -6577,7 +6577,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { (toArrayType->GetElementCount() != fromArrayType->GetElementCount())) Warning(pos, "Type-converting array of length %d to length %d", fromArrayType->GetElementCount(), toArrayType->GetElementCount()); - Assert(Type::EqualIgnoringConst(toArrayType->GetBaseType(), + AssertPos(pos, Type::EqualIgnoringConst(toArrayType->GetBaseType(), fromArrayType->GetBaseType())); llvm::Value *v = expr->GetValue(ctx); llvm::Type *ptype = toType->LLVMType(g->ctx); @@ -6599,14 +6599,14 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { (toArray->GetElementCount() != fromArray->GetElementCount())) Warning(pos, "Type-converting array of length %d to length %d", fromArray->GetElementCount(), toArray->GetElementCount()); - Assert(Type::EqualIgnoringConst(toArray->GetBaseType(), + AssertPos(pos, Type::EqualIgnoringConst(toArray->GetBaseType(), fromArray->GetBaseType())); llvm::Value *v = expr->GetValue(ctx); llvm::Type *ptype = toType->LLVMType(g->ctx); return ctx->BitCastInst(v, ptype); //, "array_cast_0size"); } - Assert(Type::Equal(toTarget, fromTarget) || + AssertPos(pos, Type::Equal(toTarget, fromTarget) || Type::Equal(toTarget, fromTarget->GetAsConstType())); return expr->GetValue(ctx); } @@ -6616,7 +6616,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { if (toStruct && fromStruct) { // The only legal type conversions for structs are to go from a // uniform to a varying instance of the same struct type. - Assert(toStruct->IsVaryingType() && fromStruct->IsUniformType() && + AssertPos(pos, toStruct->IsVaryingType() && fromStruct->IsUniformType() && Type::EqualIgnoringConst(toStruct, fromStruct->GetAsVaryingType())); @@ -6630,7 +6630,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { const VectorType *fromVector = CastType(fromType); if (toVector && fromVector) { // this should be caught during typechecking - Assert(toVector->GetElementCount() == fromVector->GetElementCount()); + AssertPos(pos, toVector->GetElementCount() == fromVector->GetElementCount()); llvm::Value *exprVal = expr->GetValue(ctx); if (!exprVal) @@ -6672,7 +6672,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { const AtomicType *fromAtomic = CastType(fromType); // at this point, coming from an atomic type is all that's left... - Assert(fromAtomic != NULL); + AssertPos(pos, fromAtomic != NULL); if (toVector) { // scalar -> short vector conversion @@ -6700,7 +6700,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { else { const AtomicType *toAtomic = CastType(toType); // typechecking should ensure this is the case - Assert(toAtomic != NULL); + AssertPos(pos, toAtomic != NULL); return lTypeConvAtomic(ctx, exprVal, toAtomic, fromAtomic, pos); } @@ -6709,7 +6709,7 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const { const Type * TypeCastExpr::GetType() const { - Assert(type->HasUnboundVariability() == false); + AssertPos(pos, type->HasUnboundVariability() == false); return type; } @@ -6972,7 +6972,7 @@ llvm::Value * ReferenceExpr::GetValue(FunctionEmitContext *ctx) const { ctx->SetDebugPos(pos); if (expr == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -6986,13 +6986,13 @@ ReferenceExpr::GetValue(FunctionEmitContext *ctx) const { llvm::Type *llvmType; if ((type = expr->GetType()) == NULL || (llvmType = type->LLVMType(g->ctx)) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } value = expr->GetValue(ctx); if (value == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -7142,10 +7142,10 @@ const Type * PtrDerefExpr::GetType() const { const Type *type; if (expr == NULL || (type = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } - Assert(CastType(type) != NULL); + AssertPos(pos, CastType(type) != NULL); if (type->IsUniformType()) return type->GetBaseType(); @@ -7158,7 +7158,7 @@ Expr * PtrDerefExpr::TypeCheck() { const Type *type; if (expr == NULL || (type = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -7176,7 +7176,7 @@ int PtrDerefExpr::EstimateCost() const { const Type *type; if (expr == NULL || (type = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return 0; } @@ -7213,11 +7213,11 @@ const Type * RefDerefExpr::GetType() const { const Type *type; if (expr == NULL || (type = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } - Assert(CastType(type) != NULL); + AssertPos(pos, CastType(type) != NULL); return type->GetReferenceTarget(); } @@ -7226,14 +7226,14 @@ Expr * RefDerefExpr::TypeCheck() { const Type *type; if (expr == NULL || (type = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } // We only create RefDerefExprs internally for references in // expressions, so we should never create one with a non-reference // expression... - Assert(CastType(type) != NULL); + AssertPos(pos, CastType(type) != NULL); return this; } @@ -7298,7 +7298,7 @@ AddressOfExpr::GetType() const { else { t = expr->GetType(); if (t == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } return PointerType::GetUniform(t); @@ -7328,7 +7328,7 @@ Expr * AddressOfExpr::TypeCheck() { const Type *exprType; if (expr == NULL || (exprType = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -7361,7 +7361,7 @@ llvm::Constant * AddressOfExpr::GetConstant(const Type *type) const { const Type *exprType; if (expr == NULL || (exprType = expr->GetType()) == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -7518,7 +7518,7 @@ SymbolExpr::Optimize() { if (symbol == NULL) return NULL; else if (symbol->constValue != NULL) { - Assert(GetType()->IsConstType()); + AssertPos(pos, GetType()->IsConstType()); return new ConstExpr(symbol->constValue, pos); } else @@ -7638,7 +7638,7 @@ lPrintOverloadCandidates(SourcePos pos, const std::vector &funcs, const std::vector *argCouldBeNULL) { for (unsigned int i = 0; i < funcs.size(); ++i) { const FunctionType *ft = CastType(funcs[i]->type); - Assert(ft != NULL); + AssertPos(pos, ft != NULL); Error(funcs[i]->pos, "Candidate function: %s.", ft->GetString().c_str()); } @@ -7751,7 +7751,7 @@ FunctionSymbolExpr::getCandidateFunctions(int argCount) const { for (int i = 0; i < (int)candidateFunctions.size(); ++i) { const FunctionType *ft = CastType(candidateFunctions[i]->type); - Assert(ft != NULL); + AssertPos(pos, ft != NULL); // There's no way to match if the caller is passing more arguments // than this function instance takes. @@ -7896,7 +7896,7 @@ FunctionSymbolExpr::ResolveOverloads(SourcePos argPos, for (int i = 0; i < (int)actualCandidates.size(); ++i) { const FunctionType *ft = CastType(actualCandidates[i]->type); - Assert(ft != NULL); + AssertPos(pos, ft != NULL); candidateCosts.push_back(computeOverloadCost(ft, argTypes, argCouldBeNULL, argIsConstant)); @@ -8025,7 +8025,7 @@ NullPointerExpr::GetConstant(const Type *type) const { llvm::Type *llvmType = type->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -8090,7 +8090,7 @@ NewExpr::GetValue(FunctionEmitContext *ctx) const { if (countExpr != NULL) { countValue = countExpr->GetValue(ctx); if (countValue == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } } @@ -8130,7 +8130,7 @@ NewExpr::GetValue(FunctionEmitContext *ctx) const { "alloc_size64"); func = m->module->getFunction("__new_uniform"); } - Assert(func != NULL); + AssertPos(pos, func != NULL); // Make the call for the the actual allocation. llvm::Value *ptrValue = ctx->CallInst(func, NULL, allocSize, "new"); @@ -8211,7 +8211,7 @@ Expr * NewExpr::TypeCheck() { // It's illegal to call new with an undefined struct type if (allocType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } if (CastType(allocType) != NULL) { diff --git a/ispc.h b/ispc.h index bd170936..d0837110 100644 --- a/ispc.h +++ b/ispc.h @@ -58,16 +58,6 @@ #include #include -#define Assert(expr) \ - ((void)((expr) ? 0 : __Assert (#expr, __FILE__, __LINE__))) -#define __Assert(expr, file, line) \ - ((void)fprintf(stderr, "%s:%u: Assertion failed: \"%s\"\n" \ - "***\n*** Please file a bug report at " \ - "https://github.com/ispc/ispc/issues\n*** (Including as much " \ - "information as you can about how to reproduce this error).\n" \ - "*** You have apparently encountered a bug in the compiler that " \ - "we'd like to fix!\n***\n", file, line, expr), abort(), 0) - /** @def ISPC_MAX_NVEC maximum vector size of any of the compliation targets. */ @@ -145,11 +135,25 @@ struct SourcePos { bool operator==(const SourcePos &p2) const; }; + /** Returns a SourcePos that encompasses the extent of both of the given extents. */ SourcePos Union(const SourcePos &p1, const SourcePos &p2); + +// Assert + +extern void DoAssert(const char *file, int line, const char *expr); +extern void DoAssertPos(SourcePos pos, const char *file, int line, const char *expr); + +#define Assert(expr) \ + ((void)((expr) ? 0 : ((void)DoAssert (__FILE__, __LINE__, #expr), 0))) + +#define AssertPos(pos, expr) \ + ((void)((expr) ? 0 : ((void)DoAssertPos (pos, __FILE__, __LINE__, #expr), 0))) + + /** @brief Structure that defines a compilation target This structure defines a compilation target for the ispc compiler. diff --git a/parse.yy b/parse.yy index f72a9f65..3eb4b2be 100644 --- a/parse.yy +++ b/parse.yy @@ -391,7 +391,7 @@ argument_expression_list { ExprList *argList = dynamic_cast($1); if (argList == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); argList = new ExprList(@3); } argList->exprs.push_back($3); @@ -623,13 +623,13 @@ declaration_statement : declaration { if ($1 == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); $$ = NULL; } else if ($1->declSpecs->storageClass == SC_TYPEDEF) { for (unsigned int i = 0; i < $1->declarators.size(); ++i) { if ($1->declarators[i] == NULL) - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); else m->AddTypeDef($1->declarators[i]->name, $1->declarators[i]->type, @@ -789,7 +789,7 @@ init_declarator_list { std::vector *dl = (std::vector *)$1; if (dl == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); dl = new std::vector; } if ($3 != NULL) @@ -918,7 +918,7 @@ struct_declaration_list { std::vector *sdl = (std::vector *)$1; if (sdl == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); sdl = new std::vector; } if ($2 != NULL) @@ -1013,7 +1013,7 @@ struct_declarator_list { std::vector *sdl = (std::vector *)$1; if (sdl == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); sdl = new std::vector; } if ($3 != NULL) @@ -1087,7 +1087,7 @@ enumerator_list { std::vector *symList = $1; if (symList == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); symList = new std::vector; } if ($3 != NULL) @@ -1487,7 +1487,7 @@ initializer_list { ExprList *exprList = $1; if (exprList == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); exprList = new ExprList(@3); } exprList->exprs.push_back($3); @@ -1558,7 +1558,7 @@ statement_list { StmtList *sl = (StmtList *)$1; if (sl == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); sl = new StmtList(@2); } sl->Add($2); @@ -1670,7 +1670,7 @@ foreach_dimension_list { std::vector *dv = $1; if (dv == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); dv = new std::vector; } if ($3 != NULL) @@ -1708,7 +1708,7 @@ iteration_statement { std::vector *dims = $3; if (dims == NULL) { - Assert(m->errorCount > 0); + AssertPos(@3, m->errorCount > 0); dims = new std::vector; } for (unsigned int i = 0; i < dims->size(); ++i) @@ -1718,7 +1718,7 @@ iteration_statement { std::vector *dims = $3; if (dims == NULL) { - Assert(m->errorCount > 0); + AssertPos(@3, m->errorCount > 0); dims = new std::vector; } @@ -1736,7 +1736,7 @@ iteration_statement { std::vector *dims = $3; if (dims == NULL) { - Assert(m->errorCount > 0); + AssertPos(@3, m->errorCount > 0); dims = new std::vector; } @@ -1747,7 +1747,7 @@ iteration_statement { std::vector *dims = $3; if (dims == NULL) { - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); dims = new std::vector; } @@ -1861,7 +1861,7 @@ function_definition $2->InitFromDeclSpecs($1); const FunctionType *funcType = CastType($2->type); if (funcType == NULL) - Assert(m->errorCount > 0); + AssertPos(@1, m->errorCount > 0); else { Stmt *code = $4; if (code == NULL) code = new StmtList(@4); @@ -2010,7 +2010,7 @@ lAddFunctionParams(Declarator *decl) { m->symbolTable->PushScope(); if (decl == NULL) { - Assert(m->errorCount > 0); + AssertPos(decl->pos, m->errorCount > 0); return; } @@ -2018,7 +2018,7 @@ lAddFunctionParams(Declarator *decl) { while (decl->kind != DK_FUNCTION && decl->child != NULL) decl = decl->child; if (decl->kind != DK_FUNCTION) { - Assert(m->errorCount > 0); + AssertPos(decl->pos, m->errorCount > 0); return; } @@ -2028,14 +2028,14 @@ lAddFunctionParams(Declarator *decl) { Assert(pdecl != NULL && pdecl->declarators.size() == 1); Declarator *declarator = pdecl->declarators[0]; if (declarator == NULL) - Assert(m->errorCount > 0); + AssertPos(decl->pos, m->errorCount > 0); else { Symbol *sym = new Symbol(declarator->name, declarator->pos, declarator->type, declarator->storageClass); #ifndef NDEBUG bool ok = m->symbolTable->AddVariable(sym); if (ok == false) - Assert(m->errorCount > 0); + AssertPos(decl->pos, m->errorCount > 0); #else m->symbolTable->AddVariable(sym); #endif @@ -2189,7 +2189,7 @@ lFinalizeEnumeratorSymbols(std::vector &enums, if (enums[i]->constValue != NULL) { /* Already has a value, so first update nextVal with it. */ int count = enums[i]->constValue->AsUInt32(&nextVal); - Assert(count == 1); + AssertPos(enums[i]->pos, count == 1); ++nextVal; /* When the source file as being parsed, the ConstExpr for any @@ -2202,7 +2202,7 @@ lFinalizeEnumeratorSymbols(std::vector &enums, enums[i]->pos); castExpr = Optimize(castExpr); enums[i]->constValue = dynamic_cast(castExpr); - Assert(enums[i]->constValue != NULL); + AssertPos(enums[i]->pos, enums[i]->constValue != NULL); } else { enums[i]->constValue = new ConstExpr(enumType, nextVal++, diff --git a/stmt.cpp b/stmt.cpp index bcc57f4b..6a6f58e5 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -140,7 +140,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const { for (unsigned int i = 0; i < vars.size(); ++i) { Symbol *sym = vars[i].sym; - Assert(sym != NULL); + AssertPos(pos, sym != NULL); if (sym->type == NULL) continue; Expr *initExpr = vars[i].init; @@ -191,7 +191,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const { llvm::Type *llvmType = sym->type->LLVMType(g->ctx); if (llvmType == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -478,12 +478,12 @@ IfStmt::emitMaskedTrueAndFalse(FunctionEmitContext *ctx, llvm::Value *oldMask, lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements"); // under varying control flow,, returns can't stop instruction // emission, so this better be non-NULL... - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(ctx->GetDebugPos(), ctx->GetCurrentBasicBlock()); } if (falseStmts) { ctx->SetInternalMaskAndNot(oldMask, test); lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements"); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(ctx->GetDebugPos(), ctx->GetCurrentBasicBlock()); } } @@ -564,7 +564,7 @@ IfStmt::emitVaryingIf(FunctionEmitContext *ctx, llvm::Value *ltest) const { (costIsAcceptable || g->opt.disableCoherentControlFlow)) { ctx->StartVaryingIf(oldMask); emitMaskedTrueAndFalse(ctx, oldMask, ltest); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->EndIf(); } else { @@ -587,7 +587,7 @@ IfStmt::emitMaskAllOn(FunctionEmitContext *ctx, llvm::Value *ltest, // compiler see what's going on so that subsequent optimizations for // code emitted here can operate with the knowledge that the mask is // definitely all on (until it modifies the mask itself). - Assert(!g->opt.disableCoherentControlFlow); + AssertPos(pos, !g->opt.disableCoherentControlFlow); if (!g->opt.disableMaskAllOnOptimizations) ctx->SetInternalMask(LLVMMaskAllOn); llvm::Value *oldFunctionMask = ctx->GetFunctionMask(); @@ -637,7 +637,7 @@ IfStmt::emitMaskAllOn(FunctionEmitContext *ctx, llvm::Value *ltest, emitMaskedTrueAndFalse(ctx, LLVMMaskAllOn, ltest); // In this case, return/break/continue isn't allowed to jump and end // emission. - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->EndIf(); ctx->BranchInst(bDone); @@ -666,7 +666,7 @@ IfStmt::emitMaskMixed(FunctionEmitContext *ctx, llvm::Value *oldMask, // Emit statements for true ctx->SetCurrentBasicBlock(bRunTrue); lEmitIfStatements(ctx, trueStmts, "if: expr mixed, true statements"); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->BranchInst(bNext); ctx->SetCurrentBasicBlock(bNext); } @@ -683,7 +683,7 @@ IfStmt::emitMaskMixed(FunctionEmitContext *ctx, llvm::Value *oldMask, // Emit code for false ctx->SetCurrentBasicBlock(bRunFalse); lEmitIfStatements(ctx, falseStmts, "if: expr mixed, false statements"); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->BranchInst(bNext); ctx->SetCurrentBasicBlock(bNext); } @@ -837,7 +837,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetFunctionMask(LLVMMaskAllOn); if (bodyStmts) bodyStmts->EmitCode(ctx); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->SetFunctionMask(oldFunctionMask); ctx->BranchInst(btest); @@ -845,7 +845,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetCurrentBasicBlock(bMixed); if (bodyStmts) bodyStmts->EmitCode(ctx); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->BranchInst(btest); } else { @@ -986,7 +986,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { // it and then jump into the loop test code. (Also start a new scope // since the initiailizer may be a declaration statement). if (init) { - Assert(dynamic_cast(init) == NULL); + AssertPos(pos, dynamic_cast(init) == NULL); ctx->StartScope(); init->EmitCode(ctx); } @@ -1015,7 +1015,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { if (doCoherentCheck) Warning(test->pos, "Uniform condition supplied to cfor/cwhile " "statement."); - Assert(ltest->getType() == LLVMTypes::BoolType); + AssertPos(pos, ltest->getType() == LLVMTypes::BoolType); ctx->BranchInst(bloop, bexit, ltest); } else { @@ -1051,7 +1051,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetFunctionMask(LLVMMaskAllOn); if (stmts) stmts->EmitCode(ctx); - Assert(ctx->GetCurrentBasicBlock()); + AssertPos(pos, ctx->GetCurrentBasicBlock()); ctx->SetFunctionMask(oldFunctionMask); ctx->BranchInst(bstep); @@ -1364,8 +1364,8 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetFunctionMask(LLVMMaskAllOn); // This should be caught during typechecking - Assert(startExprs.size() == dimVariables.size() && - endExprs.size() == dimVariables.size()); + AssertPos(pos, startExprs.size() == dimVariables.size() && + endExprs.size() == dimVariables.size()); int nDims = (int)dimVariables.size(); /////////////////////////////////////////////////////////////////////// @@ -1704,7 +1704,7 @@ ForeachStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetContinueTarget(bbFullBodyContinue); ctx->AddInstrumentationPoint("foreach loop body (all on)"); stmts->EmitCode(ctx); - Assert(ctx->GetCurrentBasicBlock() != NULL); + AssertPos(pos, ctx->GetCurrentBasicBlock() != NULL); ctx->BranchInst(bbFullBodyContinue); } ctx->SetCurrentBasicBlock(bbFullBodyContinue); { @@ -2094,7 +2094,7 @@ SwitchStmt::EmitCode(FunctionEmitContext *ctx) const { const Type *type; if (expr == NULL || ((type = expr->GetType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -2112,7 +2112,7 @@ SwitchStmt::EmitCode(FunctionEmitContext *ctx) const { llvm::Value *exprValue = expr->GetValue(ctx); if (exprValue == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } @@ -2342,7 +2342,7 @@ LabeledStmt::LabeledStmt(const char *n, Stmt *s, SourcePos p) void LabeledStmt::EmitCode(FunctionEmitContext *ctx) const { llvm::BasicBlock *bblock = ctx->GetLabeledBasicBlock(name); - Assert(bblock != NULL); + AssertPos(pos, bblock != NULL); // End the current basic block with a jump to our basic block and then // set things up for emission to continue there. Note that the current @@ -2597,7 +2597,7 @@ PrintStmt::EmitCode(FunctionEmitContext *ctx) const { // Now we can emit code to call __do_print() llvm::Function *printFunc = m->module->getFunction("__do_print"); - Assert(printFunc); + AssertPos(pos, printFunc); llvm::Value *mask = ctx->GetFullMask(); // Set up the rest of the parameters to it @@ -2653,7 +2653,7 @@ AssertStmt::EmitCode(FunctionEmitContext *ctx) const { llvm::Function *assertFunc = isUniform ? m->module->getFunction("__do_assert_uniform") : m->module->getFunction("__do_assert_varying"); - Assert(assertFunc != NULL); + AssertPos(pos, assertFunc != NULL); char *errorString; if (asprintf(&errorString, "%s:%d:%d: Assertion failed: %s\n", @@ -2721,18 +2721,18 @@ DeleteStmt::EmitCode(FunctionEmitContext *ctx) const { const Type *exprType; if (expr == NULL || ((exprType = expr->GetType()) == NULL)) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } llvm::Value *exprValue = expr->GetValue(ctx); if (exprValue == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return; } // Typechecking should catch this - Assert(CastType(exprType) != NULL); + AssertPos(pos, CastType(exprType) != NULL); if (exprType->IsUniformType()) { // For deletion of a uniform pointer, we just need to cast the @@ -2741,7 +2741,7 @@ DeleteStmt::EmitCode(FunctionEmitContext *ctx) const { exprValue = ctx->BitCastInst(exprValue, LLVMTypes::VoidPointerType, "ptr_to_void"); llvm::Function *func = m->module->getFunction("__delete_uniform"); - Assert(func != NULL); + AssertPos(pos, func != NULL); ctx->CallInst(func, NULL, exprValue, ""); } @@ -2751,7 +2751,7 @@ DeleteStmt::EmitCode(FunctionEmitContext *ctx) const { // only need to extend to 64-bit values on 32-bit targets before // calling it. llvm::Function *func = m->module->getFunction("__delete_varying"); - Assert(func != NULL); + AssertPos(pos, func != NULL); if (g->target.is32Bit) exprValue = ctx->ZExtInst(exprValue, LLVMTypes::Int64VectorType, "ptr_to_64"); @@ -2804,7 +2804,7 @@ DeleteStmt::EstimateCost() const { Stmt * CreateForeachActiveStmt(Symbol *iterSym, Stmt *stmts, SourcePos pos) { if (iterSym == NULL) { - Assert(m->errorCount > 0); + AssertPos(pos, m->errorCount > 0); return NULL; } @@ -2831,11 +2831,11 @@ CreateForeachActiveStmt(Symbol *iterSym, Stmt *stmts, SourcePos pos) { // First, call __movmsk(__mask)) to get the mask as a set of bits. // This should be hoisted out of the loop Symbol *maskSym = m->symbolTable->LookupVariable("__mask"); - Assert(maskSym != NULL); + AssertPos(pos, maskSym != NULL); Expr *maskVecExpr = new SymbolExpr(maskSym, pos); std::vector mmFuns; m->symbolTable->LookupFunction("__movmsk", &mmFuns); - Assert(mmFuns.size() == (g->target.maskBitCount == 32 ? 2 : 1)); + AssertPos(pos, mmFuns.size() == (g->target.maskBitCount == 32 ? 2 : 1)); FunctionSymbolExpr *movmskFunc = new FunctionSymbolExpr("__movmsk", mmFuns, pos); ExprList *movmskArgs = new ExprList(maskVecExpr, pos); diff --git a/util.cpp b/util.cpp index 95da62f2..3c0de598 100644 --- a/util.cpp +++ b/util.cpp @@ -420,18 +420,41 @@ PerformanceWarning(SourcePos p, const char *fmt, ...) { } -void -FatalError(const char *file, int line, const char *message) { - fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message); +static void +lPrintBugText() { fprintf(stderr, "***\n" "*** Please file a bug report at https://github.com/ispc/ispc/issues\n" "*** (Including as much information as you can about how to " "reproduce this error).\n" "*** You have apparently encountered a bug in the compiler that we'd " "like to fix!\n***\n"); +} + + +void +FatalError(const char *file, int line, const char *message) { + fprintf(stderr, "%s(%d): FATAL ERROR: %s\n", file, line, message); + lPrintBugText(); abort(); } + +void +DoAssert(const char *file, int line, const char *expr) { + fprintf(stderr, "%s:%u: Assertion failed: \"%s\".\n", file, line, expr); + lPrintBugText(); + abort(); +} + + +void +DoAssertPos(SourcePos pos, const char *file, int line, const char *expr) { + Error(pos, "Assertion failed (%s:%u): \"%s\".", file, line, expr); + lPrintBugText(); + abort(); +} + + /////////////////////////////////////////////////////////////////////////// // http://en.wikipedia.org/wiki/Levenshtein_distance