Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] No. 53,54 enable cppcoreguidelines-c-copy-assignment-signature and bugprone-use-after-move #56601

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bugprone-integer-division,
-bugprone-unhandled-self-assignment,
bugprone-unused-raii,
-bugprone-unused-return-value,
-bugprone-use-after-move,
bugprone-use-after-move,
-bugprone-virtual-near-miss,
-clang-analyzer-apiModeling.StdCLibraryFunctions,
-clang-analyzer-apiModeling.TrustNonnull,
Expand Down Expand Up @@ -153,7 +153,7 @@ clang-analyzer-unix.Vfork,
-clang-analyzer-valist.ValistBase,
cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-c-copy-assignment-signature,
cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-narrowing-conversions,
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/distributed/rpc/rpc_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RpcAgent::RpcAgent(std::string name, std::vector<WorkerInfo> infos) {
PADDLE_ENFORCE_EQ(
server_.AddService(rpc_service_.get(), brpc::SERVER_DOESNT_OWN_SERVICE),
0,
platform::errors::Fatal("Fail to add service: %s", name));
platform::errors::Fatal("Fail to add service: %s", name_));
}

int RpcAgent::StartWorker() {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/framework/new_executor/program_interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ void ProgramInterpreter::Convert(
for (size_t op_idx = 0; op_idx < op_nums; ++op_idx) {
auto& op_func_node = nodes[op_idx];
auto* dev_ctx_ = stream_analyzer_.ParseDeviceContext(op_func_node);
vec_instruction_.emplace_back(op_idx, std::move(op_func_node), *dev_ctx_);
#ifdef PADDLE_WITH_CUDA
if (FLAGS_new_executor_use_cuda_graph) {
auto& op = op_func_node.operator_base_;
Expand All @@ -637,6 +636,7 @@ void ProgramInterpreter::Convert(
.RecordCapturingDeviceContext(dev_ctx_);
}
#endif
vec_instruction_.emplace_back(op_idx, std::move(op_func_node), *dev_ctx_);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要调整一下顺序?

Copy link
Contributor Author

@xiaoyewww xiaoyewww Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要调整一下顺序?

@zhangbo9674
因为开启了GPU后,op_func_node会在std::move之后调用,并且看到vec_instruction_没有在617-638这块代码里使用,所以调整了一下顺序

}

BuildOperatorDependences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ StreamSafeCustomDeviceAllocator::StreamSafeCustomDeviceAllocator(
place_(std::move(place)),
default_stream_(std::move(default_stream)) {
std::lock_guard<SpinLock> lock_guard(allocator_map_lock_);
allocator_map_[place].emplace_back(this);
allocator_map_[place_].emplace_back(this);
}

StreamSafeCustomDeviceAllocator::~StreamSafeCustomDeviceAllocator() {
Expand Down
12 changes: 8 additions & 4 deletions paddle/fluid/operators/math/beam_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,14 @@ class BeamSearchFunctor<phi::CPUContext, T> {
((score == in.score) && (offset < in.offset));
}

inline void operator=(const Item &in) {
offset = in.offset;
id = in.id;
score = in.score;
inline Item &operator=(const Item &in) {
if (this != &in) {
this->offset = in.offset;
this->id = in.id;
this->score = in.score;
return *this;
}
return *this;
}

std::string ToString() {
Expand Down
14 changes: 9 additions & 5 deletions paddle/phi/core/sparse_coo_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ SparseCooTensor::SparseCooTensor(const SparseCooTensor& other) {
set_meta(other.meta());
}

SparseCooTensor SparseCooTensor::operator=(const SparseCooTensor& other) {
this->non_zero_elements_ = other.non_zero_elements_;
this->non_zero_indices_ = other.non_zero_indices_;
this->coalesced_ = other.coalesced_;
set_meta(other.meta());
SparseCooTensor& SparseCooTensor::operator=(const SparseCooTensor& other) {
if (this != &other) {
this->non_zero_elements_ = other.non_zero_elements_;
this->non_zero_indices_ = other.non_zero_indices_;
this->coalesced_ = other.coalesced_;
set_meta(other.meta());
return *this;
}

return *this;
}

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/core/sparse_coo_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SparseCooTensor : public TensorBase,
SparseCooTensor(SparseCooTensor&& other);

/// \brief SparseCooTensor shallow copy assignment.
SparseCooTensor operator=(const SparseCooTensor& other);
SparseCooTensor& operator=(const SparseCooTensor& other);

/// \brief Destroy the tensor object and release exclusive resources.
virtual ~SparseCooTensor() = default;
Expand Down
14 changes: 10 additions & 4 deletions paddle/phi/kernels/cpu/weighted_sample_neighbors_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ struct GraphWeightedNode {
}
GraphWeightedNode(T node_id, float weight_key, T eid = 0)
: node_id(node_id), weight_key(weight_key), eid(eid) {}
void operator=(const GraphWeightedNode<T>& other) {
node_id = other.node_id;
weight_key = other.weight_key;
eid = other.eid;

GraphWeightedNode& operator=(const GraphWeightedNode<T>& other) {
if (this != &other) {
this->node_id = other.node_id;
this->weight_key = other.weight_key;
this->eid = other.eid;
return *this;
}

return *this;
}
friend bool operator>(const GraphWeightedNode<T>& n1,
const GraphWeightedNode<T>& n2) {
Expand Down
10 changes: 8 additions & 2 deletions test/cpp/fluid/reader/reader_blocking_queue_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,21 @@ struct MyClass {
explicit MyClass(int val) : val_(val) {}
MyClass(const MyClass& b) { val_ = b.val_; }
MyClass(MyClass&& b) { val_ = b.val_; }
void operator=(const MyClass& b) { val_ = b.val_; }
MyClass& operator=(const MyClass& b) {
if (this != &b) {
val_ = b.val_;
return *this;
}
return *this;
}

int val_;
};

TEST(BlockingQueue, MyClassTest) {
BlockingQueue<MyClass> q(2);
MyClass a(200);
q.Send(std::move(a));
q.Send(a);
MyClass b;
q.Receive(&b);
EXPECT_EQ(a.val_, b.val_);
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/phi/core/test_string_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TEST(pstring, func) {
CHECK_EQ(copy_nchar_str, "AAAAA");

// Test Move Ctor
pstring move_nchar_str(std::move(nchar_str));
pstring move_nchar_str(nchar_str);
CHECK_EQ(move_nchar_str, "AAAAA");
pstring std_str(std::string("BBBB"));
CHECK_EQ(std_str, "BBBB");
Expand Down