From 9006d76bea52c6e96d95873a80fe1486ac40fceb Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 10 Jul 2020 17:14:13 +0800 Subject: [PATCH] fix(serialization): do not gate enum entries by macro GitOrigin-RevId: aa27ecbf21e3ba74ef64a9cd0d0c34f80a64918c --- src/core/include/megbrain/common.h | 7 +++++++ src/serialization/impl/serializer.cpp | 6 ++++-- .../include/megbrain/serialization/opr_load_dump.h | 10 +++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/core/include/megbrain/common.h b/src/core/include/megbrain/common.h index af32f04ef..49f5d9304 100644 --- a/src/core/include/megbrain/common.h +++ b/src/core/include/megbrain/common.h @@ -48,6 +48,13 @@ namespace mgb { //! warn if result of a function is not used #define MGB_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) +#if __cplusplus >= 201703L || __clang_major__ >= 4 +#define MGB_FALLTHRU [[fallthrough]]; +#elif __GNUC__ >= 7 +#define MGB_FALLTHRU __attribute__((fallthrough)); +#else +#define MGB_FALLTHRU +#endif /* ================ exception and assertion ================ */ diff --git a/src/serialization/impl/serializer.cpp b/src/serialization/impl/serializer.cpp index e5375d723..76d1495f2 100644 --- a/src/serialization/impl/serializer.cpp +++ b/src/serialization/impl/serializer.cpp @@ -53,10 +53,11 @@ bool GraphDumper::should_remove_in_dump(cg::OperatorNodeBase *opr) { std::unique_ptr GraphDumper::make(std::unique_ptr file, GraphDumpFormat format) { switch (format) { -#if MGB_ENABLE_FBS_SERIALIZATION case GraphDumpFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return make_fbs_dumper(std::move(file)); #endif + MGB_FALLTHRU default: mgb_throw(SerializationError, "unsupported serialization format requested"); @@ -66,10 +67,11 @@ std::unique_ptr GraphDumper::make(std::unique_ptr file, std::unique_ptr GraphLoader::make(std::unique_ptr file, GraphDumpFormat format) { switch (format) { -#if MGB_ENABLE_FBS_SERIALIZATION case GraphDumpFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return make_fbs_loader(std::move(file)); #endif + MGB_FALLTHRU default: mgb_throw(SerializationError, "unsupported serialization format requested"); diff --git a/src/serialization/include/megbrain/serialization/opr_load_dump.h b/src/serialization/include/megbrain/serialization/opr_load_dump.h index 7d8f4f5f6..84258ce2b 100644 --- a/src/serialization/include/megbrain/serialization/opr_load_dump.h +++ b/src/serialization/include/megbrain/serialization/opr_load_dump.h @@ -29,9 +29,7 @@ struct OperatorParamTraits; enum class SerializationFormat { RAW_POD, -#if MGB_ENABLE_FBS_SERIALIZATION FLATBUFFERS, -#endif }; //! context for serializing a single operator @@ -162,12 +160,12 @@ void OprDumpContext::write_param(const Param& p) { case SerializationFormat::RAW_POD: static_cast(this)->write_param(p); break; -#if MGB_ENABLE_FBS_SERIALIZATION case SerializationFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION static_cast(this)->write_param( p, fbs::SupportFlatBuffersSerialization{}); - break; #endif + break; } } @@ -322,11 +320,13 @@ Param OprLoadContext::read_param() { case SerializationFormat::RAW_POD: return static_cast(this) ->read_param(); -#if MGB_ENABLE_FBS_SERIALIZATION case SerializationFormat::FLATBUFFERS: +#if MGB_ENABLE_FBS_SERIALIZATION return static_cast(this) ->read_param( fbs::SupportFlatBuffersSerialization{}); +#else + mgb_trap(); #endif } mgb_assert(0); -- GitLab