From 449d31e0b5bfe27c83cde981bb40876a9183efa7 Mon Sep 17 00:00:00 2001 From: lianliguang Date: Fri, 14 Jan 2022 15:39:39 +0800 Subject: [PATCH] fix code check --- .jenkins/check/config/filter_cppcheck.txt | 1 + .../ccsrc/frontend/operator/ops_front_infer_function.cc | 2 +- mindspore/ccsrc/pipeline/jit/resource.h | 6 +++--- .../pipeline/jit/static_analysis/async_eval_result.h | 6 +++--- .../ccsrc/pipeline/jit/static_analysis/auto_monad.cc | 1 - mindspore/ccsrc/pipeline/jit/static_analysis/evaluator.h | 4 ++-- mindspore/ccsrc/pipeline/jit/static_analysis/prim.h | 8 ++++---- .../ccsrc/pipeline/jit/static_analysis/stack_frame.h | 5 ++--- .../ccsrc/pipeline/jit/static_analysis/static_analysis.h | 4 ++-- mindspore/ccsrc/pybind_api/ir/primitive_py.h | 4 ++-- mindspore/ccsrc/vm/backend.cc | 2 +- mindspore/ccsrc/vm/vm.cc | 2 +- mindspore/core/abstract/abstract_function.h | 9 +++++---- mindspore/core/abstract/abstract_value.h | 2 +- mindspore/core/abstract/dshape.h | 6 +++--- mindspore/core/ops/audio_spectrogram.cc | 2 +- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.jenkins/check/config/filter_cppcheck.txt b/.jenkins/check/config/filter_cppcheck.txt index 4c69e10474d..3c5e57e316e 100644 --- a/.jenkins/check/config/filter_cppcheck.txt +++ b/.jenkins/check/config/filter_cppcheck.txt @@ -24,6 +24,7 @@ "mindspore/mindspore/ccsrc/runtime/hccl_adapter/hccl_adapter.cc" "useStlAlgorithm" "mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/cast_gpu_kernel.cc" "unknownMacro" "mindspore/mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc" "nullPointerArithmeticRedundantCheck" +"mindspore/mindspore/ccsrc/pipeline/jit/static_analysis/auto_monad.cc" "containerOutOfBounds" # MindData "mindspore/mindspore/ccsrc/minddata/dataset/engine/dataset_iterator.cc" "useStlAlgorithm" diff --git a/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc index e11ab11d2fd..82369fa76b0 100644 --- a/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc +++ b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc @@ -830,7 +830,7 @@ REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(J, prim::kPrimJ, InferImplJ, nullptr); REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(Shard, prim::kPrimShard, InferImplShard, nullptr); REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(BroadcastGradientArgs, prim::kPrimBroadcastGradientArgs, InferImplBroadcastGradientArgs, nullptr); -REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(MakeSiice, prim::kPrimMakeSlice, InferImplMakeSlice, nullptr); +REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(MakeSlice, prim::kPrimMakeSlice, InferImplMakeSlice, nullptr); REGISTER_PRIMITIVE_FRONT_EVAL_IMPL(SliceGetItem, prim::kPrimSliceGetItem, InferImplSliceGetItem, nullptr); } // namespace abstract } // namespace mindspore diff --git a/mindspore/ccsrc/pipeline/jit/resource.h b/mindspore/ccsrc/pipeline/jit/resource.h index acd92a4e9aa..5b5fe2a9d98 100644 --- a/mindspore/ccsrc/pipeline/jit/resource.h +++ b/mindspore/ccsrc/pipeline/jit/resource.h @@ -84,9 +84,9 @@ class Resource : public ResourceBase { loop_size_ = size; } void set_is_load(bool flag) { is_load_ = flag; } - bool is_load() { return is_load_; } - bool vm_loop_flag() { return vm_loop_flag_; } - int64_t loop_size() { return loop_size_; } + bool is_load() const { return is_load_; } + bool vm_loop_flag() const { return vm_loop_flag_; } + int64_t loop_size() const { return loop_size_; } void set_layout_map(const LayoutMap &layout_map) { layout_map_ = layout_map; } const LayoutMap &get_layout_map() const { return layout_map_; } diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h index f3d9c2b8a1a..21a08ad0d7c 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/async_eval_result.h @@ -295,7 +295,7 @@ class AsyncInferTask { static AsyncInferTaskPtr MakeShared(const AsyncAbstractPtr &abstract, const std::string &thread = "") { std::string thread_id = thread; if (thread_id == "") { - thread_id = AnalysisSchedule::GetInstance().thread_id(); + thread_id = AnalysisSchedule::thread_id(); } MS_EXCEPTION_IF_NULL(abstract); auto ret = std::make_shared(thread_id, abstract); @@ -388,10 +388,10 @@ class EvaluatorCacheMgr { ~EvaluatorCacheMgr() = default; void Clear() { eval_result_cache_.clear(); } - const EvalResultCache &GetCache() { return eval_result_cache_; } + const EvalResultCache &GetCache() const { return eval_result_cache_; } EvalResultPtr GetValue(const AbstractBasePtrList &key) { return eval_result_cache_.get(key); } void SetValue(const AbstractBasePtrList &key, const EvalResultPtr &arg) { eval_result_cache_.set(key, arg); } - size_t GetSize() { return eval_result_cache_.size(); } + size_t GetSize() const { return eval_result_cache_.size(); } private: EvalResultCache eval_result_cache_; diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/auto_monad.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/auto_monad.cc index 3d124b7913e..1a8d6d6a817 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/auto_monad.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/auto_monad.cc @@ -616,7 +616,6 @@ class SideEffectFinder { if (IsPrimitiveEquals(prim, prim::kPrimMakeTuple)) { if (tuple_indexes->empty()) { MS_LOG(EXCEPTION) << "Unexpected make_tuple: " << cnode->DebugString(2); - return {EffectInfo::kDetected, false, false, false}; } // Pop out tuple index. auto top_index = tuple_indexes->top(); diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/evaluator.h b/mindspore/ccsrc/pipeline/jit/static_analysis/evaluator.h index 3b767f16035..427540dfc94 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/evaluator.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/evaluator.h @@ -73,7 +73,7 @@ class Evaluator : public Base { return nullptr; } - auto is_abstract = std::any_of(args_spec_list.begin(), args_spec_list.end(), [](auto &arg) { + auto is_abstract = std::any_of(args_spec_list.begin(), args_spec_list.end(), [](auto &arg) -> bool { if (arg->BuildType()->type_id() == kObjectTypeUndeterminedType) { return true; } @@ -95,7 +95,7 @@ class Evaluator : public Base { EvaluatorCacheMgrPtr evaluator_cache_mgr() const { return evaluator_cache_mgr_; } EvaluatorAttrCachePtr attr_cache() const { return attr_cache_; } - std::recursive_timed_mutex &eval_lock() { return eval_lock_; } + const std::recursive_timed_mutex &eval_lock() { return eval_lock_; } protected: std::string identifier_; diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h index b6f8978fba3..352c0718218 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h @@ -89,7 +89,7 @@ class UniformPrimEvaluator final : public TrivialPrimEvaluator { } } } - ~UniformPrimEvaluator() override = default; + ~UniformPrimEvaluator() override { impl_ = nullptr; }; MS_DECLARE_PARENT(UniformPrimEvaluator, TrivialPrimEvaluator); EvalResultPtr EvalPrim(const AnalysisEnginePtr &engine, const AbstractBasePtrList &args) override; @@ -122,7 +122,7 @@ class DoSignatureEvaluator final : public Evaluator { ~DoSignatureEvaluator() override = default; MS_DECLARE_PARENT(DoSignatureEvaluator, Evaluator); EvalResultPtr Run(AnalysisEnginePtr engine, const ConfigPtrList &argrefs, - const AnfNodeConfigPtr &out_config = nullptr) override; + const AnfNodeConfigPtr &out_config) override; EvalResultPtr Eval(AnalysisEnginePtr, const AbstractBasePtrList &, const AnfNodeConfigPtr &) override { MS_LOG(EXCEPTION) << "Eval() should not be called, Run() method should be called"; @@ -138,7 +138,7 @@ class UnpackGraphEvaluator final : public Evaluator { ~UnpackGraphEvaluator() override = default; MS_DECLARE_PARENT(UnpackGraphEvaluator, Evaluator); EvalResultPtr Run(AnalysisEnginePtr engine, const ConfigPtrList &argrefs, - const AnfNodeConfigPtr &out_config = nullptr) override; + const AnfNodeConfigPtr &out_config) override; EvalResultPtr Eval(AnalysisEnginePtr, const AbstractBasePtrList &, const AnfNodeConfigPtr &) override { MS_LOG(EXCEPTION) << "Eval() should not be called, Run() method should be called"; @@ -155,7 +155,7 @@ class MixedPrecisionCastEvaluator final : public Evaluator { ~MixedPrecisionCastEvaluator() override = default; MS_DECLARE_PARENT(MixedPrecisionCastEvaluator, Evaluator); EvalResultPtr Run(AnalysisEnginePtr engine, const ConfigPtrList &argrefs, - const AnfNodeConfigPtr &out_config = nullptr) override; + const AnfNodeConfigPtr &out_config) override; EvalResultPtr Eval(AnalysisEnginePtr, const AbstractBasePtrList &, const AnfNodeConfigPtr &) override { MS_LOG(EXCEPTION) << "Eval() should not be called, Run() method should be called"; diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/stack_frame.h b/mindspore/ccsrc/pipeline/jit/static_analysis/stack_frame.h index d47ab7baa15..d71b4baf4fe 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/stack_frame.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/stack_frame.h @@ -27,7 +27,6 @@ namespace mindspore { namespace abstract { class StackFrame; -using StackFramePtr = std::shared_ptr; using EvaluatorWeakPtr = std::weak_ptr; using BaseFuncGraphEvaluatorPtr = std::shared_ptr; @@ -65,7 +64,7 @@ class StackFrame final : public Base { // Return back from branch func graph. void Back(const AnalysisEnginePtr &engine, const StackFramePtr &last_stack_frame, const EvalResultPtr &eval_result); - bool Done() { return done_; } + bool Done() const { return done_; } AnfNodePtr &CurrentNode() { if (slot_index_ >= node_slots_.size()) { @@ -92,7 +91,7 @@ class StackFrame final : public Base { AnalysisContextPtr current_context() const { return current_context_; } AnalysisContextPtr parent_context() const { return parent_context_; } - const AbstractBasePtrList &args_abs_list() { return args_abs_list_; } + const AbstractBasePtrList &args_abs_list() const { return args_abs_list_; } void set_args_abs_list(const AbstractBasePtrList &&args_abs_list) { args_abs_list_ = args_abs_list; } std::string ToString() const override { diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h index 9cd12aa1a03..cc9e05af903 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/static_analysis.h @@ -65,7 +65,7 @@ using AttrValueMapPtr = std::shared_ptr; // the class to save evaluated result: abstract value and modified attribute class EvalResult : public Base { public: - EvalResult(AbstractBasePtr abs, AttrValueMapPtr attr) : abstract_(abs), attribute_(attr) {} + EvalResult(const AbstractBasePtr &abs, const AttrValueMapPtr &attr) : abstract_(abs), attribute_(attr) {} ~EvalResult() override = default; MS_DECLARE_PARENT(EvalResult, Base); const AbstractBasePtr &abstract() { return abstract_; } @@ -292,7 +292,7 @@ class AnalysisEngine : public std::enable_shared_from_this { forward_count_ = 0; enable_recursive_eval_ = (common::GetEnv("MS_DEV_RECURSIVE_EVAL") == "1"); } - ~AnalysisEngine() = default; + virtual ~AnalysisEngine() = default; // func_graph: The func_graph to analyze. // args_spec_list: The abstracted arguments for the func_graph. Must be a tuple of AbstractBase. diff --git a/mindspore/ccsrc/pybind_api/ir/primitive_py.h b/mindspore/ccsrc/pybind_api/ir/primitive_py.h index ab0d2f38239..077a67c4e24 100644 --- a/mindspore/ccsrc/pybind_api/ir/primitive_py.h +++ b/mindspore/ccsrc/pybind_api/ir/primitive_py.h @@ -71,7 +71,7 @@ class PrimitivePy : public Primitive { py::dict RunInfer(const py::tuple &args); void RunCheck(const py::tuple &args); py::object RunInferValue(const py::tuple &args); - bool HasPyObj() { return python_obj_.operator bool(); } + bool HasPyObj() const { return python_obj_.operator bool(); } PrimitivePtr Clone() override; PrimitivePyAdapterPtr adapter() const { return adapter_; } void set_bprop_cls_name(const std::string &name) { bprop_cls_name_ = name; } @@ -102,7 +102,7 @@ class PrimitivePyAdapter { void set_hook(const py::function &hook); void set_instance_name(const std::string &s); void set_attached_primitive(const PrimitivePyPtr &prim); - PrimitivePyPtr attached_primitive() { return attached_primitive_.lock(); } + PrimitivePyPtr attached_primitive() const { return attached_primitive_.lock(); } std::string name() const { return name_; } void set_name(const std::string &name) { name_ = name; } const bool parse_info_ = true; diff --git a/mindspore/ccsrc/vm/backend.cc b/mindspore/ccsrc/vm/backend.cc index a315b107ac1..fa370efb222 100644 --- a/mindspore/ccsrc/vm/backend.cc +++ b/mindspore/ccsrc/vm/backend.cc @@ -1135,7 +1135,7 @@ std::unique_ptr MindRTBackend::ConstructGraphCompilerInfo(con parser->Parse(control_nodes_, graphs, device_contexts, root_graph, func_graph_to_kernel_graphs); runtime::KernelMapPosition outputs_order; - size_t outputs_num = 0; + size_t outputs_num; const auto &root_output = AnfAlgo::VisitKernelWithReturnType(root_graph->output(), 0, false, {prim::kPrimTupleGetItem}).first; size_t position = 0; diff --git a/mindspore/ccsrc/vm/vm.cc b/mindspore/ccsrc/vm/vm.cc index fc5f92bd572..0a5572b5712 100644 --- a/mindspore/ccsrc/vm/vm.cc +++ b/mindspore/ccsrc/vm/vm.cc @@ -134,7 +134,7 @@ void FinalVM::Popsp() { int64_t sp = retsp_.top(); MS_LOG(DEBUG) << "Current sp:" << sp_ << ", before sp:" << sp << ", " << sp_ - sp; if (sp_ >= sp) { - Pop(sp_ - sp + 1); + Pop((sp_ - sp) + 1); retsp_.pop(); } else { MS_LOG(EXCEPTION) << "Stack point sp_:" << sp << " must be bigger than sp:" << sp_; diff --git a/mindspore/core/abstract/abstract_function.h b/mindspore/core/abstract/abstract_function.h index d1272a8da88..a4f29bc6295 100644 --- a/mindspore/core/abstract/abstract_function.h +++ b/mindspore/core/abstract/abstract_function.h @@ -268,14 +268,12 @@ class MS_CORE_API PartialAbstractClosure final : public AbstractFuncAtom { /// \brief Get the pre-provided arguments. /// /// \return The pre-provided arguments. - const AbstractBasePtrList &args() { return args_spec_list_; } - - ValuePtr RealBuildValue() const override { return fn_->BuildValue(); } + const AbstractBasePtrList &args() const { return args_spec_list_; } /// \brief Get the CNode this PartialAbstractClosure evaluated from. /// /// \return The CNode this PartialAbstractClosure evaluated from. - AnfNodePtr node() { return node_.lock(); } + AnfNodePtr node() const { return node_.lock(); } /// \brief Set the CNode this PartialAbstractClosure evaluated from. /// @@ -292,6 +290,9 @@ class MS_CORE_API PartialAbstractClosure final : public AbstractFuncAtom { std::string ToString() const override; + protected: + ValuePtr RealBuildValue() const override { return fn_->BuildValue(); } + private: AbstractFuncAtomPtr fn_; AbstractBasePtrList args_spec_list_; diff --git a/mindspore/core/abstract/abstract_value.h b/mindspore/core/abstract/abstract_value.h index 69db37f5a97..aa0ce432e20 100644 --- a/mindspore/core/abstract/abstract_value.h +++ b/mindspore/core/abstract/abstract_value.h @@ -147,7 +147,7 @@ class MS_CORE_API AbstractBase : public Base { /// \brief Set the function, which prints the debug info. /// /// \param[in] trace_node_provider The function. - static void set_trace_node_provider(TraceNodeProvider trace_node_provider) { + static void set_trace_node_provider(const TraceNodeProvider &trace_node_provider) { trace_node_provider_ = trace_node_provider; } diff --git a/mindspore/core/abstract/dshape.h b/mindspore/core/abstract/dshape.h index 23eaab02892..ed48d0b3af9 100644 --- a/mindspore/core/abstract/dshape.h +++ b/mindspore/core/abstract/dshape.h @@ -175,17 +175,17 @@ class MS_CORE_API Shape final : public BaseShape { /// \brief Get shape dimensions. /// /// \return Shape dimensions. - const ShapeVector &shape() { return shape_; } + const ShapeVector &shape() const { return shape_; } /// \brief Get minimum shape dimensions. /// /// \return Minimum shape dimensions. - const ShapeVector &min_shape() { return min_shape_; } + const ShapeVector &min_shape() const { return min_shape_; } /// \brief Get maximum shape dimensions. /// /// \return Maximum shape dimensions. - const ShapeVector &max_shape() { return max_shape_; } + const ShapeVector &max_shape() const { return max_shape_; } bool IsDynamic() const override { return std::any_of(shape_.begin(), shape_.end(), [](int64_t s) { return s < 0; }); diff --git a/mindspore/core/ops/audio_spectrogram.cc b/mindspore/core/ops/audio_spectrogram.cc index 447da90a91c..4bef1b78859 100644 --- a/mindspore/core/ops/audio_spectrogram.cc +++ b/mindspore/core/ops/audio_spectrogram.cc @@ -60,7 +60,7 @@ abstract::ShapePtr AudioSpectrogramInferShape(const PrimitivePtr &primitive, } auto stride_size = GetValue(primitive->GetAttr(kStride)); if (stride_size < 1) { - MS_LOG(ERROR) << "stride must be positive, now is " << stride_size; + MS_LOG(EXCEPTION) << "stride must be positive, now is " << stride_size; } std::vector infer_shape; infer_shape.push_back(input_shape[1]);