From da47ace885c5e4ffd3ff4927ae9801bfd9801d74 Mon Sep 17 00:00:00 2001 From: qiuhan Date: Thu, 23 Jul 2020 22:56:30 +0800 Subject: [PATCH 1/2] [Fix] avoid unexpected throw in AttrInitEntry avoid unexpected throw in AttrInitEntry, as discussed in #6093 --- include/tvm/ir/attrs.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/tvm/ir/attrs.h b/include/tvm/ir/attrs.h index 4cdf8c5cbe94..413321b0060c 100644 --- a/include/tvm/ir/attrs.h +++ b/include/tvm/ir/attrs.h @@ -337,6 +337,18 @@ struct AttrInitEntry { T* value_; // whether the value is missing. bool value_missing_{true}; + + AttrInitEntry() = default; + + AttrInitEntry(AttrInitEntry&& other) { + type_key_ = other.type_key_; + key_ = other.key_; + value_ = other.value_; + value_missing_ = other.value_missing_; + // avoid unexpected throw + other.value_missing_ = false; + } + // If the value is still missing in destruction time throw an error. ~AttrInitEntry() DMLC_THROW_EXCEPTION { if (value_missing_) { @@ -379,7 +391,7 @@ struct AttrInitEntry { } TSelf& describe(DMLC_ATTRIBUTE_UNUSED const char* str) { return *this; } }; - + // Template function to allow smart conversion // from Expr types into the constants. template @@ -463,7 +475,7 @@ class AttrInitVisitor { } else { opt.value_missing_ = true; } - return opt; + return std::move(opt); } private: From 823a887299aded5b8b173aa11cce1cb3bb0eb3d2 Mon Sep 17 00:00:00 2001 From: qiuhan Date: Mon, 3 Aug 2020 10:47:05 +0800 Subject: [PATCH 2/2] fix lint broken --- include/tvm/ir/attrs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/tvm/ir/attrs.h b/include/tvm/ir/attrs.h index 413321b0060c..d20ba4f95456 100644 --- a/include/tvm/ir/attrs.h +++ b/include/tvm/ir/attrs.h @@ -391,7 +391,7 @@ struct AttrInitEntry { } TSelf& describe(DMLC_ATTRIBUTE_UNUSED const char* str) { return *this; } }; - + // Template function to allow smart conversion // from Expr types into the constants. template