From 4dcd76a388120fe75721c261a27191c413ea7b42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=B2=9C=EA=B5=90/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 8 Aug 2019 16:39:29 +0900 Subject: [PATCH] [moco-tf] Revise sanity check for squeeze dim (#6370) This commit would throw error for invalid squeeze dimension. Signed-off-by: Cheongyo Bahk --- compiler/moco-tf/src/Transforms/FixShapeTransform.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp b/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp index cdc5b0e..a372109 100644 --- a/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp +++ b/compiler/moco-tf/src/Transforms/FixShapeTransform.cpp @@ -1400,16 +1400,24 @@ bool fix_shape(moco::tf::TFSqueeze *node) uint32_t input_rank = input_tensor_shape.rank(); // Sanity check for 'squeeze_dims' - // TODO make lambda to hide these assertions - { - assert(squeeze_dims.size() < input_rank); + auto is_valid_squeeze_dims = [&squeeze_dims, &input_rank]() { + if (!(squeeze_dims.size() < input_rank)) + return false; for (auto squeeze_dim : squeeze_dims) { - assert(squeeze_dim >= -(int64_t)input_rank); - assert(squeeze_dim < (int64_t)input_rank); + if (!(squeeze_dim >= -(int64_t)input_rank)) + return false; + if (!(squeeze_dim < (int64_t)input_rank)) + return false; } + return true; }; + if (!is_valid_squeeze_dims()) + { + throw std::runtime_error("Fix shape for TFSqueeze: invalid squeeze dimension"); + } + // Resolve negative squeeze dimension for (auto squeeze_dim : squeeze_dims) { -- 2.7.4