From ffbbcc7839588bdb3d40b0473c7965296e3e08d8 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Thu, 26 Oct 2023 15:08:00 +0200 Subject: [PATCH] cg: Fix triggering of an mlir assertion. --- lib/vast/CodeGen/CodeGenFunction.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vast/CodeGen/CodeGenFunction.cpp b/lib/vast/CodeGen/CodeGenFunction.cpp index 95bfb553e9..c9a82e0d2d 100644 --- a/lib/vast/CodeGen/CodeGenFunction.cpp +++ b/lib/vast/CodeGen/CodeGenFunction.cpp @@ -116,6 +116,9 @@ namespace vast::cg } operation get_last_effective_operation(auto &block) { + if (block.empty()) { + return {}; + } auto last = &block.back(); if (auto scope = mlir::dyn_cast< core::ScopeOp >(last)) { return get_last_effective_operation(scope.getBody().back()); @@ -130,7 +133,10 @@ namespace vast::cg auto &last_block = fn.getBody().back(); auto missing_return = [&] (auto &block) { if (codegen.has_insertion_block()) { - return block.empty() || !get_last_effective_operation(block)->template hasTrait< core::return_trait >(); + if (auto op = get_last_effective_operation(block)) { + return !op->template hasTrait< core::return_trait >(); + } + return true; } return false;