!20783 Clean code warning for debug

Merge pull request !20783 from huanghui/clean_code_warning_723
This commit is contained in:
i-robot 2021-07-24 04:15:12 +00:00 committed by Gitee
commit 349d3f85cb
5 changed files with 24 additions and 23 deletions

View File

@ -40,8 +40,8 @@ void Compute(const ComputeParams<T> *params, const size_t start, const size_t en
}
offset += index * out_strides->at(j) * params->unit_size_;
}
auto ret =
memcpy_s(x + offset, params->x_mem_size_, updates + params->unit_size_ * i, params->unit_size_ * sizeof(T));
auto ret = memcpy_s(x + offset, params->x_mem_size_ - offset, updates + params->unit_size_ * i,
params->unit_size_ * sizeof(T));
if (ret != 0) {
MS_LOG(EXCEPTION) << "memcpy_s error, errorno" << ret;
}

View File

@ -33,10 +33,8 @@
#include "debug/common.h"
namespace mindspore {
// namespace to support debug utils
namespace draw {
namespace {
// Only for ValueNode
std::string ValueType(const ValueNodePtr &node) {
@ -44,7 +42,7 @@ std::string ValueType(const ValueNodePtr &node) {
return "";
}
auto v = node->value();
MS_EXCEPTION_IF_NULL(v);
return v->type_name();
}
@ -230,7 +228,7 @@ void DrawUserFuncGraph(const std::string &, const FuncGraphPtr &) {
}
#endif
std::string Graphviz::Shape(AnfNodePtr node) {
std::string Graphviz::Shape(const AnfNodePtr &node) {
if (node == nullptr) {
return "";
}
@ -302,7 +300,7 @@ void BaseDigraph::Tail(const FuncGraphPtr &func_graph) {
buffer_ << "node" << func_graph->get_return() << "_" << 0;
}
void BaseDigraph::Edge(AnfNodePtr start, FuncGraphPtr end, int id_start) {
void BaseDigraph::Edge(const AnfNodePtr &start, const FuncGraphPtr &end, int id_start) {
Head(start, id_start);
buffer_ << "->";
Tail(end);
@ -521,7 +519,7 @@ static void DrawCNode(Graphviz *const graph_obj, const CNodePtr &node) {
graph_obj->buffer() << "</table>>,";
}
void Digraph::Node(AnfNodePtr node, int id) {
void Digraph::Node(const AnfNodePtr &node, int id) {
if (node == nullptr) {
return;
}
@ -558,7 +556,7 @@ void Digraph::Node(AnfNodePtr node, int id) {
buffer_ << "]" << std::endl;
}
void Digraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
void Digraph::Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int id_start) {
if (start == nullptr || end == nullptr) {
return;
}
@ -591,7 +589,7 @@ ModelDigraph::~ModelDigraph() {
}
}
std::string ModelDigraph::Shape(AnfNodePtr node) {
std::string ModelDigraph::Shape(const AnfNodePtr &node) {
if (node == nullptr) {
return "";
}
@ -611,7 +609,7 @@ std::string ModelDigraph::Shape(AnfNodePtr node) {
return "plaintext";
}
void ModelDigraph::Node(AnfNodePtr node, int id) {
void ModelDigraph::Node(const AnfNodePtr &node, int id) {
if (node == nullptr) {
return;
}
@ -644,7 +642,7 @@ void ModelDigraph::Node(AnfNodePtr node, int id) {
buffer_ << "]" << std::endl;
}
void ModelDigraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
void ModelDigraph::Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int id_start) {
if (start == nullptr || end == nullptr) {
return;
}

View File

@ -37,7 +37,7 @@ class Graphviz {
virtual void Start() {}
virtual void End() {}
virtual std::string Shape(AnfNodePtr node);
virtual std::string Shape(const AnfNodePtr &node);
std::string Color(const AnfNodePtr &node);
std::ostringstream &buffer() { return buffer_; }
std::ostringstream buffer_;
@ -54,12 +54,12 @@ class BaseDigraph : public Graphviz {
explicit BaseDigraph(const std::string &name) : Graphviz(name) {}
~BaseDigraph() override = default;
virtual void Node(AnfNodePtr node, int id = 0) = 0;
virtual void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) = 0;
virtual void Node(const AnfNodePtr &node, int id = 0) = 0;
virtual void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) = 0;
void Start() override;
void End() override;
virtual void Edge(AnfNodePtr start, FuncGraphPtr end, int id_start);
virtual void Edge(const AnfNodePtr &start, const FuncGraphPtr &end, int id_start);
void FuncGraphParameters(const FuncGraphPtr &key);
void SubGraph(const FuncGraphPtr &key, const std::shared_ptr<BaseDigraph> &gsub);
@ -77,8 +77,8 @@ class Digraph : public BaseDigraph {
explicit Digraph(const std::string &name) : BaseDigraph(name) {}
~Digraph() override;
void Node(AnfNodePtr node, int id = 0) override;
void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) override;
void Node(const AnfNodePtr &node, int id = 0) override;
void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) override;
};
class ModelDigraph : public BaseDigraph {
@ -87,9 +87,9 @@ class ModelDigraph : public BaseDigraph {
explicit ModelDigraph(const std::string &name) : BaseDigraph(name) {}
~ModelDigraph() override;
std::string Shape(AnfNodePtr node) override;
void Node(AnfNodePtr node, int id = 0) override;
void Edge(AnfNodePtr start, AnfNodePtr end, int idx, int idx_start = 0) override;
std::string Shape(const AnfNodePtr &node) override;
void Node(const AnfNodePtr &node, int id = 0) override;
void Edge(const AnfNodePtr &start, const AnfNodePtr &end, int idx, int idx_start = 0) override;
};
// API to draw

View File

@ -106,6 +106,7 @@ static irpb::DataType GetNumberDataType(const TypePtr &type) {
}
void CheckIfValidType(const TypePtr &type) {
MS_EXCEPTION_IF_NULL(type);
if (type->isa<Problem>()) {
MS_LOG(WARNING) << "The type: " << type->type_name();
}

View File

@ -64,7 +64,7 @@ std::string GetAbstractStr(const abstract::AbstractBasePtr &abs) {
return oss.str();
}
std::string GetGraphParamString(const FuncGraphPtr &graph, abstract::AbstractBasePtrList args_spec_list) {
std::string GetGraphParamString(const FuncGraphPtr &graph, const abstract::AbstractBasePtrList &args_spec_list) {
MS_EXCEPTION_IF_NULL(graph);
std::ostringstream oss;
oss << "graph:" << graph->ToString() << " with args[";
@ -219,6 +219,8 @@ AbstractBasePtr AnalyzeFailExporter::GetNodeAbstract(const AnfNodePtr &node) {
}
AnfNodeConfigPtr AnalyzeFailExporter::GetFordwardConfig(const AnfNodeConfigPtr &cfg) {
MS_EXCEPTION_IF_NULL(cfg);
MS_EXCEPTION_IF_NULL(engine_);
AnfNodeConfigPtr cur_cfg = cfg;
auto iter = engine_->anfnode_config_map().find(cur_cfg);
while (iter != engine_->anfnode_config_map().end()) {
@ -419,7 +421,7 @@ void GetEvalStackInfo(std::ostringstream &oss) {
std::string last_location_info = "";
for (size_t i = 0; i < stack.size(); ++i) {
auto node_config = stack[i];
MS_EXCEPTION_IF_NULL(node_config);
auto cnode = dyn_cast<CNode>(node_config->node());
if (cnode == nullptr) {
MS_LOG(DEBUG) << "CNode of elements[" << i << "] is nullptr.";