This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 4b42156fc0d3b7828fb70f5f591c4c5facd508eb
Author: py023 <[email protected]>
AuthorDate: Mon Feb 5 15:55:54 2024 +0800

    [chore](clang-tidy): add bugprone linters (#29521)
    
    This PR introduces 4 bugprone linter rules to .clang-tidy, these linters 
found some bugs in #28965. This PR also add some comments to mute false 
positive reports.
---
 .clang-tidy                                              | 15 +++++++++------
 be/src/olap/rowset/segment_creator.cpp                   |  2 +-
 be/src/service/backend_service.cpp                       |  3 ++-
 be/src/vec/common/hash_table/hash_table.h                |  9 +++++----
 be/src/vec/exec/format/orc/vorc_reader.cpp               |  6 ++++--
 be/src/vec/exec/format/parquet/vparquet_group_reader.cpp |  6 ++++--
 be/src/vec/exec/scan/new_olap_scan_node.cpp              |  2 +-
 be/src/vec/functions/function.cpp                        |  2 +-
 8 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index 5d530bcb768..f572f100cec 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -4,6 +4,10 @@ Checks: |
   clang-diagnostic-*,
   clang-analyzer-*,
   bugprone-redundant-branch-condition,
+  bugprone-use-after-move,
+  bugprone-bool-pointer-implicit-conversion,
+  bugprone-unused-raii,
+  bugprone-fold-init-type,
   modernize-*,
   -modernize-use-trailing-return-type,
   -modernize-use-nodiscard,
@@ -24,10 +28,9 @@ Checks: |
   performance-faster-string-find,
   performance-inefficient-algorithm,
   performance-move-const-arg
-WarningsAsErrors: '*'
+WarningsAsErrors: "*"
 CheckOptions:
-  - key:             readability-function-size.LineThreshold
-    value:           '80'
-  - key:             readability-function-cognitive-complexity.Threshold
-    value:           '50'
-
+  - key: readability-function-size.LineThreshold
+    value: "80"
+  - key: readability-function-cognitive-complexity.Threshold
+    value: "50"
diff --git a/be/src/olap/rowset/segment_creator.cpp 
b/be/src/olap/rowset/segment_creator.cpp
index 0fa0151b4b3..66825a9fbbd 100644
--- a/be/src/olap/rowset/segment_creator.cpp
+++ b/be/src/olap/rowset/segment_creator.cpp
@@ -218,7 +218,7 @@ Status 
SegmentFlusher::_expand_variant_to_subcolumns(vectorized::Block& block,
         VLOG_DEBUG << "dump rs schema: " << 
_context->tablet_schema->dump_structure();
     }
 
-    block.swap(flush_block);
+    block.swap(flush_block); // NOLINT(bugprone-use-after-move)
     VLOG_DEBUG << "dump block: " << block.dump_data();
     VLOG_DEBUG << "dump flush schema: " << flush_schema->dump_structure();
     return Status::OK();
diff --git a/be/src/service/backend_service.cpp 
b/be/src/service/backend_service.cpp
index fb98d60dce4..a8171d2196d 100644
--- a/be/src/service/backend_service.cpp
+++ b/be/src/service/backend_service.cpp
@@ -224,7 +224,8 @@ void _ingest_binlog(IngestBinlogArg* arg) {
     }
 
     // Step 5.2: check data capacity
-    uint64_t total_size = std::accumulate(segment_file_sizes.begin(), 
segment_file_sizes.end(), 0);
+    uint64_t total_size = std::accumulate(segment_file_sizes.begin(), 
segment_file_sizes.end(),
+                                          0); // 
NOLINT(bugprone-fold-init-type)
     if (!local_tablet->can_add_binlog(total_size)) {
         LOG(WARNING) << "failed to add binlog, no enough space, total_size=" 
<< total_size
                      << ", tablet=" << local_tablet->tablet_id();
diff --git a/be/src/vec/common/hash_table/hash_table.h 
b/be/src/vec/common/hash_table/hash_table.h
index 7e669f275e2..04a5ff8f0e4 100644
--- a/be/src/vec/common/hash_table/hash_table.h
+++ b/be/src/vec/common/hash_table/hash_table.h
@@ -611,10 +611,11 @@ public:
         std::swap(_need_partition, rhs._need_partition);
         std::swap(_partitioned_threshold, rhs._partitioned_threshold);
 
-        Hash::operator=(std::move(rhs));
-        Allocator::operator=(std::move(rhs));
-        Cell::State::operator=(std::move(rhs));
-        ZeroValueStorage<Cell::need_zero_value_storage, 
Cell>::operator=(std::move(rhs));
+        Hash::operator=(std::move(rhs));        // 
NOLINT(bugprone-use-after-move)
+        Allocator::operator=(std::move(rhs));   // 
NOLINT(bugprone-use-after-move)
+        Cell::State::operator=(std::move(rhs)); // 
NOLINT(bugprone-use-after-move)
+        ZeroValueStorage<Cell::need_zero_value_storage, Cell>::operator=(
+                std::move(rhs)); // NOLINT(bugprone-use-after-move)
 
         return *this;
     }
diff --git a/be/src/vec/exec/format/orc/vorc_reader.cpp 
b/be/src/vec/exec/format/orc/vorc_reader.cpp
index 436673722b6..d1b908dbc22 100644
--- a/be/src/vec/exec/format/orc/vorc_reader.cpp
+++ b/be/src/vec/exec/format/orc/vorc_reader.cpp
@@ -1938,8 +1938,10 @@ Status OrcReader::on_string_dicts_loaded(
                 auto data_type = slot_desc->get_data_type_ptr();
                 if (data_type->is_nullable()) {
                     temp_block.insert(
-                            
{ColumnNullable::create(std::move(dict_value_column),
-                                                    
ColumnUInt8::create(dict_value_column_size, 0)),
+                            {ColumnNullable::create(
+                                     std::move(
+                                             dict_value_column), // 
NOLINT(bugprone-use-after-move)
+                                     
ColumnUInt8::create(dict_value_column_size, 0)),
                              
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>()),
                              ""});
                 } else {
diff --git a/be/src/vec/exec/format/parquet/vparquet_group_reader.cpp 
b/be/src/vec/exec/format/parquet/vparquet_group_reader.cpp
index 3784c054b8c..1aea6a52c4e 100644
--- a/be/src/vec/exec/format/parquet/vparquet_group_reader.cpp
+++ b/be/src/vec/exec/format/parquet/vparquet_group_reader.cpp
@@ -800,8 +800,10 @@ Status RowGroupReader::_rewrite_dict_predicates() {
                 auto data_type = slot_desc->get_data_type_ptr();
                 if (data_type->is_nullable()) {
                     temp_block.insert(
-                            
{ColumnNullable::create(std::move(dict_value_column),
-                                                    
ColumnUInt8::create(dict_value_column_size, 0)),
+                            {ColumnNullable::create(
+                                     std::move(
+                                             dict_value_column), // 
NOLINT(bugprone-use-after-move)
+                                     
ColumnUInt8::create(dict_value_column_size, 0)),
                              
std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>()),
                              ""});
                 } else {
diff --git a/be/src/vec/exec/scan/new_olap_scan_node.cpp 
b/be/src/vec/exec/scan/new_olap_scan_node.cpp
index b11db29eb11..44a435ed2a2 100644
--- a/be/src/vec/exec/scan/new_olap_scan_node.cpp
+++ b/be/src/vec/exec/scan/new_olap_scan_node.cpp
@@ -648,7 +648,7 @@ Status 
NewOlapScanNode::_init_scanners(std::list<VScannerSPtr>* scanners) {
                 }
 
                 const auto max_add_seg_nums = rs_seg_count[rowset_idx] - 
segment_idx_to_scan;
-                auto& split = rs_splits.emplace_back();
+                auto& split = rs_splits.emplace_back(); // 
NOLINT(bugprone-use-after-move)
                 split.rs_reader = 
read_source.rs_splits[rowset_idx].rs_reader->clone();
 
                 // if segments assigned to current scanner are already more 
than the average count,
diff --git a/be/src/vec/functions/function.cpp 
b/be/src/vec/functions/function.cpp
index e0f785b0ef6..6a033d52f03 100644
--- a/be/src/vec/functions/function.cpp
+++ b/be/src/vec/functions/function.cpp
@@ -62,7 +62,7 @@ ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& 
block, const Colum
         if (const auto* nullable = assert_cast<const 
ColumnNullable*>(elem.column.get());
             nullable->has_null()) {
             const ColumnPtr& null_map_column = 
nullable->get_null_map_column_ptr();
-            if (!result_null_map_column) {
+            if (!result_null_map_column) { // NOLINT(bugprone-use-after-move)
                 result_null_map_column = 
null_map_column->clone_resized(input_rows_count);
                 continue;
             }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to