From 98696c09e3270e1b1b02d21bf20dada6dfaf2362 Mon Sep 17 00:00:00 2001 From: gouzil <66515297+gouzil@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:53:12 +0800 Subject: [PATCH] [clang-tidy] NO.10 enable `cppcoreguidelines-init-variables` (#57871) * [clang-tidy] enable cppcoreguidelines-init-variables check * fix --- .clang-tidy | 2 +- .../auto_parallel/spmd_rules/common.cc | 2 +- .../distributed/fleet_executor/dist_model.cc | 2 +- paddle/fluid/framework/data_feed.cc | 6 ++-- .../framework/details/gather_op_handle.cc | 2 +- .../framework/details/multi_devices_helper.cc | 4 +-- .../framework/details/reduce_op_handle.cc | 2 +- .../details/threaded_ssa_graph_executor.cc | 2 +- paddle/fluid/framework/downpour_worker.cc | 4 +-- paddle/fluid/framework/downpour_worker_opt.cc | 2 +- paddle/fluid/framework/hogwild_worker.cc | 6 ++-- paddle/fluid/framework/io/crypto/cipher.cc | 4 +-- .../fluid/framework/io/crypto/cipher_utils.cc | 2 +- .../framework/io/crypto/cipher_utils_test.cc | 8 ++--- .../fluid/framework/ir/conv_bn_fuse_pass.cc | 4 +-- .../framework/ir/conv_bn_fuse_pass_tester.cc | 2 +- .../ir/delete_quant_dequant_linear_op_pass.cc | 2 +- .../delete_weight_dequant_linear_op_pass.cc | 3 +- .../framework/ir/fuse_gemm_epilogue_pass.cc | 8 ++--- paddle/fluid/framework/ir/graph_viz_pass.cc | 2 +- .../ir/multihead_matmul_fuse_pass.cc | 36 +++++++++---------- .../ir/multihead_matmul_roformer_fuse_pass.cc | 18 +++++----- .../ir/seqpool_concat_fuse_pass_tester.cc | 6 ++-- .../ir/seqpool_cvm_concat_fuse_pass.cc | 2 +- .../ir/seqpool_cvm_concat_fuse_pass_tester.cc | 6 ++-- paddle/fluid/framework/lod_tensor.cc | 14 ++++---- .../new_executor/interpreter/data_transfer.cc | 2 +- .../interpreter/interpreter_util.cc | 2 +- .../new_executor/interpreter/static_build.cc | 2 +- paddle/fluid/framework/program_utils.cc | 2 +- paddle/fluid/framework/scope_pool.cc | 2 +- paddle/fluid/framework/selected_rows_utils.cc | 8 ++--- paddle/fluid/framework/string_array.cc | 6 ++-- paddle/fluid/framework/tensor_util.cc | 12 +++---- paddle/fluid/imperative/data_loader.cc | 6 ++-- .../fluid/imperative/partial_grad_engine.cc | 2 +- .../fluid/inference/api/analysis_predictor.cc | 6 ++-- paddle/fluid/inference/api/api_impl.cc | 2 +- paddle/fluid/inference/utils/io_utils.cc | 16 ++++----- .../ir_adaptor/translator/op_translator.cc | 2 +- paddle/fluid/jit/serializer_utils.cc | 2 +- .../fluid/memory/allocation/cpu_allocator.cc | 2 +- .../allocation/system_allocator_test.cc | 2 +- paddle/fluid/operators/bilateral_slice_op.cc | 2 +- .../controlflow/conditional_block_infer_op.cc | 2 +- .../controlflow/conditional_block_op.cc | 4 +-- .../operators/controlflow/get_places_op.cc | 2 +- paddle/fluid/operators/detection/mask_util.cc | 15 ++++---- .../operators/detection/multiclass_nms_op.cc | 6 ++-- .../detection/rpn_target_assign_op.cc | 2 +- .../fluid/operators/fused/fused_matmul_op.cc | 2 +- paddle/fluid/operators/fused/fusion_gru_op.cc | 2 +- .../fluid/operators/fused/fusion_lstm_op.cc | 2 +- paddle/fluid/operators/gru_op.cc | 3 +- paddle/fluid/operators/interpolate_op.cc | 6 ++-- paddle/fluid/operators/math/tree2col.cc | 2 +- paddle/fluid/operators/matmul_op.cc | 2 +- paddle/fluid/operators/merge_lod_tensor_op.cc | 2 +- .../reader/create_double_buffer_reader_op.cc | 2 +- paddle/fluid/operators/reader/py_reader.cc | 2 +- paddle/fluid/operators/split_lod_tensor_op.cc | 2 +- .../operators/string/faster_tokenizer_op.cc | 2 +- .../pir/transforms/pd_op_to_kernel_pass.cc | 2 +- paddle/fluid/platform/profiler.cc | 16 ++++----- paddle/fluid/pybind/eager_method.cc | 4 +-- paddle/fluid/pybind/eager_utils.cc | 4 +-- paddle/fluid/pybind/eval_frame.c | 2 +- paddle/fluid/pybind/op_function_common.cc | 20 +++++------ paddle/phi/api/lib/data_transform.cc | 2 +- paddle/phi/backends/context_pool.cc | 2 +- paddle/phi/backends/dynload/dynamic_loader.cc | 4 +-- .../phi/core/distributed/store/tcp_store.cc | 2 +- .../phi/core/distributed/store/tcp_utils.cc | 6 ++-- paddle/phi/core/generator.cc | 2 +- paddle/phi/infermeta/binary.cc | 8 ++--- paddle/phi/infermeta/multiary.cc | 6 ++-- paddle/phi/infermeta/nullary.cc | 2 +- paddle/phi/infermeta/unary.cc | 24 ++++++------- paddle/phi/kernels/cpu/allclose_kernel.cc | 4 +-- paddle/phi/kernels/cpu/cumprod_grad_kernel.cc | 4 +-- paddle/phi/kernels/cpu/diag_kernel.cc | 2 +- .../cpu/distribute_fpn_proposals_kernel.cc | 2 +- paddle/phi/kernels/cpu/eigvals_kernel.cc | 2 +- paddle/phi/kernels/cpu/group_norm_kernel.cc | 4 +-- .../kernels/cpu/instance_norm_grad_kernel.cc | 2 +- .../kernels/cpu/interpolate_grad_kernel.cc | 6 ++-- paddle/phi/kernels/cpu/interpolate_kernel.cc | 6 ++-- .../phi/kernels/cpu/matrix_rank_tol_kernel.cc | 2 +- .../phi/kernels/cpu/multiclass_nms3_kernel.cc | 6 ++-- paddle/phi/kernels/cpu/norm_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/norm_kernel.cc | 4 +-- paddle/phi/kernels/cpu/p_norm_kernel.cc | 2 +- .../phi/kernels/cpu/psroi_pool_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/psroi_pool_kernel.cc | 2 +- paddle/phi/kernels/cpu/qr_kernel.cc | 4 +-- .../phi/kernels/cpu/roi_align_grad_kernel.cc | 4 +-- .../phi/kernels/cpu/roi_pool_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/svd_kernel.cc | 2 +- .../phi/kernels/cpu/yolo_loss_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/yolo_loss_kernel.cc | 2 +- .../kernels/funcs/gather_scatter_functor.cc | 2 +- paddle/phi/kernels/funcs/gpc.cc | 20 +++++------ paddle/phi/kernels/funcs/im2col.cc | 2 +- paddle/phi/kernels/funcs/jit/gen_base.cc | 6 ++-- paddle/phi/kernels/funcs/jit/helper.cc | 2 +- .../funcs/jit/more/intrinsic/layer_norm.cc | 4 +-- paddle/phi/kernels/funcs/maxouting.cc | 4 +-- paddle/phi/kernels/funcs/pooling.cc | 10 +++--- paddle/phi/kernels/funcs/vol2col.cc | 4 +-- .../kernels/selected_rows/cpu/adam_kernel.cc | 2 +- paddle/phi/kernels/stride/diagonal_kernel.cc | 2 +- paddle/phi/ops/compat/strided_slice_sig.cc | 4 +-- paddle/utils/flags_native_test.cc | 4 +-- test/cpp/fluid/math/im2col_test.cc | 6 ++-- test/cpp/fluid/math/vol2col_test.cc | 4 +-- .../reader/reader_blocking_queue_test.cc | 10 +++--- .../imperative/test_gradient_accmulator.cc | 2 +- test/cpp/phi/core/test_ddim.cc | 2 +- 118 files changed, 278 insertions(+), 275 deletions(-) mode change 100755 => 100644 test/cpp/phi/core/test_ddim.cc diff --git a/.clang-tidy b/.clang-tidy index 924095b4def28..e25238ec43772 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -155,7 +155,7 @@ cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-avoid-goto, cppcoreguidelines-c-copy-assignment-signature, cppcoreguidelines-explicit-virtual-functions, --cppcoreguidelines-init-variables, +cppcoreguidelines-init-variables, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, -cppcoreguidelines-pro-type-const-cast, diff --git a/paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc b/paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc index e8ef88c03032b..09b4d6a2189b7 100644 --- a/paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc +++ b/paddle/fluid/distributed/auto_parallel/spmd_rules/common.cc @@ -57,7 +57,7 @@ std::unordered_map ShardingMergeForTensors( const bool merge_conflicts) { std::unordered_map axis_to_dim_map; std::unordered_map dim_to_axis_map; - int64_t merge_dim; + int64_t merge_dim = 0; for (auto& pair : tensor_axes_to_dim_pairs) { for (size_t i = 0; i < pair.second.size(); ++i) { diff --git a/paddle/fluid/distributed/fleet_executor/dist_model.cc b/paddle/fluid/distributed/fleet_executor/dist_model.cc index 2a6da1b437a1b..119c3f4c61985 100644 --- a/paddle/fluid/distributed/fleet_executor/dist_model.cc +++ b/paddle/fluid/distributed/fleet_executor/dist_model.cc @@ -47,7 +47,7 @@ bool LoadDataFromDistModelTensor(const DistModelTensor &input_data, const platform::Place &place) { VLOG(3) << "Loading data from DistModelTensor for " << input_data.name; framework::DDim dims = phi::make_ddim(input_data.shape); - void *input_tensor_ptr; + void *input_tensor_ptr = nullptr; if (input_data.dtype == DistModelDataType::INT64) { input_tensor_ptr = input_tensor->mutable_data(dims, place); } else if (input_data.dtype == DistModelDataType::FLOAT32) { diff --git a/paddle/fluid/framework/data_feed.cc b/paddle/fluid/framework/data_feed.cc index 902cd0f39369a..3bd11d87730fb 100644 --- a/paddle/fluid/framework/data_feed.cc +++ b/paddle/fluid/framework/data_feed.cc @@ -2448,9 +2448,9 @@ bool SlotRecordInMemoryDataFeed::ParseOneInstance(const std::string& line, } // parse_logkey std::string log_key = std::string(str + pos, len); - uint64_t search_id; - uint32_t cmatch; - uint32_t rank; + uint64_t search_id = 0; + uint32_t cmatch = 0; + uint32_t rank = 0; parser_log_key(log_key, &search_id, &cmatch, &rank); rec->ins_id_ = log_key; diff --git a/paddle/fluid/framework/details/gather_op_handle.cc b/paddle/fluid/framework/details/gather_op_handle.cc index 79b43b1b501db..0aae1ce6b60d7 100644 --- a/paddle/fluid/framework/details/gather_op_handle.cc +++ b/paddle/fluid/framework/details/gather_op_handle.cc @@ -45,7 +45,7 @@ void GatherOpHandle::RunImpl() { in_var_handles.size(), places_.size())); - VarHandle *out_var_handle; + VarHandle *out_var_handle = nullptr; { auto out_var_handles = DynamicCast(this->Outputs()); PADDLE_ENFORCE_EQ( diff --git a/paddle/fluid/framework/details/multi_devices_helper.cc b/paddle/fluid/framework/details/multi_devices_helper.cc index 4849ca34e3e95..d2379c2c49a19 100644 --- a/paddle/fluid/framework/details/multi_devices_helper.cc +++ b/paddle/fluid/framework/details/multi_devices_helper.cc @@ -176,7 +176,7 @@ static bool IsDataParallelInferenceGraphImpl( } bool IsDataParallelInferenceGraph(const ir::Graph &graph) { - size_t place_num; + size_t place_num = 0; std::unordered_map op_to_dev_idx; return IsDataParallelInferenceGraphImpl(graph, &op_to_dev_idx, &place_num); } @@ -196,7 +196,7 @@ bool IsDataParallelInferenceGraph(const ir::Graph &graph) { */ std::vector> TrySeparateToMultipleSingleDeviceGraphs( ir::Graph *graph) { - size_t place_num; + size_t place_num = 0; std::unordered_map op_to_dev_idx; if (!IsDataParallelInferenceGraphImpl(*graph, &op_to_dev_idx, &place_num)) { return {}; diff --git a/paddle/fluid/framework/details/reduce_op_handle.cc b/paddle/fluid/framework/details/reduce_op_handle.cc index 7acf425fd77f3..fe43126ca8abe 100644 --- a/paddle/fluid/framework/details/reduce_op_handle.cc +++ b/paddle/fluid/framework/details/reduce_op_handle.cc @@ -63,7 +63,7 @@ void ReduceOpHandle::RunImpl() { in_var_handles.size(), places_.size())); - VarHandle *out_var_handle; + VarHandle *out_var_handle = nullptr; { auto out_var_handles = DynamicCast(outputs_); diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc index ce3fe004c40bb..0397f87f6649e 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc @@ -128,7 +128,7 @@ inline FetchResultType ThreadedSSAGraphExecutor::RunImpl( run_all_ops(ready_ops); // 2. Find ready variable - bool timeout; + bool timeout = false; auto cur_ready_vars = ready_vars->PopAll(1, &timeout); if (timeout) { for (auto &run_op_future : run_op_futures_) { diff --git a/paddle/fluid/framework/downpour_worker.cc b/paddle/fluid/framework/downpour_worker.cc index e69a25bb32781..72596cb5db93b 100644 --- a/paddle/fluid/framework/downpour_worker.cc +++ b/paddle/fluid/framework/downpour_worker.cc @@ -485,7 +485,7 @@ void DownpourWorker::TrainFilesWithProfiler() { double push_sparse_time = 0.0; double push_dense_time = 0.0; double copy_table_time = 0.0; - int cur_batch; + int cur_batch = 0; int batch_cnt = 0; uint64_t total_inst = 0; timeline.Start(); @@ -804,7 +804,7 @@ void DownpourWorker::TrainFiles() { platform::SetNumThreads(1); device_reader_->Start(); int batch_cnt = 0; - int cur_batch; + int cur_batch = 0; while ((cur_batch = device_reader_->Next()) > 0) { if (copy_table_config_.need_copy()) { if (batch_cnt % copy_table_config_.batch_num() == 0) { diff --git a/paddle/fluid/framework/downpour_worker_opt.cc b/paddle/fluid/framework/downpour_worker_opt.cc index 68c774965aeab..99bce83a24f4e 100644 --- a/paddle/fluid/framework/downpour_worker_opt.cc +++ b/paddle/fluid/framework/downpour_worker_opt.cc @@ -307,7 +307,7 @@ void DownpourWorkerOpt::TrainFiles() { platform::SetNumThreads(1); device_reader_->Start(); int batch_cnt = 0; - int cur_batch; + int cur_batch = 0; std::future pull_async_status; std::string async_wait_name = ""; for (int i = 0; i < param_.program_config(0).pull_sparse_table_id_size(); diff --git a/paddle/fluid/framework/hogwild_worker.cc b/paddle/fluid/framework/hogwild_worker.cc index 08d681ae6411f..fbf219a773e12 100644 --- a/paddle/fluid/framework/hogwild_worker.cc +++ b/paddle/fluid/framework/hogwild_worker.cc @@ -239,7 +239,7 @@ void HogwildWorker::TrainFilesWithProfiler() { platform::Timer timeline; double total_time = 0.0; double read_time = 0.0; - int cur_batch; + int cur_batch = 0; int batch_cnt = 0; if (thread_id_ == 0) { quit_flag_.store(false); @@ -372,7 +372,7 @@ void HogwildWorker::TrainFiles() { int total_batch_num = 0; // how to accumulate fetched values here device_reader_->Start(); - int cur_batch; + int cur_batch = 0; int batch_cnt = 0; if (thread_id_ == 0) { quit_flag_.store(false); @@ -471,7 +471,7 @@ void HogwildWorker::PrintFetchVars() { } if (thread_id_ == 0 && batch_num_ % batch_per_print == 0) { - time_t curtime; + time_t curtime = 0; time(&curtime); std::array mbstr; std::strftime(mbstr.data(), diff --git a/paddle/fluid/framework/io/crypto/cipher.cc b/paddle/fluid/framework/io/crypto/cipher.cc index 2001e8a416a1a..03e0cb4d0eb27 100644 --- a/paddle/fluid/framework/io/crypto/cipher.cc +++ b/paddle/fluid/framework/io/crypto/cipher.cc @@ -24,8 +24,8 @@ namespace framework { std::shared_ptr CipherFactory::CreateCipher( const std::string& config_file) { std::string cipher_name; - int iv_size; - int tag_size; + int iv_size = 0; + int tag_size = 0; std::unordered_map config; if (!config_file.empty()) { config = CipherUtils::LoadConfig(config_file); diff --git a/paddle/fluid/framework/io/crypto/cipher_utils.cc b/paddle/fluid/framework/io/crypto/cipher_utils.cc index c10da1ce6706c..42d6223b729af 100644 --- a/paddle/fluid/framework/io/crypto/cipher_utils.cc +++ b/paddle/fluid/framework/io/crypto/cipher_utils.cc @@ -72,7 +72,7 @@ std::unordered_map CipherUtils::LoadConfig( "make sure input filename is available.", config_file)); std::unordered_map ret; - char c; + char c = 0; std::string line; std::istringstream iss; while (std::getline(fin, line)) { diff --git a/paddle/fluid/framework/io/crypto/cipher_utils_test.cc b/paddle/fluid/framework/io/crypto/cipher_utils_test.cc index 356c919cbcbe8..ee4453bcaab67 100644 --- a/paddle/fluid/framework/io/crypto/cipher_utils_test.cc +++ b/paddle/fluid/framework/io/crypto/cipher_utils_test.cc @@ -46,19 +46,19 @@ TEST(CipherUtils, load_config) { EXPECT_TRUE(CipherUtils::GetValue(config, "key_str", &out_str)); EXPECT_EQ(out_str, std::string("ciphername")); - int out_int; + int out_int = 0; EXPECT_TRUE(CipherUtils::GetValue(config, "key_int", &out_int)); EXPECT_EQ(out_int, 1); - bool out_bool; + bool out_bool = false; EXPECT_TRUE(CipherUtils::GetValue(config, "key_bool", &out_bool)); EXPECT_EQ(out_bool, true); - bool out_bool1; + bool out_bool1 = false; EXPECT_TRUE(CipherUtils::GetValue(config, "key_bool1", &out_bool1)); EXPECT_EQ(out_bool1, false); - bool out_bool2; + bool out_bool2 = false; EXPECT_TRUE(CipherUtils::GetValue(config, "key_bool2", &out_bool2)); EXPECT_EQ(out_bool2, false); } diff --git a/paddle/fluid/framework/ir/conv_bn_fuse_pass.cc b/paddle/fluid/framework/ir/conv_bn_fuse_pass.cc index 6b21bfa5defc9..aa15b2696d7a1 100644 --- a/paddle/fluid/framework/ir/conv_bn_fuse_pass.cc +++ b/paddle/fluid/framework/ir/conv_bn_fuse_pass.cc @@ -371,8 +371,8 @@ void ConvBNFusePass::ApplyImpl(ir::Graph* graph) const { bool mkldnn_with_bias = is_mkldnn && has_bias; // Create eltwise_y (conv bias) variable - phi::DenseTensor* eltwise_y_in_tensor; - Node* eltwise_y_in_node; + phi::DenseTensor* eltwise_y_in_tensor = nullptr; + Node* eltwise_y_in_node = nullptr; if (!mkldnn_with_bias) { VarDesc eltwise_y_in_desc( patterns::PDNodeName("fuse_conv_bn", conv_type() + "_eltwise_y_in")); diff --git a/paddle/fluid/framework/ir/conv_bn_fuse_pass_tester.cc b/paddle/fluid/framework/ir/conv_bn_fuse_pass_tester.cc index 7cd069eea91a8..2f420bc858e37 100644 --- a/paddle/fluid/framework/ir/conv_bn_fuse_pass_tester.cc +++ b/paddle/fluid/framework/ir/conv_bn_fuse_pass_tester.cc @@ -59,7 +59,7 @@ void TestMain(const std::string& conv_type) { auto* in = layers.data("in", {1, 3, 20, 20}); auto* filters = layers.data("filters", {3, 3, 2, 2}, true); auto* bias_0 = layers.data("bias_0", {3}, true); - VarDesc* conv_out; + VarDesc* conv_out = nullptr; if (conv_type == "conv_transpose") { conv_out = layers.conv2d_transpose(in, filters, bias_0); } else { diff --git a/paddle/fluid/framework/ir/delete_quant_dequant_linear_op_pass.cc b/paddle/fluid/framework/ir/delete_quant_dequant_linear_op_pass.cc index cb6a6e1d5d9dc..286f7f08cdfc9 100644 --- a/paddle/fluid/framework/ir/delete_quant_dequant_linear_op_pass.cc +++ b/paddle/fluid/framework/ir/delete_quant_dequant_linear_op_pass.cc @@ -122,7 +122,7 @@ void DeleteQuantDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const { platform::errors::InvalidArgument( "Input scale tensor's place should be CPU.")); - float input_scale; + float input_scale = NAN; if (input_scale_tensor.dtype() == phi::DataType::FLOAT32) { const float* input_scale_data = input_scale_tensor.data(); input_scale = input_scale_data[0]; diff --git a/paddle/fluid/framework/ir/delete_weight_dequant_linear_op_pass.cc b/paddle/fluid/framework/ir/delete_weight_dequant_linear_op_pass.cc index 0b09d1b30f40a..cf5c9a2c94cf9 100644 --- a/paddle/fluid/framework/ir/delete_weight_dequant_linear_op_pass.cc +++ b/paddle/fluid/framework/ir/delete_weight_dequant_linear_op_pass.cc @@ -45,7 +45,8 @@ void DeleteWeightDequantLinearOpPass::ApplyImpl(ir::Graph* graph) const { if (n->IsOp()) { auto* op = n->Op(); if (op->Type() == "dequantize_linear") { - Node *weight_var_node, *calcu_op_node, *while_op_node; + Node *weight_var_node = nullptr, *calcu_op_node = nullptr, + *while_op_node = nullptr; Node *dequantized_weight_var_node = nullptr, *scale_var_node = nullptr; // 1. Judge whether for dequant weight and find // weight_var_node/scale_var_node diff --git a/paddle/fluid/framework/ir/fuse_gemm_epilogue_pass.cc b/paddle/fluid/framework/ir/fuse_gemm_epilogue_pass.cc index 2f92a58ba3a77..f945471e507a2 100644 --- a/paddle/fluid/framework/ir/fuse_gemm_epilogue_pass.cc +++ b/paddle/fluid/framework/ir/fuse_gemm_epilogue_pass.cc @@ -83,7 +83,7 @@ ir::Graph *FuseGemmEpiloguePass::FuseLinearFwd(ir::Graph *graph, auto matmul_op_desc = matmul_op->Op(); if (!IsGemmFromLinear_(matmul_x_shape, matmul_w_shape)) return; - bool trans_x, trans_y; + bool trans_x = false, trans_y = false; GetTransposeAttrsFromOp(*matmul_op_desc, &trans_x, &trans_y); OpDesc fused_gemm_epilogue_op_desc(matmul_op->Op()->Block()); @@ -168,7 +168,7 @@ ir::Graph *FuseGemmEpiloguePass::FuseLinearActFwd( auto activation = act_op->Op()->Type(); - bool trans_x, trans_y; + bool trans_x = false, trans_y = false; GetTransposeAttrsFromOp(*matmul_op_desc, &trans_x, &trans_y); OpDesc fused_gemm_epilogue_op_desc(matmul_op->Op()->Block()); @@ -291,7 +291,7 @@ ir::Graph *FuseGemmEpiloguePass::FuseLinearBwd(ir::Graph *graph, auto matmul_grad_op_desc = matmul_grad_op->Op(); if (!IsGemmFromLinear_(matmul_grad_x_shape, matmul_grad_w_shape)) return; - bool trans_x, trans_y; + bool trans_x = false, trans_y = false; GetTransposeAttrsFromOp(*matmul_grad_op_desc, &trans_x, &trans_y); OpDesc fused_gemm_epilogue_grad_op_desc(ele_add_grad_op->Op()->Block()); @@ -430,7 +430,7 @@ ir::Graph *FuseGemmEpiloguePass::FuseLinearActBwd( auto activation_grad = act_grad_op->Op()->Type(); - bool trans_x, trans_y; + bool trans_x = false, trans_y = false; GetTransposeAttrsFromOp(*matmul_grad_op_desc, &trans_x, &trans_y); OpDesc fused_gemm_epilogue_grad_op_desc(ele_add_grad_op->Op()->Block()); fused_gemm_epilogue_grad_op_desc.SetType("fused_gemm_epilogue_grad"); diff --git a/paddle/fluid/framework/ir/graph_viz_pass.cc b/paddle/fluid/framework/ir/graph_viz_pass.cc index 4f430ba4041d6..3f68f5c6dd72b 100644 --- a/paddle/fluid/framework/ir/graph_viz_pass.cc +++ b/paddle/fluid/framework/ir/graph_viz_pass.cc @@ -149,7 +149,7 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const { } } } - decltype(op_attrs)* attr; + decltype(op_attrs)* attr = nullptr; if (marked_nodes.count(n)) { attr = &marked_var_attrs; } else if (const_cast(n)->Var() && diff --git a/paddle/fluid/framework/ir/multihead_matmul_fuse_pass.cc b/paddle/fluid/framework/ir/multihead_matmul_fuse_pass.cc index a950ec191a4bf..0fd3a71754f6d 100644 --- a/paddle/fluid/framework/ir/multihead_matmul_fuse_pass.cc +++ b/paddle/fluid/framework/ir/multihead_matmul_fuse_pass.cc @@ -273,9 +273,9 @@ PDNode* MultiHeadMatmulPattern::operator()() { auto* mul0_out_var = pattern->NewNode(mul0_out_repr())->assert_is_ops_output(mul_ops); - decltype(mul0) eltadd0; - decltype(mul0) eltadd0_b_var; - decltype(mul0) eltadd0_out_var; + decltype(mul0) eltadd0 = nullptr; + decltype(mul0) eltadd0_b_var = nullptr; + decltype(mul0) eltadd0_out_var = nullptr; mul0_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); @@ -353,9 +353,9 @@ PDNode* MultiHeadMatmulPattern::operator()() { auto* mul1_out_var = pattern->NewNode(mul1_out_repr())->assert_is_ops_output(mul_ops); - decltype(mul1) eltadd1; - decltype(mul1) eltadd1_b_var; - decltype(mul1) eltadd1_out_var; + decltype(mul1) eltadd1 = nullptr; + decltype(mul1) eltadd1_b_var = nullptr; + decltype(mul1) eltadd1_out_var = nullptr; mul1_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd1 = pattern->NewNode(eltadd1_repr())->assert_is_op("elementwise_add"); @@ -389,9 +389,9 @@ PDNode* MultiHeadMatmulPattern::operator()() { auto* mul2_out_var = pattern->NewNode(mul2_out_repr())->assert_is_ops_output(mul_ops); - decltype(mul2) eltadd2; - decltype(mul2) eltadd2_b_var; - decltype(mul2) eltadd2_out_var; + decltype(mul2) eltadd2 = nullptr; + decltype(mul2) eltadd2_b_var = nullptr; + decltype(mul2) eltadd2_out_var = nullptr; mul2_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd2 = pattern->NewNode(eltadd2_repr())->assert_is_op("elementwise_add"); @@ -465,9 +465,9 @@ PDNode* MultiHeadMatmulV3Pattern::operator()() { auto* mul0_out_var = pattern->NewNode(mul0_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul0) eltadd0; - decltype(mul0) eltadd0_b_var; - decltype(mul0) eltadd0_out_var; + decltype(mul0) eltadd0 = nullptr; + decltype(mul0) eltadd0_b_var = nullptr; + decltype(mul0) eltadd0_out_var = nullptr; mul0_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); @@ -539,9 +539,9 @@ PDNode* MultiHeadMatmulV3Pattern::operator()() { auto* mul1_out_var = pattern->NewNode(mul1_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul1) eltadd1; - decltype(mul1) eltadd1_b_var; - decltype(mul1) eltadd1_out_var; + decltype(mul1) eltadd1 = nullptr; + decltype(mul1) eltadd1_b_var = nullptr; + decltype(mul1) eltadd1_out_var = nullptr; mul1_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd1 = pattern->NewNode(eltadd1_repr())->assert_is_op("elementwise_add"); @@ -575,9 +575,9 @@ PDNode* MultiHeadMatmulV3Pattern::operator()() { auto* mul2_out_var = pattern->NewNode(mul2_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul2) eltadd2; - decltype(mul2) eltadd2_b_var; - decltype(mul2) eltadd2_out_var; + decltype(mul2) eltadd2 = nullptr; + decltype(mul2) eltadd2_b_var = nullptr; + decltype(mul2) eltadd2_out_var = nullptr; mul2_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd2 = pattern->NewNode(eltadd2_repr())->assert_is_op("elementwise_add"); diff --git a/paddle/fluid/framework/ir/multihead_matmul_roformer_fuse_pass.cc b/paddle/fluid/framework/ir/multihead_matmul_roformer_fuse_pass.cc index c974f5fafd68b..be5fad23fd6e2 100644 --- a/paddle/fluid/framework/ir/multihead_matmul_roformer_fuse_pass.cc +++ b/paddle/fluid/framework/ir/multihead_matmul_roformer_fuse_pass.cc @@ -53,9 +53,9 @@ PDNode* MultiHeadMatmulRoformerPattern::operator()() { auto* mul0_out_var = pattern->NewNode(mul0_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul0) eltadd0; - decltype(mul0) eltadd0_b_var; - decltype(mul0) eltadd0_out_var; + decltype(mul0) eltadd0 = nullptr; + decltype(mul0) eltadd0_b_var = nullptr; + decltype(mul0) eltadd0_out_var = nullptr; mul0_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); @@ -165,9 +165,9 @@ PDNode* MultiHeadMatmulRoformerPattern::operator()() { auto* mul1_out_var = pattern->NewNode(mul1_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul1) eltadd1; - decltype(mul1) eltadd1_b_var; - decltype(mul1) eltadd1_out_var; + decltype(mul1) eltadd1 = nullptr; + decltype(mul1) eltadd1_b_var = nullptr; + decltype(mul1) eltadd1_out_var = nullptr; mul1_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd1 = pattern->NewNode(eltadd1_repr())->assert_is_op("elementwise_add"); @@ -232,9 +232,9 @@ PDNode* MultiHeadMatmulRoformerPattern::operator()() { auto* mul2_out_var = pattern->NewNode(mul2_out_repr())->assert_is_ops_output(matmul_ops); - decltype(mul2) eltadd2; - decltype(mul2) eltadd2_b_var; - decltype(mul2) eltadd2_out_var; + decltype(mul2) eltadd2 = nullptr; + decltype(mul2) eltadd2_b_var = nullptr; + decltype(mul2) eltadd2_out_var = nullptr; mul2_out_var->AsIntermediate()->assert_is_op_input("elementwise_add"); eltadd2 = pattern->NewNode(eltadd2_repr())->assert_is_op("elementwise_add"); diff --git a/paddle/fluid/framework/ir/seqpool_concat_fuse_pass_tester.cc b/paddle/fluid/framework/ir/seqpool_concat_fuse_pass_tester.cc index a0693e8a39433..d4e8a1683ed18 100644 --- a/paddle/fluid/framework/ir/seqpool_concat_fuse_pass_tester.cc +++ b/paddle/fluid/framework/ir/seqpool_concat_fuse_pass_tester.cc @@ -114,7 +114,7 @@ TEST(SeqPoolConcatFusePass, basic) { std::vector({"j"})); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove 10 Nodes: op1, op2, op3, d, e, f, g, h, i, concat_op // Add 1 Node: fusion_seqpool_concat @@ -168,7 +168,7 @@ TEST(SeqPoolConcatFusePass, advanced) { std::vector({"h"})); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove 7 Nodes: op1, op2, c, d, e, f concat_op // Add 1 Node: fusion_seqpool_concat @@ -204,7 +204,7 @@ TEST(SeqPoolConcatFusePass, more_inputs) { for (int num : {1, 2, 10}) { ProgramDesc prog = BuildProgramDesc(num); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove Nodes: n * (seqpool_op, out, out_unused), and concat_op // Add Node: fusion_seqpool_concat op diff --git a/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass.cc b/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass.cc index 16296d83dae1c..eeef9c73db3d7 100644 --- a/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass.cc +++ b/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass.cc @@ -145,7 +145,7 @@ void SeqPoolCVMConcatFusePass::ApplyImpl(ir::Graph* graph) const { std::vector subgraph_ins_name; std::unordered_set marked_nodes; - Node* cvm_input_of_cvm; + Node* cvm_input_of_cvm = nullptr; Node* concat_out_var = concat_node->outputs[0]; GraphPatternDetector::handle_t handler = diff --git a/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass_tester.cc b/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass_tester.cc index f3adab84d3a3d..390a6fc0706df 100644 --- a/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass_tester.cc +++ b/paddle/fluid/framework/ir/seqpool_cvm_concat_fuse_pass_tester.cc @@ -151,7 +151,7 @@ TEST(SeqPoolCVMConcatFusePass, basic) { std::vector({"m"})); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove 16 Nodes: op1, op2, op3, op4, op5, op6, d, e, f, g, h, i, j, k, l, // concat_op @@ -219,7 +219,7 @@ TEST(SeqPoolCVMConcatFusePass, advanced) { std::vector({"j"})); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove 11 Nodes: op1, op2, op4, op5, c, d, e, f, h, i, concat_op // Add 1 Node: fusion_seqpool_cvm_concat @@ -265,7 +265,7 @@ TEST(SeqPoolCVMConcatFusePass, more_inputs) { for (int num : {1, 2, 10}) { ProgramDesc prog = BuildProgramDesc(num); std::unique_ptr graph(new ir::Graph(prog)); - int before, after; + int before = 0, after = 0; graph = GetNumNodesOfBeforeAfter(std::move(graph), &before, &after); // Remove Nodes: n * (seqpool_op, seqpool_out, out_unused, cvm_op, cvm_out), // and concat_op diff --git a/paddle/fluid/framework/lod_tensor.cc b/paddle/fluid/framework/lod_tensor.cc index 32675d5fa09c1..96cff2521dfe7 100644 --- a/paddle/fluid/framework/lod_tensor.cc +++ b/paddle/fluid/framework/lod_tensor.cc @@ -235,7 +235,7 @@ void SerializeToStream(std::ostream &os, void SerializeToStream(std::ostream &os, const phi::DenseTensor &tensor) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); - const platform::DeviceContext *dev_ctx; + const platform::DeviceContext *dev_ctx = nullptr; auto place = tensor.place(); dev_ctx = pool.Get(place); SerializeToStream(os, tensor, *dev_ctx); @@ -243,7 +243,7 @@ void SerializeToStream(std::ostream &os, const phi::DenseTensor &tensor) { void DeserializeFromStream(std::istream &os, phi::DenseTensor *tensor) { platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance(); - const platform::DeviceContext *dev_ctx; + const platform::DeviceContext *dev_ctx = nullptr; dev_ctx = pool.Get(platform::CPUPlace()); DeserializeFromStream(os, tensor, *dev_ctx); } @@ -255,7 +255,7 @@ void DeserializeFromStream(std::istream &is, const std::vector &shape) { { // the 1st field, unit32_t version for DenseTensor - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); PADDLE_ENFORCE_EQ(paddle::framework::IsTensorVersionSupported(version), true, @@ -271,7 +271,7 @@ void DeserializeFromStream(std::istream &is, } { // the 2st field, LoD information - uint64_t lod_level; + uint64_t lod_level = 0; is.read(reinterpret_cast(&lod_level), sizeof(lod_level)); auto &lod = *tensor->mutable_lod(); lod.resize(lod_level); @@ -286,7 +286,7 @@ void DeserializeFromStream(std::istream &is, const platform::DeviceContext &dev_ctx) { { // the 1st field, unit32_t version for DenseTensor - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); PADDLE_ENFORCE_EQ(paddle::framework::IsTensorVersionSupported(version), true, @@ -302,12 +302,12 @@ void DeserializeFromStream(std::istream &is, } { // the 2st field, LoD information - uint64_t lod_level; + uint64_t lod_level = 0; is.read(reinterpret_cast(&lod_level), sizeof(lod_level)); auto &lod = *tensor->mutable_lod(); lod.resize(lod_level); for (uint64_t i = 0; i < lod_level; ++i) { - uint64_t size; + uint64_t size = 0; is.read(reinterpret_cast(&size), sizeof(size)); std::vector tmp(size / sizeof(size_t)); is.read(reinterpret_cast(tmp.data()), diff --git a/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc b/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc index 0baa62f8a4dcd..0d3af1e55c2a0 100644 --- a/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc +++ b/paddle/fluid/framework/new_executor/interpreter/data_transfer.cc @@ -508,7 +508,7 @@ void ApplyDataTransform(const OpKernelType& expected_kernel_key, const std::string var_name = argument_names[i]; Variable* var = arguments->at(i); - const phi::DenseTensor* tensor_in; + const phi::DenseTensor* tensor_in = nullptr; if (var->IsType() || var->IsType()) { tensor_in = GetLoDTensorOrSelectedRowsValueFromVar(*var); diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc index 3d142acdc1c7a..8338f881a8cdb 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc @@ -894,7 +894,7 @@ void BuildOpFuncList(const platform::Place& place, // avoid overwriting valid data if (static_build && original_tensor->initialized()) { const phi::Place& target_place = transformed_tensor->place(); - platform::DeviceContext* dev_ctx_for_copy; + platform::DeviceContext* dev_ctx_for_copy = nullptr; if (target_place.GetType() != AllocationType::CPU) { dev_ctx_for_copy = pool.Get(target_place); } else { diff --git a/paddle/fluid/framework/new_executor/interpreter/static_build.cc b/paddle/fluid/framework/new_executor/interpreter/static_build.cc index e8e5a1ef29aed..bebeb142d473f 100644 --- a/paddle/fluid/framework/new_executor/interpreter/static_build.cc +++ b/paddle/fluid/framework/new_executor/interpreter/static_build.cc @@ -330,7 +330,7 @@ void FakeInitializeTensor(const platform::DeviceContext& dev_ctx, // set place if (tensor->initialized()) { // avoid overwriting valid data - platform::DeviceContext* dev_ctx_for_copy; + platform::DeviceContext* dev_ctx_for_copy = nullptr; if (place.GetType() != AllocationType::CPU) { dev_ctx_for_copy = platform::DeviceContextPool::Instance().Get(place); } else { diff --git a/paddle/fluid/framework/program_utils.cc b/paddle/fluid/framework/program_utils.cc index 2d8a35ca00a76..10d8264538c81 100644 --- a/paddle/fluid/framework/program_utils.cc +++ b/paddle/fluid/framework/program_utils.cc @@ -150,7 +150,7 @@ void ProgramProcessor::AddDepToBlockOp(const BlockDesc &block) { VLOG(3) << "sub_outputs.size:" << sub_outputs.size(); auto *op_inputs = op->MutableInputs(); - std::vector *op_input_var_vec; + std::vector *op_input_var_vec = nullptr; VLOG(3) << "op_type:>>>>>>" << op_type; if (op_type.compare("while") == 0) { op_input_var_vec = &((*op_inputs)["kX"]); diff --git a/paddle/fluid/framework/scope_pool.cc b/paddle/fluid/framework/scope_pool.cc index 1f7aba8e225bd..833848864a785 100644 --- a/paddle/fluid/framework/scope_pool.cc +++ b/paddle/fluid/framework/scope_pool.cc @@ -29,7 +29,7 @@ void ScopePool::Insert(std::unique_ptr &&s) { } void ScopePool::Remove(Scope *s) { - size_t has_scope; + size_t has_scope = 0; { std::lock_guard guard(mtx_); has_scope = scopes_.erase(s); diff --git a/paddle/fluid/framework/selected_rows_utils.cc b/paddle/fluid/framework/selected_rows_utils.cc index d74e45449226f..3f72ced811390 100644 --- a/paddle/fluid/framework/selected_rows_utils.cc +++ b/paddle/fluid/framework/selected_rows_utils.cc @@ -45,7 +45,7 @@ void SerializeToStream(std::ostream& os, void SerializeToStream(std::ostream& os, const phi::SelectedRows& selected_rows) { platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); - const platform::DeviceContext* dev_ctx; + const platform::DeviceContext* dev_ctx = nullptr; auto place = selected_rows.place(); dev_ctx = pool.Get(place); SerializeToStream(os, selected_rows, *dev_ctx); @@ -53,7 +53,7 @@ void SerializeToStream(std::ostream& os, void DeserializeFromStream(std::istream& is, phi::SelectedRows* selected_rows) { platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); - const platform::DeviceContext* dev_ctx; + const platform::DeviceContext* dev_ctx = nullptr; dev_ctx = pool.Get(platform::CPUPlace()); DeserializeFromStream(is, selected_rows, *dev_ctx); } @@ -63,7 +63,7 @@ void DeserializeFromStream(std::istream& is, const platform::DeviceContext& dev_ctx) { { // the 1st field, unit32_t version for SelectedRows - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); PADDLE_ENFORCE_EQ(version, 0U, @@ -86,7 +86,7 @@ void DeserializeFromStream(std::istream& is, } { // the 3st field, the height of the SelectedRows - int64_t height; + int64_t height = 0; is.read(reinterpret_cast(&height), sizeof(int64_t)); selected_rows->set_height(height); } diff --git a/paddle/fluid/framework/string_array.cc b/paddle/fluid/framework/string_array.cc index 58c658a67c69e..07e3f07294fae 100644 --- a/paddle/fluid/framework/string_array.cc +++ b/paddle/fluid/framework/string_array.cc @@ -81,20 +81,20 @@ void StringMapToStream(std::ostream& os, void StringMapFromStream(std::istream& is, std::unordered_map* data) { // first read the map size - size_t map_size; + size_t map_size = 0; is.read(reinterpret_cast(&map_size), sizeof(map_size)); data->reserve(map_size); // then read the data for (size_t i = 0; i < map_size; ++i) { // read the token - size_t token_length; + size_t token_length = 0; is.read(reinterpret_cast(&token_length), sizeof(token_length)); char* tmp = new char[token_length]; is.read(tmp, token_length); // NOLINT std::string token(tmp, tmp + token_length); delete[] tmp; // read the token_id - int32_t token_id; + int32_t token_id = 0; is.read(reinterpret_cast(&token_id), sizeof(token_id)); data->emplace(token, token_id); diff --git a/paddle/fluid/framework/tensor_util.cc b/paddle/fluid/framework/tensor_util.cc index 16a9065c2eb87..d7cfb4738822a 100644 --- a/paddle/fluid/framework/tensor_util.cc +++ b/paddle/fluid/framework/tensor_util.cc @@ -274,7 +274,7 @@ void TensorCopyImpl(const TENSOR& src, const platform::Place& dst_place, TENSOR* dst) { platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); - const platform::DeviceContext* dev_ctx; + const platform::DeviceContext* dev_ctx = nullptr; if (platform::is_gpu_place(dst_place) || platform::is_custom_place(dst_place)) { dev_ctx = pool.Get(dst_place); @@ -585,7 +585,7 @@ void TensorFromStream(std::istream& is, const platform::DeviceContext& dev_ctx, const size_t& seek, const std::vector& shape) { - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); PADDLE_ENFORCE_EQ( @@ -598,7 +598,7 @@ void TensorFromStream(std::istream& is, proto::VarType::TensorDesc desc; { // int32_t size // proto buffer - int32_t size; + int32_t size = 0; is.read(reinterpret_cast(&size), sizeof(size)); std::unique_ptr buf(new char[size]); // NOLINT is.read(reinterpret_cast(buf.get()), size); @@ -612,7 +612,7 @@ void TensorFromStream(std::istream& is, size_t seekg = seek * framework::SizeOfType(desc.data_type()); is.seekg(seekg, is.cur); // NOLINT - void* buf; + void* buf = nullptr; phi::CPUContext ctx; size_t size = tensor->numel() * framework::SizeOfType(desc.data_type()); if (platform::is_gpu_place(dev_ctx.GetPlace()) || @@ -652,7 +652,7 @@ void TensorFromStream(std::istream& is, void TensorFromStream(std::istream& is, phi::DenseTensor* tensor, const platform::DeviceContext& dev_ctx) { - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); PADDLE_ENFORCE_EQ( version, @@ -685,7 +685,7 @@ void TensorFromStream(std::istream& is, dims.reserve(static_cast(desc.dims().size())); std::copy(desc.dims().begin(), desc.dims().end(), std::back_inserter(dims)); tensor->Resize(phi::make_ddim(dims)); - void* buf; + void* buf = nullptr; phi::CPUContext ctx; size_t size = tensor->numel() * framework::SizeOfType(desc.data_type()); if (platform::is_gpu_place(dev_ctx.GetPlace()) || diff --git a/paddle/fluid/imperative/data_loader.cc b/paddle/fluid/imperative/data_loader.cc index 3e2e96f143277..bf09ac38d6d11 100644 --- a/paddle/fluid/imperative/data_loader.cc +++ b/paddle/fluid/imperative/data_loader.cc @@ -128,9 +128,9 @@ void SetLoadProcessSignalHandler() { } void ThrowErrorIfLoadProcessFailed() { - int error; - std::set *pids_set; - pid_t process_pid; + int error = 0; + std::set *pids_set = nullptr; + pid_t process_pid = 0; siginfo_t infop; for (auto &p : load_process_pids) { diff --git a/paddle/fluid/imperative/partial_grad_engine.cc b/paddle/fluid/imperative/partial_grad_engine.cc index 833a13546ccd7..a3973a32512a2 100644 --- a/paddle/fluid/imperative/partial_grad_engine.cc +++ b/paddle/fluid/imperative/partial_grad_engine.cc @@ -907,7 +907,7 @@ void PartialGradTask::RunEachOp(OpBase *op) { } else { for (auto &grad_var : input_pair.second) { if (grad_var) { - bool is_last; + bool is_last = false; new_inputs.emplace_back( ready_grad_vars_.Get(grad_var.get(), op->place(), &is_last)); VLOG(10) << "Got ready grad var " << grad_var->Name() << " " diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index f30e2c560b57f..9520f4b1f0d71 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -217,7 +217,7 @@ bool PaddleTensorToDenseTensor(const PaddleTensor &pt, phi::DenseTensor *t, const platform::Place &place) { framework::DDim ddim = phi::make_ddim(pt.shape); - void *input_ptr; + void *input_ptr = nullptr; if (pt.dtype == PaddleDType::INT64) { input_ptr = t->mutable_data(ddim, place); } else if (pt.dtype == PaddleDType::FLOAT32) { @@ -1988,7 +1988,7 @@ AnalysisPredictor::GetOutputTypes() { std::unique_ptr AnalysisPredictor::GetInputTensor( const std::string &name) { - framework::Scope *scope; + framework::Scope *scope = nullptr; #if defined(PADDLE_WITH_DISTRIBUTE) && defined(PADDLE_WITH_PSCORE) if (config_.dist_config().use_dist_model()) { scope = scope_.get(); @@ -2039,7 +2039,7 @@ std::unique_ptr AnalysisPredictor::GetInputTensor( std::unique_ptr AnalysisPredictor::GetOutputTensor( const std::string &name) { - framework::Scope *scope; + framework::Scope *scope; // NOLINT #if defined(PADDLE_WITH_DISTRIBUTE) && defined(PADDLE_WITH_PSCORE) if (config_.dist_config().use_dist_model()) { scope = scope_.get(); diff --git a/paddle/fluid/inference/api/api_impl.cc b/paddle/fluid/inference/api/api_impl.cc index 76b0410cc8e8f..c3f50fd6f6bb3 100644 --- a/paddle/fluid/inference/api/api_impl.cc +++ b/paddle/fluid/inference/api/api_impl.cc @@ -214,7 +214,7 @@ bool NativePaddlePredictor::SetFeed(const std::vector &inputs, for (size_t i = 0; i < inputs.size(); ++i) { auto &input = feed_tensors_[i]; framework::DDim ddim = phi::make_ddim(inputs[i].shape); - void *input_ptr; + void *input_ptr = nullptr; if (inputs[i].dtype == PaddleDType::INT64) { input_ptr = input.mutable_data(ddim, place_); } else if (inputs[i].dtype == PaddleDType::FLOAT32) { diff --git a/paddle/fluid/inference/utils/io_utils.cc b/paddle/fluid/inference/utils/io_utils.cc index 0ee80e3700b5c..c74414926aa2f 100644 --- a/paddle/fluid/inference/utils/io_utils.cc +++ b/paddle/fluid/inference/utils/io_utils.cc @@ -80,21 +80,21 @@ void SerializePDTensorToStream(std::ostream *os, const PaddleTensor &tensor) { void DeserializePDTensorToStream(std::istream &is, PaddleTensor *tensor) { // 1. Version - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); // 2. Name - uint64_t name_bytes; + uint64_t name_bytes = 0; is.read(reinterpret_cast(&name_bytes), sizeof(name_bytes)); std::vector bytes(name_bytes); is.read(bytes.data(), name_bytes); // NOLINT tensor->name = std::string(bytes.data(), name_bytes); // 3. LoD - uint64_t lod_level; + uint64_t lod_level = 0; is.read(reinterpret_cast(&lod_level), sizeof(lod_level)); auto *lod = &(tensor->lod); lod->resize(lod_level); for (uint64_t i = 0; i < lod_level; ++i) { - uint64_t size; + uint64_t size = 0; is.read(reinterpret_cast(&size), sizeof(size)); std::vector tmp(size / sizeof(size_t)); is.read(reinterpret_cast(tmp.data()), @@ -102,13 +102,13 @@ void DeserializePDTensorToStream(std::istream &is, PaddleTensor *tensor) { (*lod)[i] = tmp; } // 4. Shape - size_t dims; + size_t dims = 0; is.read(reinterpret_cast(&dims), sizeof(dims)); tensor->shape.resize(dims); is.read(reinterpret_cast(tensor->shape.data()), sizeof(int) * dims); // NOLINT // 5. Data - uint64_t length; + uint64_t length = 0; is.read(reinterpret_cast(&tensor->dtype), sizeof(tensor->dtype)); is.read(reinterpret_cast(&length), sizeof(length)); tensor->data.Resize(length); @@ -139,10 +139,10 @@ void SerializePDTensorsToStream(std::ostream *os, void DeserializePDTensorsToStream(std::istream &is, std::vector *tensors) { // 1. Version - uint32_t version; + uint32_t version = 0; is.read(reinterpret_cast(&version), sizeof(version)); // 2. Tensors - uint64_t num; + uint64_t num = 0; is.read(reinterpret_cast(&num), sizeof(num)); tensors->resize(num); for (auto &tensor : *tensors) { diff --git a/paddle/fluid/ir_adaptor/translator/op_translator.cc b/paddle/fluid/ir_adaptor/translator/op_translator.cc index 65ed57ebc9be1..9f60d37409988 100644 --- a/paddle/fluid/ir_adaptor/translator/op_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/op_translator.cc @@ -280,7 +280,7 @@ pir::OpInfo OpTranscriber::LoopkUpOpInfo(pir::IrContext* ctx, if (need_inputs_sig.size() != sig.inputs.size()) { continue; } - size_t i; + size_t i = 0; for (i = 0; i < need_inputs_sig.size(); ++i) { if (need_inputs_sig[i] == "") { continue; diff --git a/paddle/fluid/jit/serializer_utils.cc b/paddle/fluid/jit/serializer_utils.cc index 5b58b9d417312..4fdc07f55ac74 100644 --- a/paddle/fluid/jit/serializer_utils.cc +++ b/paddle/fluid/jit/serializer_utils.cc @@ -79,7 +79,7 @@ const std::vector> PdmodelFilePaths( std::string dir_path = format_path.substr(0, format_path.length() - layer_name.length()); DIR* dir = opendir(dir_path.c_str()); - struct dirent* ptr; + struct dirent* ptr = nullptr; while ((ptr = readdir(dir)) != nullptr) { std::string file_name = ptr->d_name; diff --git a/paddle/fluid/memory/allocation/cpu_allocator.cc b/paddle/fluid/memory/allocation/cpu_allocator.cc index dde362ebed4ef..398c015627860 100644 --- a/paddle/fluid/memory/allocation/cpu_allocator.cc +++ b/paddle/fluid/memory/allocation/cpu_allocator.cc @@ -38,7 +38,7 @@ void CPUAllocator::FreeImpl(phi::Allocation *allocation) { } phi::Allocation *CPUAllocator::AllocateImpl(size_t size) { - void *p; + void *p = nullptr; #ifdef _WIN32 p = _aligned_malloc(size, kAlignment); #else diff --git a/paddle/fluid/memory/allocation/system_allocator_test.cc b/paddle/fluid/memory/allocation/system_allocator_test.cc index e04d14f0adfde..16b538599df25 100644 --- a/paddle/fluid/memory/allocation/system_allocator_test.cc +++ b/paddle/fluid/memory/allocation/system_allocator_test.cc @@ -26,7 +26,7 @@ PHI_DECLARE_bool(use_pinned_memory); void TestAllocator(paddle::memory::detail::SystemAllocator* a, size_t size) { bool freed = false; { - size_t index; + size_t index; // NOLINT void* p = a->Alloc(&index, size); if (size > 0) { EXPECT_NE(p, nullptr); diff --git a/paddle/fluid/operators/bilateral_slice_op.cc b/paddle/fluid/operators/bilateral_slice_op.cc index 53386c1551d0f..1a6561fc383cc 100644 --- a/paddle/fluid/operators/bilateral_slice_op.cc +++ b/paddle/fluid/operators/bilateral_slice_op.cc @@ -51,7 +51,7 @@ class BilateralSliceOp : public framework::OperatorWithKernel { int64_t coeffs_chans = grid_dims[1]; int64_t input_chans = input_dims[1]; - int64_t output_chans; + int64_t output_chans = 0; if ((!ctx->IsRuntime()) && ((coeffs_chans < 0) || (input_chans < 0))) { output_chans = -1; } else { diff --git a/paddle/fluid/operators/controlflow/conditional_block_infer_op.cc b/paddle/fluid/operators/controlflow/conditional_block_infer_op.cc index 0dd43e761da39..9caca06f53ad3 100644 --- a/paddle/fluid/operators/controlflow/conditional_block_infer_op.cc +++ b/paddle/fluid/operators/controlflow/conditional_block_infer_op.cc @@ -50,7 +50,7 @@ class ConditionalBlockInferOp : public ConditionalOp { private: void RunImpl(const framework::Scope &scope, const platform::Place &dev_place) const override { - bool need_run; + bool need_run = false; if (Attr("is_scalar_condition")) { // When is_scalar_condition is True, the conditional variable is a scalar, // whether need to execute the operators in sub-block depends on the diff --git a/paddle/fluid/operators/controlflow/conditional_block_op.cc b/paddle/fluid/operators/controlflow/conditional_block_op.cc index 501761d82d034..d7166a5ad0267 100644 --- a/paddle/fluid/operators/controlflow/conditional_block_op.cc +++ b/paddle/fluid/operators/controlflow/conditional_block_op.cc @@ -51,7 +51,7 @@ class ConditionalBlockOp : public ConditionalOp { private: void RunImpl(const framework::Scope &scope, const platform::Place &dev_place) const override { - bool need_run; + bool need_run = false; if (Attr("is_scalar_condition")) { // When is_scalar_condition is True, the conditional variable is a scalar, // whether need to execute the operators in sub-block depends on the @@ -147,7 +147,7 @@ class ConditionalBlockGradOp : public ConditionalOp { private: void RunImpl(const framework::Scope &scope, const platform::Place &dev_place) const override { - bool need_run; + bool need_run = false; if (Attr("is_scalar_condition")) { auto xs = this->InputTensors(scope, ConditionalOp::kCondition); need_run = ScalarCondition(xs); diff --git a/paddle/fluid/operators/controlflow/get_places_op.cc b/paddle/fluid/operators/controlflow/get_places_op.cc index 9f67b1d4b6e18..9262ca59af970 100644 --- a/paddle/fluid/operators/controlflow/get_places_op.cc +++ b/paddle/fluid/operators/controlflow/get_places_op.cc @@ -52,7 +52,7 @@ class GetPlacesOp : public framework::OperatorBase { private: void RunImpl(const framework::Scope &scope, const platform::Place &place) const override { - bool is_gpu; + bool is_gpu = false; if (Attr("device_type") == "AUTO") { is_gpu = platform::is_gpu_place(place); } else { diff --git a/paddle/fluid/operators/detection/mask_util.cc b/paddle/fluid/operators/detection/mask_util.cc index 70fdf4b8999f4..f3e5b166b43b8 100644 --- a/paddle/fluid/operators/detection/mask_util.cc +++ b/paddle/fluid/operators/detection/mask_util.cc @@ -42,10 +42,10 @@ void Decode(const uint32_t* cnts, int m, uint8_t* mask) { typedef uint32_t uint; void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) { - int j, m = 0; + int j = 0, m = 0; double scale = 5; - int *x, *y, *u, *v; - uint *a, *b; + int *x = nullptr, *y = nullptr, *u = nullptr, *v = nullptr; + uint *a = nullptr, *b = nullptr; platform::CPUPlace cpu; auto xptr = memory::Alloc(cpu, sizeof(int) * (k + 1) * 2); x = reinterpret_cast(xptr->ptr()); @@ -65,9 +65,10 @@ void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) { v = u + m; m = 0; for (j = 0; j < k; j++) { - int xs = x[j], xe = x[j + 1], ys = y[j], ye = y[j + 1], dx, dy, t, d; - int flip; - double s; + int xs = x[j], xe = x[j + 1], ys = y[j], ye = y[j + 1], dx = 0, dy = 0, + t = 0, d = 0; + int flip = 0; + double s = NAN; dx = abs(xe - xs); dy = abs(ys - ye); flip = (dx >= dy && xs > xe) || (dx < dy && ys > ye); @@ -100,7 +101,7 @@ void Poly2Mask(const float* xy, int k, int h, int w, uint8_t* mask) { /* get points along y-boundary and downsample */ k = m; m = 0; - double xd, yd; + double xd = NAN, yd = NAN; auto xyptr = memory::Alloc(cpu, sizeof(int) * k * 2); x = reinterpret_cast(xyptr->ptr()); y = x + k; diff --git a/paddle/fluid/operators/detection/multiclass_nms_op.cc b/paddle/fluid/operators/detection/multiclass_nms_op.cc index 8519752bc1049..9f3f426d1ad85 100644 --- a/paddle/fluid/operators/detection/multiclass_nms_op.cc +++ b/paddle/fluid/operators/detection/multiclass_nms_op.cc @@ -250,7 +250,7 @@ class MultiClassNMSKernel : public framework::OpKernel { *num_nmsed_out = num_det; const T* scores_data = scores.data(); if (keep_top_k > -1 && num_det > keep_top_k) { - const T* sdata; + const T* sdata = nullptr; std::vector>> score_index_pairs; for (const auto& it : *indices) { int label = it.first; @@ -310,7 +310,7 @@ class MultiClassNMSKernel : public framework::OpKernel { auto* scores_data = scores.data(); auto* bboxes_data = bboxes.data(); auto* odata = outs->data(); - const T* sdata; + const T* sdata = nullptr; phi::DenseTensor bbox; bbox.Resize({scores.dims()[0], box_size}); int count = 0; @@ -325,7 +325,7 @@ class MultiClassNMSKernel : public framework::OpKernel { for (auto idx : indices) { odata[count * out_dim] = label; // label - const T* bdata; + const T* bdata = nullptr; if (scores_size == 3) { bdata = bboxes_data + idx * box_size; odata[count * out_dim + 1] = sdata[idx]; // score diff --git a/paddle/fluid/operators/detection/rpn_target_assign_op.cc b/paddle/fluid/operators/detection/rpn_target_assign_op.cc index a41b8a70a4283..81e8d0d3edf7e 100644 --- a/paddle/fluid/operators/detection/rpn_target_assign_op.cc +++ b/paddle/fluid/operators/detection/rpn_target_assign_op.cc @@ -122,7 +122,7 @@ std::vector FilterStraddleAnchor( int anchor_num = static_cast(anchor->dims()[0]); auto* anchor_data = anchor->data(); if (rpn_straddle_thresh >= 0) { - int index; + int index = 0; for (int i = 0; i < anchor_num; ++i) { index = i * 4; if ((anchor_data[index + 0] >= -rpn_straddle_thresh) && diff --git a/paddle/fluid/operators/fused/fused_matmul_op.cc b/paddle/fluid/operators/fused/fused_matmul_op.cc index ca3d02bf9bfa1..198fd61a15078 100644 --- a/paddle/fluid/operators/fused/fused_matmul_op.cc +++ b/paddle/fluid/operators/fused/fused_matmul_op.cc @@ -82,7 +82,7 @@ class FusedMatmulOp : public framework::OperatorWithKernel { y_broadcasted = true; } - size_t M, N; + size_t M = 0, N = 0; if (trans_x) { M = dims_x[ndims_x - 1]; } else { diff --git a/paddle/fluid/operators/fused/fusion_gru_op.cc b/paddle/fluid/operators/fused/fusion_gru_op.cc index 0625d5c80c08e..541233949b5d2 100644 --- a/paddle/fluid/operators/fused/fusion_gru_op.cc +++ b/paddle/fluid/operators/fused/fusion_gru_op.cc @@ -129,7 +129,7 @@ void FusionGRUOp::InferShape(framework::InferShapeContext* ctx) const { framework::DDim out_dims({x_mat_dims[0], frame_size}); ctx->SetOutputDim("Hidden", out_dims); ctx->ShareLoD("X", "Hidden"); - int xx_width; + int xx_width = 0; if (ctx->Attrs().Get("use_seq")) { xx_width = static_cast(wx_dims[1]); } else { diff --git a/paddle/fluid/operators/fused/fusion_lstm_op.cc b/paddle/fluid/operators/fused/fusion_lstm_op.cc index 400d8dcdaad2f..d6e05a4ba3d48 100644 --- a/paddle/fluid/operators/fused/fusion_lstm_op.cc +++ b/paddle/fluid/operators/fused/fusion_lstm_op.cc @@ -141,7 +141,7 @@ void FusionLSTMOp::InferShape(framework::InferShapeContext* ctx) const { ctx->SetOutputDim("Cell", out_dims); ctx->ShareLoD("X", "Hidden"); ctx->ShareLoD("X", "Cell"); - int xx_width; + int xx_width = 0; if (ctx->Attrs().Get("use_seq")) { xx_width = static_cast(wx_dims[1]); } else { diff --git a/paddle/fluid/operators/gru_op.cc b/paddle/fluid/operators/gru_op.cc index 315bd22580972..f199fa096d0df 100644 --- a/paddle/fluid/operators/gru_op.cc +++ b/paddle/fluid/operators/gru_op.cc @@ -333,7 +333,8 @@ class GRUCPUKernel : public framework::OpKernel { auto input_dims = input->dims(); auto hidden_dims = hidden->dims(); - LodTensorPtr batch_gate, batch_reset_hidden_prev, batch_hidden; + LodTensorPtr batch_gate = nullptr, batch_reset_hidden_prev = nullptr, + batch_hidden = nullptr; phi::DenseTensor batch_gate_tmp, batch_reset_hidden_prev_tmp, batch_hidden_tmp; if (is_test) { diff --git a/paddle/fluid/operators/interpolate_op.cc b/paddle/fluid/operators/interpolate_op.cc index 2bb9bf633f0c2..1af8b247de447 100644 --- a/paddle/fluid/operators/interpolate_op.cc +++ b/paddle/fluid/operators/interpolate_op.cc @@ -61,7 +61,7 @@ static void Interpolate1DInferShapeCheck(framework::InferShapeContext* ctx) { return; } - int out_w; + int out_w = 0; if (ctx->HasInput("Scale")) { auto scale_tensor = ctx->GetInputDim("Scale"); PADDLE_ENFORCE_EQ( @@ -151,7 +151,7 @@ static void Interpolate2DInferShapeCheck(framework::InferShapeContext* ctx) { return; } - int out_h, out_w; + int out_h = 0, out_w = 0; if (ctx->HasInput("Scale")) { auto scale_tensor = ctx->GetInputDim("Scale"); PADDLE_ENFORCE_EQ( @@ -247,7 +247,7 @@ static void Interpolate3DInferShapeCheck(framework::InferShapeContext* ctx) { return; } - int out_d, out_h, out_w; + int out_d = 0, out_h = 0, out_w = 0; if (ctx->HasInput("Scale")) { auto scale_tensor = ctx->GetInputDim("Scale"); PADDLE_ENFORCE_EQ( diff --git a/paddle/fluid/operators/math/tree2col.cc b/paddle/fluid/operators/math/tree2col.cc index 21eeb52fd311a..41c131de0f392 100644 --- a/paddle/fluid/operators/math/tree2col.cc +++ b/paddle/fluid/operators/math/tree2col.cc @@ -98,7 +98,7 @@ class Tree2ColFunctor { phi::funcs::SetConstant constant; int64_t feature_size = feature_dims[1]; size_t patch_elem_size = 3 * static_cast(feature_size); - size_t node_count = 0, patch_count = 0, patch_size; + size_t node_count = 0, patch_count = 0, patch_size = 0; Tree2ColUtil::construct_tree(EdgeSet, &tr, &node_count); std::vector> processing_list; for (size_t u = 1; u <= node_count; u++) { diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index 69c64de705645..df66ab400f40b 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -181,7 +181,7 @@ static phi::DenseTensor FoldHeadAndLastDims(const DeviceContext &context, */ static void ReshapeTensorIntoMatrixSequence( phi::DenseTensor *x, const phi::funcs::MatDescriptor &descriptor) { - int64_t h, w; + int64_t h = 0, w = 0; h = descriptor.height_; w = descriptor.width_; if (descriptor.trans_) { diff --git a/paddle/fluid/operators/merge_lod_tensor_op.cc b/paddle/fluid/operators/merge_lod_tensor_op.cc index ae00939d07844..3f0fd7bfef2dc 100644 --- a/paddle/fluid/operators/merge_lod_tensor_op.cc +++ b/paddle/fluid/operators/merge_lod_tensor_op.cc @@ -82,7 +82,7 @@ class MergeLoDTensorOp : public framework::OperatorBase { platform::Place place = dev_place; int64_t batch_size = in_true.dims()[0] + in_false.dims()[0]; auto data_type = in_true.IsInitialized() ? in_true.type() : in_false.type(); - int rank; + int rank = 0; framework::DDim in_dims; if (in_true.IsInitialized()) { rank = in_true.dims().size(); diff --git a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc index cf8197a04dd69..5cea8f5963111 100644 --- a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc +++ b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc @@ -53,7 +53,7 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase { place_str = place_str.substr(0, place_str.length() - 1); std::istringstream sin(place_str); sin.seekg(std::string("PLACE(GPU:").size(), std::ios::beg); // NOLINT - size_t num; + size_t num = 0; sin >> num; place = platform::CUDAPlace(static_cast(num)); } diff --git a/paddle/fluid/operators/reader/py_reader.cc b/paddle/fluid/operators/reader/py_reader.cc index 2db8ac6b1bcb9..f0c0409a729a5 100644 --- a/paddle/fluid/operators/reader/py_reader.cc +++ b/paddle/fluid/operators/reader/py_reader.cc @@ -31,7 +31,7 @@ PyReader::PyReader( } void PyReader::ReadNext(paddle::framework::LoDTensorArray* out) { - bool success; + bool success = false; *out = queue_->Pop(&success); if (!success) out->clear(); } diff --git a/paddle/fluid/operators/split_lod_tensor_op.cc b/paddle/fluid/operators/split_lod_tensor_op.cc index e648575a1edca..6b79d5c35b783 100644 --- a/paddle/fluid/operators/split_lod_tensor_op.cc +++ b/paddle/fluid/operators/split_lod_tensor_op.cc @@ -107,7 +107,7 @@ class SplitLoDTensorOp : public framework::OperatorBase { } for (size_t t = 0; t < 2; ++t) { - phi::DenseTensor *out; + phi::DenseTensor *out = nullptr; if (t == 0) { out = out_false; } else { diff --git a/paddle/fluid/operators/string/faster_tokenizer_op.cc b/paddle/fluid/operators/string/faster_tokenizer_op.cc index dd1e421e6cb1a..c24aca2906d67 100644 --- a/paddle/fluid/operators/string/faster_tokenizer_op.cc +++ b/paddle/fluid/operators/string/faster_tokenizer_op.cc @@ -146,7 +146,7 @@ void WordPieceTokenizer::Tokenize(const wstring& text, while (start < len) { size_t end = len; std::wstring cur_substr; - int64_t cur_substr_id; + int64_t cur_substr_id = 0; while (start < end) { std::wstring sub = text.substr(start, end - start); if (start > 0) { diff --git a/paddle/fluid/pir/transforms/pd_op_to_kernel_pass.cc b/paddle/fluid/pir/transforms/pd_op_to_kernel_pass.cc index eae6f20a34eaa..7d8f348f83c78 100644 --- a/paddle/fluid/pir/transforms/pd_op_to_kernel_pass.cc +++ b/paddle/fluid/pir/transforms/pd_op_to_kernel_pass.cc @@ -1269,7 +1269,7 @@ pir::Operation* BuildPhiKernelOp( pir::OpInfo legacy_kernel_op_info = ctx->GetRegisteredOpInfo(paddle::dialect::LegacyKernelOp::name()); - pir::Operation* op; + pir::Operation* op = nullptr; if (dialect::IsLegacyOp(op_item->name())) { op = pir::Operation::Create( vec_inputs, op_attribute, op_output_types, legacy_kernel_op_info); diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 67512474567d3..44c17c32fa8d5 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -139,8 +139,8 @@ RecordMemEvent::RecordMemEvent(const void *ptr, } if (type == TracerMemEventType::Allocate) { - uint64_t current_allocated; - uint64_t peak_allocated; + uint64_t current_allocated = 0; + uint64_t peak_allocated = 0; uint64_t current_reserved = 0; // 0 means keep the same as before uint64_t peak_reserved = 0; // 0 means keep the same as before if (platform::is_cpu_place(place) || @@ -223,8 +223,8 @@ RecordMemEvent::RecordMemEvent(const void *ptr, peak_allocated, peak_reserved); } else if (type == TracerMemEventType::ReservedAllocate) { - uint64_t current_reserved; - uint64_t peak_reserved; + uint64_t current_reserved = 0; + uint64_t peak_reserved = 0; uint64_t current_allocated = 0; // 0 means keep the same as before uint64_t peak_allocated = 0; // 0 means keep the same as before if (platform::is_cpu_place(place) || @@ -306,8 +306,8 @@ RecordMemEvent::RecordMemEvent(const void *ptr, peak_allocated, peak_reserved); } else if (type == TracerMemEventType::Free) { - uint64_t current_allocated; - uint64_t peak_allocated; + uint64_t current_allocated = 0; + uint64_t peak_allocated = 0; uint64_t current_reserved = 0; // 0 means keep the same as before uint64_t peak_reserved = 0; // 0 means keep the same as before if (platform::is_cpu_place(place) || @@ -389,8 +389,8 @@ RecordMemEvent::RecordMemEvent(const void *ptr, peak_allocated, peak_reserved); } else if (type == TracerMemEventType::ReservedFree) { - uint64_t current_reserved; - uint64_t peak_reserved; + uint64_t current_reserved = 0; + uint64_t peak_reserved = 0; uint64_t current_allocated = 0; // 0 means keep the same as before uint64_t peak_allocated = 0; // 0 means keep the same as before if (platform::is_cpu_place(place) || diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index e72f5dc77f99c..f7aa6151d9adc 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -844,7 +844,7 @@ static PyObject* tensor_clear_gradient(TensorObject* self, set_to_zero = CastPyArg2AttrBoolean(PyTuple_GET_ITEM(args, 0), 0); } - paddle::Tensor* grad; + paddle::Tensor* grad = nullptr; bool is_leaf = egr::EagerUtils::IsLeafTensor(self->tensor); if (is_leaf) { grad = egr::EagerUtils::mutable_grad(self->tensor); @@ -1729,7 +1729,7 @@ static PyObject* tensor_register_grad_hook(TensorObject* self, PyObject* args, PyObject* kwargs) { EAGER_TRY - int64_t hook_id; + int64_t hook_id = 0; if (egr::EagerUtils::IsLeafTensor(self->tensor)) { VLOG(6) << "Register hook for leaf tensor: " << self->tensor.name(); diff --git a/paddle/fluid/pybind/eager_utils.cc b/paddle/fluid/pybind/eager_utils.cc index 7d70ed174a4c8..3ad1b77d1d4ba 100644 --- a/paddle/fluid/pybind/eager_utils.cc +++ b/paddle/fluid/pybind/eager_utils.cc @@ -237,8 +237,8 @@ float CastPyArg2AttrFloat(PyObject* obj, ssize_t arg_pos) { std::string CastPyArg2AttrString(PyObject* obj, ssize_t arg_pos) { if (PyObject_CheckStr(obj)) { - Py_ssize_t size; - const char* data; + Py_ssize_t size = 0; + const char* data = nullptr; data = PyUnicode_AsUTF8AndSize(obj, &size); return std::string(data, static_cast(size)); } else { diff --git a/paddle/fluid/pybind/eval_frame.c b/paddle/fluid/pybind/eval_frame.c index a07f2033e4b4e..c0a709d5bd7c3 100644 --- a/paddle/fluid/pybind/eval_frame.c +++ b/paddle/fluid/pybind/eval_frame.c @@ -605,7 +605,7 @@ static PyObject *_custom_eval_frame(PyThreadState *tstate, PyCodeObject *code = (PyCodeObject *)PyObject_GetAttrString(result, "code"); PyObject *disable_eval_frame = PyObject_GetAttrString(result, "disable_eval_frame"); - PyObject *out; + PyObject *out = NULL; // VLOG(7) << "Start eval new frame and code."; if (disable_eval_frame != Py_True) { // Re-enable custom behavior diff --git a/paddle/fluid/pybind/op_function_common.cc b/paddle/fluid/pybind/op_function_common.cc index d28dc9bec4008..489b25f35867c 100644 --- a/paddle/fluid/pybind/op_function_common.cc +++ b/paddle/fluid/pybind/op_function_common.cc @@ -289,8 +289,8 @@ std::string CastPyArg2String(PyObject* obj, const std::string& op_type, ssize_t arg_pos) { if (PyObject_CheckString(obj)) { - Py_ssize_t size; - const char* data; + Py_ssize_t size = 0; + const char* data = nullptr; data = PyUnicode_AsUTF8AndSize(obj, &size); return std::string(data, (size_t)size); // NOLINT } else { @@ -696,8 +696,8 @@ std::vector CastPyArg2Strings(PyObject* obj, for (Py_ssize_t i = 0; i < len; i++) { item = PyList_GetItem(obj, i); if (PyObject_CheckString(item)) { - Py_ssize_t size; - const char* data; + Py_ssize_t size = 0; + const char* data = nullptr; data = PyUnicode_AsUTF8AndSize(item, &size); value.emplace_back(std::string(data, (size_t)size)); // NOLINT } else { @@ -716,8 +716,8 @@ std::vector CastPyArg2Strings(PyObject* obj, for (Py_ssize_t i = 0; i < len; i++) { item = PyTuple_GetItem(obj, i); if (PyObject_CheckString(item)) { - Py_ssize_t size; - const char* data; + Py_ssize_t size = 0; + const char* data = nullptr; data = PyUnicode_AsUTF8AndSize(item, &size); value.emplace_back(std::string(data, (size_t)size)); // NOLINT } else { @@ -896,8 +896,8 @@ void ConstructAttrMapFromPyArgs( PyObject* obj = nullptr; for (ssize_t arg_pos = attr_start; arg_pos < attr_end; arg_pos += 2) { VLOG(1) << "Start Process " << arg_pos; - Py_ssize_t key_len; - const char* key_ptr; + Py_ssize_t key_len = 0; + const char* key_ptr = nullptr; obj = PyTuple_GET_ITEM(args, arg_pos); if (PyObject_CheckString(obj)) { key_ptr = PyUnicode_AsUTF8AndSize(obj, &key_len); @@ -988,8 +988,8 @@ void ConstructAttrMapForRunProgram( PyObject* obj = nullptr; for (ssize_t arg_pos = attr_start; arg_pos < attr_end; arg_pos += 2) { VLOG(1) << "Start Process " << arg_pos; - Py_ssize_t key_len; - const char* key_ptr; + Py_ssize_t key_len = 0; + const char* key_ptr = nullptr; obj = PyTuple_GET_ITEM(args, arg_pos); if (PyObject_CheckString(obj)) { key_ptr = PyUnicode_AsUTF8AndSize(obj, &key_len); diff --git a/paddle/phi/api/lib/data_transform.cc b/paddle/phi/api/lib/data_transform.cc index 6fd1ddf87c4a2..5f28388d793a1 100644 --- a/paddle/phi/api/lib/data_transform.cc +++ b/paddle/phi/api/lib/data_transform.cc @@ -211,7 +211,7 @@ inline phi::DenseTensor TransDataPlace(const phi::DenseTensor& tensor, // But the embarrassment is that this solution this solution makes training // slower. phi::DenseTensor out; - phi::DeviceContext* dev_ctx; + phi::DeviceContext* dev_ctx = nullptr; if (dst_place.GetType() != AllocationType::CPU) { dev_ctx = pool.Get(dst_place); } else { diff --git a/paddle/phi/backends/context_pool.cc b/paddle/phi/backends/context_pool.cc index 619db6f83fc24..7824fc3b160b1 100644 --- a/paddle/phi/backends/context_pool.cc +++ b/paddle/phi/backends/context_pool.cc @@ -61,7 +61,7 @@ thread_local const std::map>>* - ptr; + ptr = nullptr; if (external_device_contexts_ && external_device_contexts_->count(place)) { ptr = external_device_contexts_; } else { diff --git a/paddle/phi/backends/dynload/dynamic_loader.cc b/paddle/phi/backends/dynload/dynamic_loader.cc index 6989f32b18e9e..96d060499afdb 100644 --- a/paddle/phi/backends/dynload/dynamic_loader.cc +++ b/paddle/phi/backends/dynload/dynamic_loader.cc @@ -185,9 +185,9 @@ static inline std::string join(const std::string& part1, static inline std::vector split( const std::string& str, const std::string separator = " ") { std::vector str_list; - std::string::size_type firstPos; + std::string::size_type firstPos = 0; firstPos = str.find_first_not_of(separator, 0); - std::string::size_type lastPos; + std::string::size_type lastPos = 0; lastPos = str.find_first_of(separator, firstPos); while (std::string::npos != firstPos && std::string::npos != lastPos) { str_list.push_back(str.substr(firstPos, lastPos - firstPos)); diff --git a/paddle/phi/core/distributed/store/tcp_store.cc b/paddle/phi/core/distributed/store/tcp_store.cc index 9650d051f98fb..6fbe2aa6761e2 100644 --- a/paddle/phi/core/distributed/store/tcp_store.cc +++ b/paddle/phi/core/distributed/store/tcp_store.cc @@ -421,7 +421,7 @@ std::vector TCPStore::get(const std::string& key) { } void TCPStore::wait(const std::string& key) { - ReplyType reply; + ReplyType reply; // NOLINT VLOG(7) << "TCPStore wait."; _client->send_command_for_key(Command::WAIT, _key_prefix + key); reply = _client->receive_value(); diff --git a/paddle/phi/core/distributed/store/tcp_utils.cc b/paddle/phi/core/distributed/store/tcp_utils.cc index aaf00cb800085..64c5424928b9f 100644 --- a/paddle/phi/core/distributed/store/tcp_utils.cc +++ b/paddle/phi/core/distributed/store/tcp_utils.cc @@ -44,7 +44,7 @@ ::addrinfo* get_addr_info(const std::string host, const std::string port, int ai_flags, int family) { - ::addrinfo hints{}, *res; + ::addrinfo hints{}, *res = nullptr; hints.ai_flags = ai_flags; hints.ai_family = family; hints.ai_socktype = SOCK_STREAM; @@ -52,7 +52,7 @@ ::addrinfo* get_addr_info(const std::string host, const char* node = host.empty() ? nullptr : host.c_str(); const char* port_cstr = port.empty() ? nullptr : port.c_str(); - int n; + int n = 0; n = ::getaddrinfo(node, port_cstr, &hints, &res); const char* gai_err = ::gai_strerror(n); const char* proto = (family == AF_INET ? "IPv4" @@ -216,7 +216,7 @@ void send_string(SocketType socket, const std::string& s) { } std::string receive_string(SocketType socket) { - std::string::size_type size; + std::string::size_type size = 0; receive_bytes(socket, &size, 1); std::vector v(size); receive_bytes(socket, v.data(), size); diff --git a/paddle/phi/core/generator.cc b/paddle/phi/core/generator.cc index 8cdbb290ea34f..4541b81de4630 100644 --- a/paddle/phi/core/generator.cc +++ b/paddle/phi/core/generator.cc @@ -242,7 +242,7 @@ uint64_t Generator::GetCurrentSeed() { uint64_t Generator::Seed() { std::lock_guard lock(this->mu_); - uint64_t seed; + uint64_t seed = 0; std::random_device de; seed = ((((uint64_t)de()) << 32) + de()) & 0x1FFFFFFFFFFFFF; this->state_.current_seed = seed; diff --git a/paddle/phi/infermeta/binary.cc b/paddle/phi/infermeta/binary.cc index a3028027ebdd8..641deab33bfdf 100644 --- a/paddle/phi/infermeta/binary.cc +++ b/paddle/phi/infermeta/binary.cc @@ -1435,7 +1435,7 @@ void FusedMatmulInferMeta(const MetaTensor& x, y_broadcasted = true; } - size_t M, N; + size_t M = 0, N = 0; if (transpose_x) { M = dims_x[ndims_x - 1]; } else { @@ -2136,7 +2136,7 @@ void MatmulInferMeta(const MetaTensor& x, y_broadcasted = true; } - size_t M, N; + size_t M = 0, N = 0; if (trans_x) { M = dims_x[ndims_x - 1]; } else { @@ -3028,7 +3028,7 @@ void YoloBoxInferMeta(const MetaTensor& x, "But received class_num (%s)", class_num)); - int box_num; + int box_num = 0; if ((dim_x[2] > 0 && dim_x[3] > 0) || config.is_runtime) { box_num = static_cast(dim_x[2] * dim_x[3] * anchor_num); } else { @@ -3103,7 +3103,7 @@ void SolveInferMeta(const MetaTensor& x, const MetaTensor& y, MetaTensor* out) { y_broadcasted = true; } - size_t M, N; + size_t M = 0, N = 0; if (trans_x) { M = x_dims_vec[x_dims_n - 1]; } else { diff --git a/paddle/phi/infermeta/multiary.cc b/paddle/phi/infermeta/multiary.cc index 8f78755486a7d..0cd5534a9c44a 100644 --- a/paddle/phi/infermeta/multiary.cc +++ b/paddle/phi/infermeta/multiary.cc @@ -1997,7 +1997,7 @@ static void Interpolate1DInferShapeCheck( return; } - int out_w_tmp; + int out_w_tmp = 0; if (scale_tensor) { auto scale_tensor_dim = scale_tensor.dims(); PADDLE_ENFORCE_EQ( @@ -2130,7 +2130,7 @@ static void Interpolate2DInferShapeCheck( return; } - int out_h_tmp, out_w_tmp; + int out_h_tmp = 0, out_w_tmp = 0; if (scale_tensor) { auto scale_tensor_dim = scale_tensor.dims(); @@ -2282,7 +2282,7 @@ static void Interpolate3DInferShapeCheck( return; } - int out_d_tmp, out_h_tmp, out_w_tmp; + int out_d_tmp = 0, out_h_tmp = 0, out_w_tmp = 0; if (scale_tensor) { auto scale_tensor_dim = scale_tensor.dims(); PADDLE_ENFORCE_EQ( diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index 1c57e2fae92ac..0e3ac3fb5ca2c 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -74,7 +74,7 @@ void EyeInferMeta(const Scalar& num_rows, DataType dtype, MetaTensor* out, MetaConfig config) { - int64_t rows, columns; + int64_t rows = 0, columns = 0; if (!config.is_runtime && num_rows.FromTensor()) { rows = -1; } else { diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 6eaff66c58389..89fc946156f35 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -555,7 +555,7 @@ void CumWithIndicesInferMeta(const MetaTensor& x, phi::errors::InvalidArgument("dtype of indices must be int32 or int64")); if (indices_type == DataType::INT32) { - int _axis; + int _axis = 0; if (axis < 0) { _axis = axis + x_dims.size(); } else { @@ -1682,11 +1682,11 @@ void FrameInferMeta(const MetaTensor& x, "Attribute(axis) of FrameOp should 0 or -1, but got %s.", axis)); std::vector output_shape; - int seq_length; - int n_frames; + int seq_length = 0; + int n_frames = 0; - int start_axis; - int end_axis; + int start_axis = 0; + int end_axis = 0; if (axis == 0) { seq_length = static_cast(x_dims[0]); @@ -2566,12 +2566,12 @@ void OverlapAddInferMeta(const MetaTensor& x, "Attribute(axis) of OverlapAddOp should 0 or -1, but got %s.", axis)); std::vector output_shape; - int n_frames; - int frame_length; - int seq_length; + int n_frames = 0; + int frame_length = 0; + int seq_length = 0; - int start_axis; - int end_axis; + int start_axis = 0; + int end_axis = 0; if (axis == 0) { n_frames = static_cast(x_dims[0]); frame_length = static_cast(x_dims[1]); @@ -3143,8 +3143,8 @@ void QrInferMeta(const MetaTensor& x, x_dims.size(), 2, phi::errors::InvalidArgument("the rank of input must greater than 2")); - bool compute_q; - bool reduced_mode; + bool compute_q = false; + bool reduced_mode = false; int m = static_cast(x_dims[x_rank - 2]); int n = static_cast(x_dims[x_rank - 1]); int min_mn = std::min(m, n); diff --git a/paddle/phi/kernels/cpu/allclose_kernel.cc b/paddle/phi/kernels/cpu/allclose_kernel.cc index c6a512aa95cb1..fd6cf3aebc268 100644 --- a/paddle/phi/kernels/cpu/allclose_kernel.cc +++ b/paddle/phi/kernels/cpu/allclose_kernel.cc @@ -30,7 +30,7 @@ void AllCloseKernel(const Context& dev_ctx, const Scalar& atol, bool equal_nan, DenseTensor* out) { - double rtol_v, atol_v; + double rtol_v = NAN, atol_v = NAN; if (rtol.dtype() == DataType::FLOAT64) { rtol_v = rtol.to(); } else if (rtol.dtype() == DataType::FLOAT32) { @@ -58,7 +58,7 @@ void AllCloseKernel(const Context& dev_ctx, auto num = x.numel(); for (int64_t i = 0; i < num; ++i) { const T a = in_a[i], b = in_b[i]; - bool val; + bool val = false; if (std::isnan(a) || std::isnan(b)) { val = equal_nan && std::isnan(a) == std::isnan(b); } else { diff --git a/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc b/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc index 7a95e47047a10..071140a2a5420 100644 --- a/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc @@ -51,8 +51,8 @@ void CumprodGradKernel(const Context& dev_ctx, size_t numel = outer_dim * mid_dim * inner_dim; // deal with complex - const T* x_data_deal; - const T* out_data_deal; + const T* x_data_deal = nullptr; + const T* out_data_deal = nullptr; Allocator::AllocationPtr x_conj; Allocator::AllocationPtr out_conj; if (phi::IsComplexType(x.dtype())) { diff --git a/paddle/phi/kernels/cpu/diag_kernel.cc b/paddle/phi/kernels/cpu/diag_kernel.cc index 1576d80b15206..fb15fcbe61f7e 100644 --- a/paddle/phi/kernels/cpu/diag_kernel.cc +++ b/paddle/phi/kernels/cpu/diag_kernel.cc @@ -32,7 +32,7 @@ void DiagKernel(const Context& dev_ctx, T* out_data = dev_ctx.template Alloc(out); auto out_dims = out->dims(); - int64_t i; + int64_t i = 0; if (x_dims.size() <= 1) { phi::funcs::SetConstant set_padding_value; set_padding_value(dev_ctx, out, static_cast(padding_value)); diff --git a/paddle/phi/kernels/cpu/distribute_fpn_proposals_kernel.cc b/paddle/phi/kernels/cpu/distribute_fpn_proposals_kernel.cc index b8156459f2a92..aabca4c852e04 100644 --- a/paddle/phi/kernels/cpu/distribute_fpn_proposals_kernel.cc +++ b/paddle/phi/kernels/cpu/distribute_fpn_proposals_kernel.cc @@ -46,7 +46,7 @@ void DistributeFpnProposalsKernel( } std::vector fpn_rois_lod; - int fpn_rois_num; + int fpn_rois_num = 0; if (rois_num.get_ptr()) { fpn_rois_lod = funcs::GetLodFromRoisNum(dev_ctx, rois_num.get_ptr()); } else { diff --git a/paddle/phi/kernels/cpu/eigvals_kernel.cc b/paddle/phi/kernels/cpu/eigvals_kernel.cc index b0fc48db5739c..cd4aaca2ecf83 100644 --- a/paddle/phi/kernels/cpu/eigvals_kernel.cc +++ b/paddle/phi/kernels/cpu/eigvals_kernel.cc @@ -216,7 +216,7 @@ void EigvalsKernel(const Context& ctx, const DenseTensor& x, DenseTensor* out) { // query workspace size T qwork; - int info; + int info = 0; funcs::lapackEig>('N', 'N', static_cast(n_dim), diff --git a/paddle/phi/kernels/cpu/group_norm_kernel.cc b/paddle/phi/kernels/cpu/group_norm_kernel.cc index a041c85534675..35975018dca1c 100644 --- a/paddle/phi/kernels/cpu/group_norm_kernel.cc +++ b/paddle/phi/kernels/cpu/group_norm_kernel.cc @@ -91,7 +91,7 @@ void GroupNormKernel(const Context& dev_ctx, if (data_layout == DataLayout::kNCHW) { for (int cid = 0; cid < number; cid++) { - int imid; + int imid = 0; for (imid = 0; imid < imsize - (imsize % M); imid += M, iter_x_data += M) { // TODO(gaoxiang): Because AVX/AVX2/AVX512 can not directly used @@ -128,7 +128,7 @@ void GroupNormKernel(const Context& dev_ctx, } else { for (int cid = 0; cid < number; cid++) { iter_x_data = tmp_x + cid; - int imid; + int imid = 0; for (imid = 0; imid < imsize - (imsize % M); imid += M, iter_x_data += M * C) { // TODO(gaoxiang): Because AVX/AVX2/AVX512 can not directly used diff --git a/paddle/phi/kernels/cpu/instance_norm_grad_kernel.cc b/paddle/phi/kernels/cpu/instance_norm_grad_kernel.cc index 7d5f60731f13d..14937ea613936 100644 --- a/paddle/phi/kernels/cpu/instance_norm_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/instance_norm_grad_kernel.cc @@ -170,7 +170,7 @@ void InstanceNormDoubleGradKernel(const Context& dev_ctx, const auto* ddBias = ddbias.get_ptr(); phi::funcs::SetConstant set_constant; const auto& x_dims = x.dims(); - int N, C, H, W, D; + int N = 0, C = 0, H = 0, W = 0, D = 0; funcs::ExtractNCWHD(x_dims, DataLayout::kNCHW, &N, &C, &H, &W, &D); const int sample_size = static_cast(x.numel() / N / C); const int NxC = N * C; diff --git a/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc b/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc index f1478d5e3b3e7..e32738b4588c8 100644 --- a/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc @@ -407,7 +407,7 @@ static void Interpolate1DCPUBwd( int align_mode, DenseTensor* input_grad) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_w = -1.0; @@ -508,7 +508,7 @@ static void Interpolate2DCPUBwd( int align_mode, DenseTensor* input_grad) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_h = -1; @@ -674,7 +674,7 @@ static void Interpolate3DCPUBwd( int align_mode, DenseTensor* input_grad) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_d = -1; diff --git a/paddle/phi/kernels/cpu/interpolate_kernel.cc b/paddle/phi/kernels/cpu/interpolate_kernel.cc index 198cba7d1e948..7c957657ceb39 100644 --- a/paddle/phi/kernels/cpu/interpolate_kernel.cc +++ b/paddle/phi/kernels/cpu/interpolate_kernel.cc @@ -561,7 +561,7 @@ static void Interpolate1DCPUFwd( int align_mode, DenseTensor* output) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(x.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_w = -1.; @@ -662,7 +662,7 @@ static void Interpolate2DCPUFwd( int align_mode, DenseTensor* output) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(x.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_h = -1; @@ -833,7 +833,7 @@ static void Interpolate3DCPUFwd( int align_mode, DenseTensor* output) { const DataLayout data_layout = phi::StringToDataLayout(data_layout_str); - int n, c, in_d, in_h, in_w; + int n = 0, c = 0, in_d = 0, in_h = 0, in_w = 0; funcs::ExtractNCDWH(x.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); float scale_d = -1; diff --git a/paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc b/paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc index 3d21c49ee1e2b..0713725127190 100644 --- a/paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc +++ b/paddle/phi/kernels/cpu/matrix_rank_tol_kernel.cc @@ -39,7 +39,7 @@ void LapackSVD(const T* x_data, T* eigenvalues_data, int rows, int cols) { int lwork = 3 * mn + std::max(mx, 7 * mn); std::vector work(lwork); std::vector iwork(8 * mn); - int info; + int info = 0; phi::funcs::lapackSvd(jobz, rows, diff --git a/paddle/phi/kernels/cpu/multiclass_nms3_kernel.cc b/paddle/phi/kernels/cpu/multiclass_nms3_kernel.cc index 336af33d8679b..aa04288124a9b 100644 --- a/paddle/phi/kernels/cpu/multiclass_nms3_kernel.cc +++ b/paddle/phi/kernels/cpu/multiclass_nms3_kernel.cc @@ -381,7 +381,7 @@ void MultiClassNMS(const Context& ctx, *num_nmsed_out = num_det; const T* scores_data = scores.data(); if (keep_top_k > -1 && num_det > keep_top_k) { - const T* sdata; + const T* sdata = nullptr; std::vector>> score_index_pairs; for (const auto& it : *indices) { int label = it.first; @@ -441,7 +441,7 @@ void MultiClassOutput(const Context& ctx, auto* scores_data = scores.data(); auto* bboxes_data = bboxes.data(); auto* odata = out->data(); - const T* sdata; + const T* sdata = nullptr; DenseTensor bbox; bbox.Resize({scores.dims()[0], box_size}); int count = 0; @@ -456,7 +456,7 @@ void MultiClassOutput(const Context& ctx, for (auto idx : indices) { odata[count * out_dim] = label; // label - const T* bdata; + const T* bdata = nullptr; if (scores_size == 3) { bdata = bboxes_data + idx * box_size; odata[count * out_dim + 1] = sdata[idx]; // score diff --git a/paddle/phi/kernels/cpu/norm_grad_kernel.cc b/paddle/phi/kernels/cpu/norm_grad_kernel.cc index 6d51a64c76bb1..8bc46fa6cdffc 100644 --- a/paddle/phi/kernels/cpu/norm_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/norm_grad_kernel.cc @@ -40,7 +40,7 @@ void NormGradKernel(const Context& ctx, auto xdim = in_x->dims(); if (axis < 0) axis = xdim.size() + axis; - int pre, n, post; + int pre = 0, n = 0, post = 0; funcs::GetPrePostNumel(xdim, axis, &pre, &n, &post); auto* place = ctx.eigen_device(); diff --git a/paddle/phi/kernels/cpu/norm_kernel.cc b/paddle/phi/kernels/cpu/norm_kernel.cc index 21af086515d71..73540f8360592 100644 --- a/paddle/phi/kernels/cpu/norm_kernel.cc +++ b/paddle/phi/kernels/cpu/norm_kernel.cc @@ -33,10 +33,10 @@ void NormKernel(const Context& ctx, auto xdim = x.dims(); T eps = epsilon; if (axis < 0) axis = xdim.size() + axis; - int pre, n, post; + int pre = 0, n = 0, post = 0; funcs::GetPrePostNumel(xdim, axis, &pre, &n, &post); - DenseTensor* out_norm; + DenseTensor* out_norm = nullptr; DenseTensor out_norm_tmp; if (is_test) { auto out_dim = x.dims(); diff --git a/paddle/phi/kernels/cpu/p_norm_kernel.cc b/paddle/phi/kernels/cpu/p_norm_kernel.cc index 7a683438176bb..3a837c96ec58a 100644 --- a/paddle/phi/kernels/cpu/p_norm_kernel.cc +++ b/paddle/phi/kernels/cpu/p_norm_kernel.cc @@ -58,7 +58,7 @@ void PNormKernel(const Context& dev_ctx, auto xdim = in_x->dims(); if (axis < 0) axis = xdim.size() + axis; - int pre, n, post; + int pre = 0, n = 0, post = 0; GetDims(xdim, axis, &pre, &n, &post, asvector); for (int i = 0; i < xdim.size(); i++) { diff --git a/paddle/phi/kernels/cpu/psroi_pool_grad_kernel.cc b/paddle/phi/kernels/cpu/psroi_pool_grad_kernel.cc index 17539957a0d44..3a517cfa1fb61 100644 --- a/paddle/phi/kernels/cpu/psroi_pool_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/psroi_pool_grad_kernel.cc @@ -43,7 +43,7 @@ void PsroiPoolGradKernel(const Context& ctx, DenseTensor rois_batch_id_list; rois_batch_id_list.Resize({rois_num_t}); int* rois_batch_id_data = ctx.template Alloc(&rois_batch_id_list); - int rois_batch_size; + int rois_batch_size = 0; if (rois_num.get_ptr()) { rois_batch_size = static_cast(rois_num->numel()); auto* rois_num_t_data = rois_num->data(); diff --git a/paddle/phi/kernels/cpu/psroi_pool_kernel.cc b/paddle/phi/kernels/cpu/psroi_pool_kernel.cc index fe48ee9e7e88e..3b15135133049 100644 --- a/paddle/phi/kernels/cpu/psroi_pool_kernel.cc +++ b/paddle/phi/kernels/cpu/psroi_pool_kernel.cc @@ -53,7 +53,7 @@ void PsroiPoolKernel(const Context& ctx, rois_batch_id_list.Resize({rois_num_t}); int* rois_batch_id_data = ctx.template Alloc(&rois_batch_id_list); - int rois_batch_size; + int rois_batch_size = 0; if (rois_num.get_ptr()) { rois_batch_size = static_cast(rois_num->numel()); auto* rois_num_data = rois_num->data(); diff --git a/paddle/phi/kernels/cpu/qr_kernel.cc b/paddle/phi/kernels/cpu/qr_kernel.cc index ac61e8e172ae6..194906ae1dc34 100644 --- a/paddle/phi/kernels/cpu/qr_kernel.cc +++ b/paddle/phi/kernels/cpu/qr_kernel.cc @@ -29,8 +29,8 @@ void QrKernel(const Context& ctx, const std::string& mode, DenseTensor* q, DenseTensor* r) { - bool compute_q; - bool reduced_mode; + bool compute_q = false; + bool reduced_mode = false; std::tie(compute_q, reduced_mode) = phi::funcs::ParseQrMode(mode); auto numel = x.numel(); PADDLE_ENFORCE_GT( diff --git a/paddle/phi/kernels/cpu/roi_align_grad_kernel.cc b/paddle/phi/kernels/cpu/roi_align_grad_kernel.cc index 81868afc46318..119f4ea1b0ac4 100644 --- a/paddle/phi/kernels/cpu/roi_align_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/roi_align_grad_kernel.cc @@ -29,7 +29,7 @@ void bilinear_interpolate_gradient(const int height, const T out_grad_this_bin, const T count, T* batch_grad_data) { - int x_low, y_low, x_high, y_high; + int x_low = 0, y_low = 0, x_high = 0, y_high = 0; T w1, w2, w3, w4; if (y < -1.0 || y > height || x < -1.0 || x > width) { w1 = w2 = w3 = w4 = 0; @@ -94,7 +94,7 @@ void RoiAlignGradKernel(const Context& dev_ctx, DenseTensor roi_batch_id_list = Empty(dev_ctx, {rois_num}); int* box_batch_id_data = roi_batch_id_list.data(); - int boxes_batch_size; + int boxes_batch_size = 0; if (boxes_num) { boxes_batch_size = static_cast(boxes_num->numel()); auto* boxes_num_data = boxes_num->data(); diff --git a/paddle/phi/kernels/cpu/roi_pool_grad_kernel.cc b/paddle/phi/kernels/cpu/roi_pool_grad_kernel.cc index 704a2b4b610fc..e25a581cbd9dd 100644 --- a/paddle/phi/kernels/cpu/roi_pool_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/roi_pool_grad_kernel.cc @@ -37,7 +37,7 @@ void RoiPoolGradKernel(const Context& dev_ctx, DenseTensor box_batch_id_list = Empty(dev_ctx, {rois_num}); int* box_batch_id_data = box_batch_id_list.data(); - int boxes_batch_size; + int boxes_batch_size = 0; if (boxes_num) { boxes_batch_size = static_cast(boxes_num->numel()); auto* boxes_num_data = boxes_num->data(); diff --git a/paddle/phi/kernels/cpu/svd_kernel.cc b/paddle/phi/kernels/cpu/svd_kernel.cc index 1ae2d9cce0d40..a3f6f38fe4780 100644 --- a/paddle/phi/kernels/cpu/svd_kernel.cc +++ b/paddle/phi/kernels/cpu/svd_kernel.cc @@ -35,7 +35,7 @@ void LapackSvd( int lwork = full ? (4 * mn * mn + 6 * mn + mx) : (4 * mn * mn + 7 * mn); std::vector work(lwork); std::vector iwork(8 * mn); - int info; + int info = 0; phi::funcs::lapackSvd(jobz, rows, cols, diff --git a/paddle/phi/kernels/cpu/yolo_loss_grad_kernel.cc b/paddle/phi/kernels/cpu/yolo_loss_grad_kernel.cc index 75fcf48cd4acf..c876718d8a8b1 100644 --- a/paddle/phi/kernels/cpu/yolo_loss_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/yolo_loss_grad_kernel.cc @@ -169,7 +169,7 @@ void YoloLossGradKernel(const Context& dev_ctx, T* input_grad_data = dev_ctx.template Alloc(input_grad); memset(input_grad_data, 0, input_grad->numel() * sizeof(T)); - const T* gt_score_data; + const T* gt_score_data = nullptr; DenseTensor gtscore; if (!(gt_score.is_initialized())) { gtscore.Resize({n, b}); diff --git a/paddle/phi/kernels/cpu/yolo_loss_kernel.cc b/paddle/phi/kernels/cpu/yolo_loss_kernel.cc index 275e83cc9b40f..280ac791d049b 100644 --- a/paddle/phi/kernels/cpu/yolo_loss_kernel.cc +++ b/paddle/phi/kernels/cpu/yolo_loss_kernel.cc @@ -229,7 +229,7 @@ void YoloLossKernel(const Context& dev_ctx, gt_match_mask->Resize({n, b}); int* gt_match_mask_data = dev_ctx.template Alloc(gt_match_mask); - const T* gt_score_data; + const T* gt_score_data = nullptr; DenseTensor gtscore; if (!(gt_score.is_initialized())) { gtscore.Resize({n, b}); diff --git a/paddle/phi/kernels/funcs/gather_scatter_functor.cc b/paddle/phi/kernels/funcs/gather_scatter_functor.cc index 2b667c32d9db3..597b8f231760b 100644 --- a/paddle/phi/kernels/funcs/gather_scatter_functor.cc +++ b/paddle/phi/kernels/funcs/gather_scatter_functor.cc @@ -92,7 +92,7 @@ struct cpu_gather_scatter_functor { outer_dim_size *= index_dims[i]; } int64_t index_idx = 0; - int64_t self_idx, src_idx; + int64_t self_idx = 0, src_idx = 0; // N layer loop squeezed into 3 layers loop for (int64_t i = 0; i < inner_dim_size; i++) { diff --git a/paddle/phi/kernels/funcs/gpc.cc b/paddle/phi/kernels/funcs/gpc.cc index b3199d88f5888..47a3001b4fda2 100644 --- a/paddle/phi/kernels/funcs/gpc.cc +++ b/paddle/phi/kernels/funcs/gpc.cc @@ -87,7 +87,7 @@ const std::array, 3> next_h_state = { */ static void reset_it(it_node **it) { - it_node *itn; + it_node *itn = nullptr; while (*it) { itn = (*it)->next; @@ -97,7 +97,7 @@ static void reset_it(it_node **it) { } static void reset_lmt(lmt_node **lmt) { - lmt_node *lmtn; + lmt_node *lmtn = nullptr; while (*lmt) { lmtn = (*lmt)->next; @@ -140,7 +140,7 @@ static void insert_bound(edge_node **b, edge_node *e) { } static edge_node **bound_list(lmt_node **lmt, double y) { - lmt_node *existing_node; + lmt_node *existing_node = nullptr; if (!*lmt) { /* Add node onto the tail end of the LMT */ @@ -407,7 +407,7 @@ static void add_edge_to_aet(edge_node **aet, edge_node *edge, edge_node *prev) { static void add_intersection( it_node **it, edge_node *edge0, edge_node *edge1, double x, double y) { - it_node *existing_node; + it_node *existing_node = nullptr; if (!*it) { /* Append a new node to the tail of the list */ @@ -440,7 +440,7 @@ static void add_st_edge(st_node **st, it_node **it, edge_node *edge, double dy) { - st_node *existing_node; + st_node *existing_node = nullptr; double den = 0.0; double r = 0.0; double x = 0.0; @@ -486,8 +486,8 @@ static void add_st_edge(st_node **st, } static void build_intersection_table(it_node **it, edge_node *aet, double dy) { - st_node *st; - st_node *stp; + st_node *st = nullptr; + st_node *stp = nullptr; edge_node *edge = nullptr; /* Build intersection table for the current scanbeam */ @@ -706,7 +706,7 @@ static void new_tristrip(polygon_node **tn, } static bbox *create_contour_bboxes(gpc_polygon *p) { - bbox *box; + bbox *box = nullptr; int c = 0; int v = 0; @@ -744,8 +744,8 @@ static bbox *create_contour_bboxes(gpc_polygon *p) { } static void minimax_test(gpc_polygon *subj, gpc_polygon *clip, gpc_op op) { - bbox *s_bbox; - bbox *c_bbox; + bbox *s_bbox = nullptr; + bbox *c_bbox = nullptr; int s = 0; int c = 0; int *o_table = nullptr; diff --git a/paddle/phi/kernels/funcs/im2col.cc b/paddle/phi/kernels/funcs/im2col.cc index e4c470e1a7064..44dd15ead335b 100644 --- a/paddle/phi/kernels/funcs/im2col.cc +++ b/paddle/phi/kernels/funcs/im2col.cc @@ -137,7 +137,7 @@ class Col2ImFunctor { int im_col_idx = w * stride[1] - padding[1] + w_offset * dilation[1]; if ((im_row_idx) >= 0 && (im_row_idx) < im_height && (im_col_idx) >= 0 && (im_col_idx) < im_width) { - int im_offset; + int im_offset = 0; if (data_layout != DataLayout::kNHWC) { im_offset = (c_im * im_height + im_row_idx) * im_width + im_col_idx; diff --git a/paddle/phi/kernels/funcs/jit/gen_base.cc b/paddle/phi/kernels/funcs/jit/gen_base.cc index a80f9817c476a..3758aaf4cace8 100644 --- a/paddle/phi/kernels/funcs/jit/gen_base.cc +++ b/paddle/phi/kernels/funcs/jit/gen_base.cc @@ -47,7 +47,7 @@ void GenBase::dumpCode(const unsigned char* code) const { } void* GenBase::operator new(size_t size) { - void* ptr; + void* ptr = nullptr; constexpr size_t alignment = 32ul; #ifdef _WIN32 ptr = _aligned_malloc(size, alignment); @@ -71,8 +71,8 @@ void GenBase::operator delete(void* ptr) { } std::vector packed_groups(int n, int k, int* block_out, int* rest_out) { - int block; - int max_num_regs; + int block = 0; + int max_num_regs = 0; if (phi::backends::cpu::MayIUse(phi::backends::cpu::avx512f)) { block = ZMM_FLOAT_BLOCK; max_num_regs = 32; diff --git a/paddle/phi/kernels/funcs/jit/helper.cc b/paddle/phi/kernels/funcs/jit/helper.cc index 5c93637649f89..c135d6ee3177d 100644 --- a/paddle/phi/kernels/funcs/jit/helper.cc +++ b/paddle/phi/kernels/funcs/jit/helper.cc @@ -104,7 +104,7 @@ KernelType to_kerneltype(const std::string& act) { template <> void pack_weights(const float* src, float* dst, int n, int k) { - int block, rest; + int block = 0, rest = 0; const auto groups = packed_groups(n, k, &block, &rest); std::for_each(groups.begin(), groups.end(), [&](int i) { PADDLE_ENFORCE_GT(i, diff --git a/paddle/phi/kernels/funcs/jit/more/intrinsic/layer_norm.cc b/paddle/phi/kernels/funcs/jit/more/intrinsic/layer_norm.cc index d7d62d6815501..4b50de277a9c2 100644 --- a/paddle/phi/kernels/funcs/jit/more/intrinsic/layer_norm.cc +++ b/paddle/phi/kernels/funcs/jit/more/intrinsic/layer_norm.cc @@ -44,8 +44,8 @@ void LayerNorm(float* x, __m256 mean_vec, var_vec; __m128 hi, lo; __m256 tmp = _mm256_setzero_ps(); - size_t offset; - size_t j; + size_t offset = 0; + size_t j = 0; __m256 reverse_num_vec = _mm256_div_ps( _mm256_set1_ps(1.0), _mm256_set1_ps(static_cast(right))); __m256 epsilon_vec = _mm256_set1_ps(epsilon); diff --git a/paddle/phi/kernels/funcs/maxouting.cc b/paddle/phi/kernels/funcs/maxouting.cc index 40b184865a520..9c32453511f75 100644 --- a/paddle/phi/kernels/funcs/maxouting.cc +++ b/paddle/phi/kernels/funcs/maxouting.cc @@ -43,7 +43,7 @@ void MaxOutFunctor::operator()(const DeviceContext& context, int new_cindex = fea_size * c; for (int f = 0; f < fea_size; ++f) { T ele = static_cast(-FLT_MAX); - int input_idx, output_idx; + int input_idx = 0, output_idx = 0; for (int ph = 0; ph < groups; ++ph) { if (axis == 1) { input_idx = (new_bindex + new_cindex) * groups + ph * fea_size + f; @@ -89,7 +89,7 @@ void MaxOutGradFunctor::operator()( for (int c = 0; c < output_channels; ++c) { int clen = fea_size * c; for (int f = 0; f < fea_size; ++f) { - int input_idx0, output_idx; + int input_idx0 = 0, output_idx = 0; bool continue_match = true; if (axis == 1) { input_idx0 = (blen + clen) * groups + f; diff --git a/paddle/phi/kernels/funcs/pooling.cc b/paddle/phi/kernels/funcs/pooling.cc index ae68da49653ff..0573430c2010c 100644 --- a/paddle/phi/kernels/funcs/pooling.cc +++ b/paddle/phi/kernels/funcs/pooling.cc @@ -1592,8 +1592,8 @@ class MaxPool2dWithIndexFunctor { T1* output_data = context.template Alloc(output); T2* mask_data = context.template Alloc(mask); - int hstart, hend; - int wstart, wend; + int hstart = 0, hend = 0; + int wstart = 0, wend = 0; for (int i = 0; i < batch_size; i++) { for (int c = 0; c < output_channels; ++c) { for (int ph = 0; ph < output_height; ++ph) { @@ -1730,9 +1730,9 @@ class MaxPool3dWithIndexFunctor { T1* output_data = context.template Alloc(output); T2* mask_data = context.template Alloc(mask); - int dstart, dend; - int hstart, hend; - int wstart, wend; + int dstart = 0, dend = 0; + int hstart = 0, hend = 0; + int wstart = 0, wend = 0; for (int i = 0; i < batch_size; i++) { for (int c = 0; c < output_channels; ++c) { for (int pd = 0; pd < output_depth; ++pd) { diff --git a/paddle/phi/kernels/funcs/vol2col.cc b/paddle/phi/kernels/funcs/vol2col.cc index e505fcb3de337..b5d6086feda77 100644 --- a/paddle/phi/kernels/funcs/vol2col.cc +++ b/paddle/phi/kernels/funcs/vol2col.cc @@ -123,7 +123,7 @@ class Vol2ColFunctor { int64_t col_idx = ((c * output_depth + d) * output_height + h) * output_width + w; - int64_t vol_idx; + int64_t vol_idx = 0; if (data_layout != DataLayout::kNHWC) { vol_idx = ((c_in * input_depth + d_pad) * input_height + h_pad) * input_width + @@ -248,7 +248,7 @@ class Col2VolFunctor { if (h_pad >= 0 && h_pad < input_height && w_pad >= 0 && w_pad < input_width && d_pad >= 0 && d_pad < input_depth) { - int vol_idx; + int vol_idx = 0; if (data_layout != DataLayout::kNHWC) { vol_idx = ((cIm * input_depth + d_pad) * input_height + h_pad) * input_width + diff --git a/paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc b/paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc index 78d34fa14295c..1deddcf6dc0fa 100644 --- a/paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc +++ b/paddle/phi/kernels/selected_rows/cpu/adam_kernel.cc @@ -118,7 +118,7 @@ void AdamDenseParamSparseGradKernel( } phi::SelectedRows tmp_grad_merge; - const phi::SelectedRows* grad_merge_ptr; + const phi::SelectedRows* grad_merge_ptr = nullptr; if (is_strict_sorted) { grad_merge_ptr = &grad; } else { diff --git a/paddle/phi/kernels/stride/diagonal_kernel.cc b/paddle/phi/kernels/stride/diagonal_kernel.cc index e8929e6773f53..b4ca6d9b277df 100644 --- a/paddle/phi/kernels/stride/diagonal_kernel.cc +++ b/paddle/phi/kernels/stride/diagonal_kernel.cc @@ -36,7 +36,7 @@ void DiagonalStridedKernel(const Context& dev_ctx, axis2 += static_cast(x_rank); } - int64_t diag_size; + int64_t diag_size = 0; int64_t x_offset = static_cast(x.offset()); if (offset >= 0) { diag_size = std::max( diff --git a/paddle/phi/ops/compat/strided_slice_sig.cc b/paddle/phi/ops/compat/strided_slice_sig.cc index 02b3914787866..0c0e5d0c868f4 100644 --- a/paddle/phi/ops/compat/strided_slice_sig.cc +++ b/paddle/phi/ops/compat/strided_slice_sig.cc @@ -57,7 +57,7 @@ KernelSignature StridedSliceOpArgumentMapping( "decrease_axis"}; paddle::small_vector outputs = {"Out"}; - const char* kernel_name; + const char* kernel_name = nullptr; if (ctx.IsDenseTensorVectorInput("Input")) { kernel_name = "strided_slice_array"; } else { @@ -106,7 +106,7 @@ KernelSignature StridedSliceGradOpArgumentMapping( "decrease_axis"}; paddle::small_vector outputs = {"Input@GRAD"}; - const char* kernel_name; + const char* kernel_name = nullptr; if (ctx.IsDenseTensorVectorInput("Input")) { kernel_name = "strided_slice_array_grad"; } else { diff --git a/paddle/utils/flags_native_test.cc b/paddle/utils/flags_native_test.cc index 26ef8c12c1875..397072bf2914b 100644 --- a/paddle/utils/flags_native_test.cc +++ b/paddle/utils/flags_native_test.cc @@ -52,8 +52,8 @@ TEST(flags_native_test, ParseCommandLineFlags) { std::string commandline = "test --paddle_test_int32=3 --paddle_test_uint32=\"4\" " "--paddle_test_string \"modified string\""; - int argc; - char** argv; + int argc = 0; + char** argv = nullptr; SplitCommandlineArg(commandline, &argc, &argv); // Parse commandline flags and check diff --git a/test/cpp/fluid/math/im2col_test.cc b/test/cpp/fluid/math/im2col_test.cc index fab3086a820f2..f3925bce95869 100644 --- a/test/cpp/fluid/math/im2col_test.cc +++ b/test/cpp/fluid/math/im2col_test.cc @@ -89,7 +89,7 @@ void testIm2col() { std::array out_cfo_data = {0, 1, 1, 2, 3, 4, 4, 5}; std::array out_ocf_data = {0, 1, 3, 4, 1, 2, 4, 5}; - float* out_cfo_ptr; + float* out_cfo_ptr = nullptr; if (paddle::platform::is_cpu_place(*place)) { out_cfo_ptr = output_cfo.data(); } else { @@ -101,7 +101,7 @@ void testIm2col() { EXPECT_EQ(out_cfo_ptr[i], out_cfo_data[i]); } - float* out_ocf_ptr; + float* out_ocf_ptr = nullptr; if (paddle::platform::is_cpu_place(*place)) { out_ocf_ptr = output_ocf.data(); } else { @@ -130,7 +130,7 @@ void testIm2col() { col2im(*context, output_cfo, dilation, stride, padding, &input); - float* in_ptr; + float* in_ptr = nullptr; if (paddle::platform::is_cpu_place(*place)) { in_ptr = input.data(); } else { diff --git a/test/cpp/fluid/math/vol2col_test.cc b/test/cpp/fluid/math/vol2col_test.cc index 27a873082a119..9a6f14c3685cb 100644 --- a/test/cpp/fluid/math/vol2col_test.cc +++ b/test/cpp/fluid/math/vol2col_test.cc @@ -91,7 +91,7 @@ void testVol2col() { std::array vol_2_col = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11}; - float* out_cfo_ptr; + float* out_cfo_ptr = nullptr; if (paddle::platform::is_cpu_place(*place)) { out_cfo_ptr = output.data(); } else { @@ -116,7 +116,7 @@ void testVol2col() { phi::funcs::Col2VolFunctor col2vol; col2vol(*context, output, dilations, strides, paddings, &input); - float* in_ptr; + float* in_ptr = nullptr; if (paddle::platform::is_cpu_place(*place)) { in_ptr = input.data(); } else { diff --git a/test/cpp/fluid/reader/reader_blocking_queue_test.cc b/test/cpp/fluid/reader/reader_blocking_queue_test.cc index 7db47f0761853..b02f21eb2eb49 100644 --- a/test/cpp/fluid/reader/reader_blocking_queue_test.cc +++ b/test/cpp/fluid/reader/reader_blocking_queue_test.cc @@ -40,7 +40,7 @@ void FirstInFirstOut(size_t queue_cap, size_t count = 0; while (true) { std::this_thread::sleep_for(std::chrono::milliseconds(receive_time_gap)); - size_t elem; + size_t elem = 0; if (!q.Receive(&elem)) { break; } @@ -76,7 +76,7 @@ TEST(BlockingQueue, SenderBlockingTest) { EXPECT_EQ(send_count, queue_cap); std::vector res; while (true) { - size_t elem; + size_t elem = 0; if (!q.Receive(&elem)) { break; } @@ -93,7 +93,7 @@ TEST(BlockingQueue, ReceiverBlockingTest) { BlockingQueue q(queue_cap); std::vector receive_res; std::thread receiver([&]() { - size_t elem; + size_t elem = 0; while (true) { if (!q.Receive(&elem)) { break; @@ -162,7 +162,7 @@ void MultiSenderMultiReceiver(const size_t queue_cap, while (true) { std::this_thread::sleep_for( std::chrono::milliseconds(receive_time_gap)); - size_t elem; + size_t elem = 0; if (!q.Receive(&elem)) { break; } @@ -230,7 +230,7 @@ TEST(BlockingQueue, speed_test_mode) { for (size_t i = 0; i < queue_size; ++i) { q1.Send(i); } - size_t b; + size_t b = 0; for (size_t i = 0; i < queue_size; ++i) { q1.Receive(&b); EXPECT_EQ(b, i); diff --git a/test/cpp/imperative/test_gradient_accmulator.cc b/test/cpp/imperative/test_gradient_accmulator.cc index 982fd81a98835..bb264250ecf56 100644 --- a/test/cpp/imperative/test_gradient_accmulator.cc +++ b/test/cpp/imperative/test_gradient_accmulator.cc @@ -392,7 +392,7 @@ static void TestGradientAccumulatorTestUnchangeInput( int64_t maximum_row_number = 100; std::uniform_int_distribution dist(1, maximum_row_number); - int seed; + int seed = 0; { std::random_device rd; seed = static_cast(rd()); diff --git a/test/cpp/phi/core/test_ddim.cc b/test/cpp/phi/core/test_ddim.cc old mode 100755 new mode 100644 index 3a8afe131eb4d..a58d86e62aa40 --- a/test/cpp/phi/core/test_ddim.cc +++ b/test/cpp/phi/core/test_ddim.cc @@ -126,7 +126,7 @@ TEST(DDim, Print) { TEST(DDim, Hash) { // hash a DDim - std::size_t h; + std::size_t h = 0; phi::DDim ddim = phi::make_ddim({2, 3, 4}); h = std::hash()(ddim); EXPECT_EQ(h, 0xa16fb2b2967ul);