diff options
Diffstat (limited to 'source/slang/slang-ir-specialize-dispatch.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-dispatch.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/source/slang/slang-ir-specialize-dispatch.cpp b/source/slang/slang-ir-specialize-dispatch.cpp index eac5287e5..bcd7b494f 100644 --- a/source/slang/slang-ir-specialize-dispatch.cpp +++ b/source/slang/slang-ir-specialize-dispatch.cpp @@ -123,14 +123,14 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext, // the witness table sequential ID passed in. builder->setInsertInto(newDispatchFunc); - + if (witnessTables.getCount() == 1) { // If there is only 1 case, no switch statement is necessary. builder->setInsertInto(newBlock); builder->emitBranch(defaultBlock); } - else + else if (witnessTables.getCount() > 1) { auto breakBlock = builder->emitBlock(); builder->setInsertInto(breakBlock); @@ -144,6 +144,21 @@ IRFunc* specializeDispatchFunction(SharedGenericsLoweringContext* sharedContext, caseBlocks.getCount(), caseBlocks.getBuffer()); } + else + { + // We have no witness tables that implements this interface. + // Just return a default value. + builder->setInsertInto(newBlock); + if (callInst->getDataType()->getOp() == kIROp_VoidType) + { + builder->emitReturn(); + } + else + { + auto defaultValue = builder->emitConstructorInst(callInst->getDataType(), 0, nullptr); + builder->emitReturn(defaultValue); + } + } // Remove old implementation. dispatchFunc->replaceUsesWith(newDispatchFunc); dispatchFunc->removeAndDeallocate(); |
