From cae70a9f0ecba8c004c59eb063da89250f947029 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Mon, 28 Mar 2022 21:06:22 +0800 Subject: [PATCH 1/8] fix bug of std::move and others --- paddle/fluid/distributed/test/ctr_accessor_test.cc | 2 +- .../framework/ir/fusion_group/code_generator_tester.cc | 4 ---- .../framework/ir/fusion_group/fusion_group_pass_tester.cc | 8 -------- .../fluid/framework/new_executor/interpretercore_util.cc | 4 ++-- paddle/fluid/framework/var_desc.h | 5 +++++ paddle/fluid/inference/utils/table_printer.cc | 2 +- paddle/fluid/platform/profiler.cc | 2 +- paddle/phi/api/lib/api_gen_utils.cc | 2 +- paddle/phi/api/lib/data_transform.cc | 2 +- paddle/phi/core/compat/arg_map_context.h | 7 ++++--- 10 files changed, 16 insertions(+), 22 deletions(-) diff --git a/paddle/fluid/distributed/test/ctr_accessor_test.cc b/paddle/fluid/distributed/test/ctr_accessor_test.cc index 835b1a361573d..c9f4f2ede40fa 100644 --- a/paddle/fluid/distributed/test/ctr_accessor_test.cc +++ b/paddle/fluid/distributed/test/ctr_accessor_test.cc @@ -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) { diff --git a/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc b/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc index f671e0ae7690a..7b6bbf0251001 100644 --- a/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc +++ b/paddle/fluid/framework/ir/fusion_group/code_generator_tester.cc @@ -420,11 +420,7 @@ std::unique_ptr BuildGraph(bool backward, n->Var()->SetDataType(proto_dtype); } } -#ifdef __clang__ return graph; -#else - return std::move(graph); -#endif } std::unordered_set DistilGradNodes( diff --git a/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc b/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc index d14c7e433bd08..db22c03a7d9c0 100644 --- a/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc +++ b/paddle/fluid/framework/ir/fusion_group/fusion_group_pass_tester.cc @@ -63,11 +63,7 @@ std::unique_ptr BuildElementwiseListGraph(bool backward = false) { n->Var()->SetDataType(proto::VarType::FP32); } } -#ifdef __clang__ return graph; -#else - return std::move(graph); -#endif } std::unique_ptr BuildElementwiseTreeGraph(bool backward = false) { @@ -125,11 +121,7 @@ std::unique_ptr 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, std::string prefix) { diff --git a/paddle/fluid/framework/new_executor/interpretercore_util.cc b/paddle/fluid/framework/new_executor/interpretercore_util.cc index a045d6c7f4a65..0e128836a3ed7 100644 --- a/paddle/fluid/framework/new_executor/interpretercore_util.cc +++ b/paddle/fluid/framework/new_executor/interpretercore_util.cc @@ -581,7 +581,7 @@ std::map> get_downstream_map( result[dep_op].push_back(op); } } - return std::move(result); + return result; } std::map> build_op_downstream_map( @@ -643,7 +643,7 @@ std::map> build_op_downstream_map( } } } - return std::move(get_downstream_map(op2dependences)); + return get_downstream_map(op2dependences); } } // namespace interpreter diff --git a/paddle/fluid/framework/var_desc.h b/paddle/fluid/framework/var_desc.h index a20ef58f9c95f..b79245c45f792 100644 --- a/paddle/fluid/framework/var_desc.h +++ b/paddle/fluid/framework/var_desc.h @@ -74,6 +74,11 @@ class VarDesc { : desc_(other.desc_), attrs_(other.attrs_), original_id_(other.original_id_) {} + VarDesc& operator=(VarDesc other) { + using std::swap; + swap(*this, other); + return *this; + } proto::VarDesc *Proto() { return &desc_; } diff --git a/paddle/fluid/inference/utils/table_printer.cc b/paddle/fluid/inference/utils/table_printer.cc index bd19320cbe647..628465c423b03 100644 --- a/paddle/fluid/inference/utils/table_printer.cc +++ b/paddle/fluid/inference/utils/table_printer.cc @@ -53,7 +53,7 @@ std::string TablePrinter::PrintTable() { AddRowDivider(ss); - return std::move(ss.str()); + return ss.str(); } TablePrinter::TablePrinter(const std::vector& header) { diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 940fc98d3b320..e6701dd50b07e 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -589,7 +589,7 @@ static std::map 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( diff --git a/paddle/phi/api/lib/api_gen_utils.cc b/paddle/phi/api/lib/api_gen_utils.cc index 7cbb4344e81d7..8443f46315a24 100644 --- a/paddle/phi/api/lib/api_gen_utils.cc +++ b/paddle/phi/api/lib/api_gen_utils.cc @@ -41,7 +41,7 @@ std::unique_ptr> TensorToDenseTensor( *std::dynamic_pointer_cast(t.impl())); } - return std::move(pt_tensors); + return pt_tensors; } std::shared_ptr TensorToSelectedRows(const Tensor& tensor) { diff --git a/paddle/phi/api/lib/data_transform.cc b/paddle/phi/api/lib/data_transform.cc index 4e6ebe33aec8f..a6401cc20b29d 100644 --- a/paddle/phi/api/lib/data_transform.cc +++ b/paddle/phi/api/lib/data_transform.cc @@ -243,7 +243,7 @@ std::unique_ptr> PrepareData( } } - return std::move(pt_tensors); + return pt_tensors; } } // namespace experimental diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index 71cec01141164..0922083bf3004 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -62,9 +62,10 @@ struct KernelSignature { // TODO(chenweihang): add assign constructor to solve windows compile // problem, remove it later - KernelSignature& operator=(const KernelSignature& other) { - name = other.name; - args = other.args; + KernelSignature(const KernelSignature& other) : name(other.name), args(other.args) { } + KernelSignature& operator=(KernelSignature other) { + using std::swap; + swap(*this, other); return *this; } }; From 12de2dc895048c487cdaa731af9b2e4f8d347b31 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Mon, 4 Apr 2022 17:18:06 +0800 Subject: [PATCH 2/8] fix an compile error in debug mode --- paddle/phi/core/utils/type_registry.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/core/utils/type_registry.h b/paddle/phi/core/utils/type_registry.h index 8d9f9167242c8..71e3272af4c8f 100644 --- a/paddle/phi/core/utils/type_registry.h +++ b/paddle/phi/core/utils/type_registry.h @@ -50,7 +50,7 @@ template TypeInfo TypeRegistry::RegisterType(const std::string& type) { std::lock_guard guard(mutex_); assert(name_to_id_.find(type) == name_to_id_.end()); - assert(names_.size() < std::numeric_limits::max()); + assert(names_.size() < static_cast(std::numeric_limits::max())); int8_t id = names_.size(); names_.emplace_back(type); name_to_id_[type] = id; From dc451089c374d56777ace51f2410363ad348118f Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Tue, 19 Apr 2022 23:02:23 +0800 Subject: [PATCH 3/8] fix wrong copy assignment operator Signed-off-by: tiancaishaonvjituizi <452565578@qq.com> --- paddle/fluid/framework/var_desc.h | 7 ++++--- paddle/phi/core/compat/arg_map_context.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/framework/var_desc.h b/paddle/fluid/framework/var_desc.h index b79245c45f792..d99ca98aa654b 100644 --- a/paddle/fluid/framework/var_desc.h +++ b/paddle/fluid/framework/var_desc.h @@ -74,9 +74,10 @@ class VarDesc { : desc_(other.desc_), attrs_(other.attrs_), original_id_(other.original_id_) {} - VarDesc& operator=(VarDesc other) { - using std::swap; - swap(*this, other); + VarDesc& operator=(const VarDesc& other) { + desc_ = other.desc_; + attrs_ = other.attrs_; + original_id_ = other.original_id_; return *this; } diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index 5ea5978de2d22..4f5b8424b4d4a 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -51,9 +51,9 @@ struct KernelSignature { // TODO(chenweihang): add assign constructor to solve windows compile // problem, remove it later KernelSignature(const KernelSignature& other) : name(other.name), args(other.args) { } - KernelSignature& operator=(KernelSignature other) { - using std::swap; - swap(*this, other); + KernelSignature& operator=(const KernelSignature& other) { + name = other.name; + args = other.args; return *this; } }; From 2eeb8bb0286bab9ec477c8040809eb02b9feed58 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Wed, 20 Apr 2022 09:32:01 +0800 Subject: [PATCH 4/8] reformat Signed-off-by: tiancaishaonvjituizi <452565578@qq.com> --- paddle/fluid/framework/var_desc.h | 2 +- paddle/phi/core/compat/arg_map_context.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/var_desc.h b/paddle/fluid/framework/var_desc.h index d99ca98aa654b..0f8c10604f39a 100644 --- a/paddle/fluid/framework/var_desc.h +++ b/paddle/fluid/framework/var_desc.h @@ -74,7 +74,7 @@ class VarDesc { : desc_(other.desc_), attrs_(other.attrs_), original_id_(other.original_id_) {} - VarDesc& operator=(const VarDesc& other) { + VarDesc &operator=(const VarDesc &other) { desc_ = other.desc_; attrs_ = other.attrs_; original_id_ = other.original_id_; diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index 4f5b8424b4d4a..153bc6d38b5ed 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -50,7 +50,8 @@ struct KernelSignature { // TODO(chenweihang): add assign constructor to solve windows compile // problem, remove it later - KernelSignature(const KernelSignature& other) : name(other.name), args(other.args) { } + KernelSignature(const KernelSignature& other) + : name(other.name), args(other.args) {} KernelSignature& operator=(const KernelSignature& other) { name = other.name; args = other.args; From f1fca39bb820626ee278760b857cb33489e20595 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Wed, 20 Apr 2022 15:01:58 +0800 Subject: [PATCH 5/8] reformat Signed-off-by: tiancaishaonvjituizi <452565578@qq.com> --- paddle/phi/core/utils/type_registry.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paddle/phi/core/utils/type_registry.h b/paddle/phi/core/utils/type_registry.h index b8a89fc1cf6c9..5b64dbd01643e 100644 --- a/paddle/phi/core/utils/type_registry.h +++ b/paddle/phi/core/utils/type_registry.h @@ -50,7 +50,8 @@ template TypeInfo TypeRegistry::RegisterType(const std::string& type) { std::lock_guard guard(mutex_); assert(name_to_id_.find(type) == name_to_id_.end()); - assert(names_.size() < static_cast(std::numeric_limits::max())); + assert(names_.size() < static_cast( + std::numeric_limits::max())); int8_t id = static_cast(names_.size()); names_.emplace_back(type); name_to_id_[type] = id; From 599836caf1b78e914066566ac94227d24a689bbf Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Thu, 21 Apr 2022 21:37:54 +0800 Subject: [PATCH 6/8] fix ArrayRef constructor following llvm --- paddle/utils/array_ref.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/paddle/utils/array_ref.h b/paddle/utils/array_ref.h index d2ab762bb154f..72d8cbba57232 100644 --- a/paddle/utils/array_ref.h +++ b/paddle/utils/array_ref.h @@ -97,9 +97,20 @@ class ArrayRef { /*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {} /// 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 &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 from ArrayRef. This uses SFINAE to /// ensure that only ArrayRefs of pointers can be converted. From 3aed8df93647c94eff7b0d87fcf975a5b990e5e7 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Fri, 22 Apr 2022 10:36:02 +0800 Subject: [PATCH 7/8] fix format --- paddle/utils/array_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/utils/array_ref.h b/paddle/utils/array_ref.h index 72d8cbba57232..788710925936b 100644 --- a/paddle/utils/array_ref.h +++ b/paddle/utils/array_ref.h @@ -96,7 +96,7 @@ class ArrayRef { template /*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 From 763150262cfde8f42869dd2dc40bac8735714af4 Mon Sep 17 00:00:00 2001 From: tiancaishaonvjituizi <452565578@qq.com> Date: Sat, 23 Apr 2022 23:59:25 +0800 Subject: [PATCH 8/8] fix conflict with master --- paddle/phi/core/compat/arg_map_context.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index bd23a48d02977..f807f268a2d33 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -59,7 +59,10 @@ struct KernelSignature { // TODO(chenweihang): add assign constructor to solve windows compile // problem, remove it later KernelSignature(const KernelSignature& other) - : name(other.name), args(other.args) {} + : 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;