mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 08:34:37 +08:00
Fix GCC 12.1.1 LTO -Walloc-size-larger-than= warnings
With -flto=auto, GCC emits multiple warnings in release builds such as
In function ‘make_unique’,
inlined from ‘Create’ at ceres-solver/internal/ceres/scratch_evaluate_preparer.cc:43:75,
inlined from ‘CreateEvaluatePreparers’ at ceres-solver/internal/ceres/compressed_row_jacobian_writer.h:95:66,
inlined from ‘__ct ’ at ceres-solver/internal/ceres/program_evaluator.h:120:9,
inlined from ‘Evaluate.constprop.isra’ at ceres-solver/internal/ceres/problem_impl.cc:695:65:
/usr/include/c++/12.1.1/bits/unique_ptr.h:1080:30: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
1080 | { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }
| ^
because a signed integer is used to specify the size of allocated arrays
instead of the expected unsigned (specifically, std::size_t) without
checking for negative values at the call site.
Change-Id: I923b1d074241535426bfea041568ef1dc7f3ec86
This commit is contained in:
committed by
Sameer Agarwal
parent
9ec4f7e44a
commit
388c142866
@@ -138,12 +138,12 @@ BlockJacobianWriter::BlockJacobianWriter(const Evaluator::Options& options,
|
||||
// Create evaluate prepareres that point directly into the final jacobian. This
|
||||
// makes the final Write() a nop.
|
||||
std::unique_ptr<BlockEvaluatePreparer[]>
|
||||
BlockJacobianWriter::CreateEvaluatePreparers(int num_threads) {
|
||||
BlockJacobianWriter::CreateEvaluatePreparers(unsigned num_threads) {
|
||||
int max_derivatives_per_residual_block =
|
||||
program_->MaxDerivativesPerResidualBlock();
|
||||
|
||||
auto preparers = std::make_unique<BlockEvaluatePreparer[]>(num_threads);
|
||||
for (int i = 0; i < num_threads; i++) {
|
||||
for (unsigned i = 0; i < num_threads; i++) {
|
||||
preparers[i].Init(&jacobian_layout_[0], max_derivatives_per_residual_block);
|
||||
}
|
||||
return preparers;
|
||||
|
||||
@@ -60,7 +60,7 @@ class CERES_NO_EXPORT BlockJacobianWriter {
|
||||
// Create evaluate prepareres that point directly into the final jacobian.
|
||||
// This makes the final Write() a nop.
|
||||
std::unique_ptr<BlockEvaluatePreparer[]> CreateEvaluatePreparers(
|
||||
int num_threads);
|
||||
unsigned num_threads);
|
||||
|
||||
std::unique_ptr<SparseMatrix> CreateJacobian() const;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Ceres Solver - A fast non-linear least squares minimizer
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
// http://ceres-solver.org/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -129,8 +129,8 @@ class ProgramEvaluator final : public Evaluator {
|
||||
#endif // CERES_NO_THREADS
|
||||
|
||||
BuildResidualLayout(*program, &residual_layout_);
|
||||
evaluate_scratch_ =
|
||||
std::move(CreateEvaluatorScratch(*program, options.num_threads));
|
||||
evaluate_scratch_ = std::move(CreateEvaluatorScratch(
|
||||
*program, static_cast<unsigned>(options.num_threads)));
|
||||
}
|
||||
|
||||
// Implementation of Evaluator interface.
|
||||
@@ -345,7 +345,7 @@ class ProgramEvaluator final : public Evaluator {
|
||||
|
||||
// Create scratch space for each thread evaluating the program.
|
||||
static std::unique_ptr<EvaluateScratch[]> CreateEvaluatorScratch(
|
||||
const Program& program, int num_threads) {
|
||||
const Program& program, unsigned num_threads) {
|
||||
int max_parameters_per_residual_block =
|
||||
program.MaxParametersPerResidualBlock();
|
||||
int max_scratch_doubles_needed_for_evaluate =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Ceres Solver - A fast non-linear least squares minimizer
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
// http://ceres-solver.org/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,19 +39,19 @@
|
||||
namespace ceres::internal {
|
||||
|
||||
std::unique_ptr<ScratchEvaluatePreparer[]> ScratchEvaluatePreparer::Create(
|
||||
const Program& program, int num_threads) {
|
||||
const Program& program, unsigned num_threads) {
|
||||
auto preparers = std::make_unique<ScratchEvaluatePreparer[]>(num_threads);
|
||||
int max_derivatives_per_residual_block =
|
||||
program.MaxDerivativesPerResidualBlock();
|
||||
for (int i = 0; i < num_threads; i++) {
|
||||
for (unsigned i = 0; i < num_threads; i++) {
|
||||
preparers[i].Init(max_derivatives_per_residual_block);
|
||||
}
|
||||
return preparers;
|
||||
}
|
||||
|
||||
void ScratchEvaluatePreparer::Init(int max_derivatives_per_residual_block) {
|
||||
jacobian_scratch_ =
|
||||
std::make_unique<double[]>(max_derivatives_per_residual_block);
|
||||
jacobian_scratch_ = std::make_unique<double[]>(
|
||||
static_cast<std::size_t>(max_derivatives_per_residual_block));
|
||||
}
|
||||
|
||||
// Point the jacobian blocks into the scratch area of this evaluate preparer.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Ceres Solver - A fast non-linear least squares minimizer
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
// Copyright 2022 Google Inc. All rights reserved.
|
||||
// http://ceres-solver.org/
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,7 +50,7 @@ class CERES_NO_EXPORT ScratchEvaluatePreparer {
|
||||
public:
|
||||
// Create num_threads ScratchEvaluatePreparers.
|
||||
static std::unique_ptr<ScratchEvaluatePreparer[]> Create(
|
||||
const Program& program, int num_threads);
|
||||
const Program& program, unsigned num_threads);
|
||||
|
||||
// EvaluatePreparer interface
|
||||
void Init(int max_derivatives_per_residual_block);
|
||||
|
||||
Reference in New Issue
Block a user