From 5e604a6f39ef8e8086702d41113ea78856804c99 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 11 May 2018 13:56:14 -0700 Subject: Cleanups around behavior when the compiler fails (#553) * Cleanups around behavior when the compiler fails * Add another case where we try to `noteInternalErrorLoc()` if an exception in thrown. This one is the in the logic for emitting an IR instruciton. This could be improved by adding another layer at the function level (as a catch-all for instructions with no location), but something is better than nothing. * Change a bunch of `assert()`s over to `SLANG_ASSERT()`s, so that we can theoretically take more control over them (e.g., make release builds with asserts enabled) * Some other small cleanups around the assertions we perform. In the survey I made, I didn't really see many obvious "smoking gun" cases where we could produce a significantly better error message for some of the unimplemented/unexpected paths, other than to actually implement the missing functionality. * fixup --- source/slang/lower-to-ir.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source/slang/lower-to-ir.cpp') diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 03d6ad321..81520abf5 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -168,7 +168,7 @@ struct LoweredValInfo BoundMemberInfo* getBoundMemberInfo() { - assert(flavor == Flavor::BoundMember); + SLANG_ASSERT(flavor == Flavor::BoundMember); return (BoundMemberInfo*)ext; } @@ -177,7 +177,7 @@ struct LoweredValInfo SubscriptInfo* getSubscriptInfo() { - assert(flavor == Flavor::Subscript); + SLANG_ASSERT(flavor == Flavor::Subscript); return (SubscriptInfo*)ext; } @@ -186,7 +186,7 @@ struct LoweredValInfo BoundSubscriptInfo* getBoundSubscriptInfo() { - assert(flavor == Flavor::BoundSubscript); + SLANG_ASSERT(flavor == Flavor::BoundSubscript); return (BoundSubscriptInfo*)ext; } @@ -195,7 +195,7 @@ struct LoweredValInfo SwizzledLValueInfo* getSwizzledLValueInfo() { - assert(flavor == Flavor::SwizzledLValue); + SLANG_ASSERT(flavor == Flavor::SwizzledLValue); return (SwizzledLValueInfo*)ext; } }; @@ -410,7 +410,7 @@ IROp getIntrinsicOp( auto nameText = getText(name); IROp op = findIROp(nameText.Buffer()); - assert(op != kIROp_Invalid); + SLANG_ASSERT(op != kIROp_Invalid); return op; } @@ -443,7 +443,7 @@ LoweredValInfo emitCompoundAssignOp( { auto builder = context->irBuilder; SLANG_UNREFERENCED_PARAMETER(argCount); - assert(argCount == 2); + SLANG_ASSERT(argCount == 2); auto leftPtr = args[0]; auto rightVal = args[1]; @@ -492,7 +492,7 @@ LoweredValInfo emitPreOp( { auto builder = context->irBuilder; SLANG_UNREFERENCED_PARAMETER(argCount); - assert(argCount == 1); + SLANG_ASSERT(argCount == 1); auto argPtr = args[0]; auto preVal = builder->emitLoad(argPtr); @@ -516,7 +516,7 @@ LoweredValInfo emitPostOp( { auto builder = context->irBuilder; SLANG_UNREFERENCED_PARAMETER(argCount); - assert(argCount == 1); + SLANG_ASSERT(argCount == 1); auto argPtr = args[0]; auto preVal = builder->emitLoad(argPtr); @@ -1709,7 +1709,7 @@ struct ExprLoweringVisitorBase : ExprVisitor // Now we can pass the address of the temporary variable // to the callee as the actual argument for the `in out` - assert(tempVar.flavor == LoweredValInfo::Flavor::Ptr); + SLANG_ASSERT(tempVar.flavor == LoweredValInfo::Flavor::Ptr); (*ioArgs).Add(tempVar.val); // Finally, after the call we will need @@ -3712,7 +3712,7 @@ struct DeclLoweringVisitor : DeclVisitor IRInst* fieldKeyInst = getSimpleVal(context, ensureDecl(context, fieldDecl)); auto fieldKey = as(fieldKeyInst); - assert(fieldKey); + SLANG_ASSERT(fieldKey); // Note: we lower the type of the field in the "sub" // context, so that any generic parameters that were @@ -4626,12 +4626,12 @@ struct DeclLoweringVisitor : DeclVisitor // to avoid emitting a bunch of extra definitions in the IR. auto primaryFuncDecl = dynamic_cast(primaryDecl); - assert(primaryFuncDecl); + SLANG_ASSERT(primaryFuncDecl); LoweredValInfo result = lowerFuncDecl(primaryFuncDecl); for (auto dd = primaryDecl->nextDecl; dd; dd = dd->nextDecl) { auto funcDecl = dynamic_cast(dd); - assert(funcDecl); + SLANG_ASSERT(funcDecl); lowerFuncDecl(funcDecl); } return result; -- cgit v1.2.3