Skip to content

Commit

Permalink
fix incorrect usages of std::move and other compile errors (#41045)
Browse files Browse the repository at this point in the history
* fix bug of std::move and others

* fix an compile error in debug mode

* fix wrong copy assignment operator

Signed-off-by: tiancaishaonvjituizi <[email protected]>

* reformat

Signed-off-by: tiancaishaonvjituizi <[email protected]>

* reformat

Signed-off-by: tiancaishaonvjituizi <[email protected]>

* fix ArrayRef constructor following llvm

* fix format

* fix conflict with master
  • Loading branch information
tiancaishaonvjituizi authored Apr 25, 2022
1 parent 3a0d7bf commit 05739d9
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/test/ctr_accessor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TableAccessorParameter gen_param() {
naive_param->add_weight_bounds(-10.0);
naive_param->add_weight_bounds(10.0);

return std::move(param);
return param;
}

TEST(downpour_feature_value_accessor_test, test_shrink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,7 @@ std::unique_ptr<paddle::framework::ir::Graph> BuildGraph(bool backward,
n->Var()->SetDataType(proto_dtype);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}

std::unordered_set<paddle::framework::ir::Node*> DistilGradNodes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ std::unique_ptr<Graph> BuildElementwiseListGraph(bool backward = false) {
n->Var()->SetDataType(proto::VarType::FP32);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}

std::unique_ptr<Graph> BuildElementwiseTreeGraph(bool backward = false) {
Expand Down Expand Up @@ -125,11 +121,7 @@ std::unique_ptr<Graph> BuildElementwiseTreeGraph(bool backward = false) {
n->Var()->SetDataType(proto::VarType::FP32);
}
}
#ifdef __clang__
return graph;
#else
return std::move(graph);
#endif
}

int TestMain(std::unique_ptr<Graph> graph, std::string prefix) {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/new_executor/interpretercore_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ std::map<int, std::list<int>> get_downstream_map(
VLOG(6) << "downstream count: " << downstream_map_count();
VLOG(6) << "downstream_map: " << std::endl << downstream_map_to_str();

return std::move(downstream);
return downstream;
}

std::map<int, std::list<int>> build_op_downstream_map(
Expand Down Expand Up @@ -995,7 +995,7 @@ std::map<int, std::list<int>> build_op_downstream_map(
std::ostream_iterator<int>(oss, " "));
VLOG(10) << oss.str();
}
return std::move(get_downstream_map(op2dependences, op_happens_before));
return get_downstream_map(op2dependences, op_happens_before);
}

} // namespace interpreter
Expand Down
6 changes: 6 additions & 0 deletions paddle/fluid/framework/var_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class VarDesc {
: desc_(other.desc_),
attrs_(other.attrs_),
original_id_(other.original_id_) {}
VarDesc &operator=(const VarDesc &other) {
desc_ = other.desc_;
attrs_ = other.attrs_;
original_id_ = other.original_id_;
return *this;
}

proto::VarDesc *Proto() { return &desc_; }

Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/utils/table_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string TablePrinter::PrintTable() {

AddRowDivider(ss);

return std::move(ss.str());
return ss.str();
}

TablePrinter::TablePrinter(const std::vector<std::string>& header) {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/platform/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ static std::map<uint64_t, ThreadEvents> DockHostEventRecorderHostPart() {
auto host_evt_sec = HostEventRecorder::GetInstance().GatherEvents();
EmulateEventPushAndPop(host_evt_sec, &thr_events);
EmulateCPURecordsAdd(host_evt_sec);
return std::move(thr_events);
return thr_events;
}

static void DockHostEventRecorderDevicePart(
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/api/lib/api_gen_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::unique_ptr<std::vector<phi::DenseTensor>> TensorToDenseTensor(
*std::dynamic_pointer_cast<phi::DenseTensor>(t.impl()));
}

return std::move(pt_tensors);
return pt_tensors;
}

std::shared_ptr<phi::SelectedRows> TensorToSelectedRows(const Tensor& tensor) {
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/api/lib/data_transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ std::unique_ptr<std::vector<phi::DenseTensor>> PrepareData(
}
}

return std::move(pt_tensors);
return pt_tensors;
}

} // namespace experimental
Expand Down
5 changes: 5 additions & 0 deletions paddle/phi/core/compat/arg_map_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ struct KernelSignature {

// TODO(chenweihang): add assign constructor to solve windows compile
// problem, remove it later
KernelSignature(const KernelSignature& other)
: name(other.name),
input_names(other.input_names),
attr_names(other.attr_names),
output_names(other.output_names) {}
KernelSignature& operator=(const KernelSignature& other) {
name = other.name;
input_names = other.input_names;
Expand Down
3 changes: 2 additions & 1 deletion paddle/phi/core/utils/type_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ template <typename BaseT>
TypeInfo<BaseT> TypeRegistry<BaseT>::RegisterType(const std::string& type) {
std::lock_guard<std::mutex> guard(mutex_);
assert(name_to_id_.find(type) == name_to_id_.end());
assert(names_.size() < std::numeric_limits<int8_t>::max());
assert(names_.size() < static_cast<decltype(names_.size())>(
std::numeric_limits<int8_t>::max()));
int8_t id = static_cast<int8_t>(names_.size());
names_.emplace_back(type);
name_to_id_[type] = id;
Expand Down
13 changes: 12 additions & 1 deletion paddle/utils/array_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ class ArrayRef {
template <size_t N>
/*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {}

/// Construct an ArrayRef from a std::initializer_list.
/// Construct an ArrayRef from a std::initializer_list.
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9
// Disable gcc's warning in this constructor as it generates an enormous
// amount
// of messages. Anyone using ArrayRef should already be aware of the fact that
// it does not do lifetime extension.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
#endif
/*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
: Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()),
Length(Vec.size()) {}
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9
#pragma GCC diagnostic pop
#endif

/// Construct an ArrayRef<const T*> from ArrayRef<T*>. This uses SFINAE to
/// ensure that only ArrayRefs of pointers can be converted.
Expand Down

0 comments on commit 05739d9

Please sign in to comment.