abseil-cpp icon indicating copy to clipboard operation
abseil-cpp copied to clipboard

[Bug]: `FixedArray` triggers `-Wfree-nonheap-object` warnings in LTO builds

Open sergiud opened this issue 10 months ago • 3 comments

Describe the issue

Using GCC 14.2.1 we see the following warnings:

/usr/include/eigen3/Eigen/src/Core/ProductEvaluators.h:29: note: a type with different bases is defined in another translation unit
   29 | struct evaluator<Product<Lhs, Rhs, Options> >
[788/969] Linking CXX executable bin/numeric_diff_cost_function_test
In member function ‘deallocate’,
    inlined from ‘deallocate’ at /usr/include/c++/14.2.1/bits/alloc_traits.h:513:23,
    inlined from ‘__dt_base ’ at /home/sergiu/Projects/ceres-solver/third_party/abseil-cpp/absl/container/fixed_array.h:481:36,
    inlined from ‘__dt_base ’ at /home/sergiu/Projects/ceres-solver/third_party/abseil-cpp/absl/container/fixed_array.h:174:3,
    inlined from ‘EvaluateJacobianForParameterBlock’ at /home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:170:3,
    inlined from ‘Apply’ at /home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:462:52,
    inlined from ‘Evaluate’ at /home/sergiu/Projects/ceres-solver/include/ceres/numeric_diff_cost_function.h:262:47:
/usr/include/c++/14.2.1/bits/new_allocator.h:172:33: warning: ‘operator delete’ called on unallocated object ‘residual_array’ [-Wfree-nonheap-object]
  172 |         _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
      |                                 ^
/home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h: In member function ‘Evaluate’:
/home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:129:30: note: declared here
  129 |     absl::FixedArray<double> residual_array(num_residuals_internal);
      |                              ^
In member function ‘deallocate’,
    inlined from ‘deallocate’ at /usr/include/c++/14.2.1/bits/alloc_traits.h:513:23,
    inlined from ‘__dt_base ’ at /home/sergiu/Projects/ceres-solver/third_party/abseil-cpp/absl/container/fixed_array.h:481:36,
    inlined from ‘__dt_base ’ at /home/sergiu/Projects/ceres-solver/third_party/abseil-cpp/absl/container/fixed_array.h:174:3,
    inlined from ‘EvaluateJacobianForParameterBlock’ at /home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:170:3,
    inlined from ‘Apply’ at /home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:462:52,
    inlined from ‘Evaluate’ at /home/sergiu/Projects/ceres-solver/include/ceres/numeric_diff_cost_function.h:262:47:
/usr/include/c++/14.2.1/bits/new_allocator.h:172:33: warning: ‘operator delete’ called on unallocated object ‘residual_array’ [-Wfree-nonheap-object]
  172 |         _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
      |                                 ^
/home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h: In member function ‘Evaluate’:
/home/sergiu/Projects/ceres-solver/include/ceres/internal/numeric_diff.h:129:30: note: declared here
  129 |     absl::FixedArray<double> residual_array(num_residuals_internal);
      |   

Steps to reproduce the problem

  1. Construct absl::FixedArray<double> a(n).
  2. Compile using -flto=auto.

What version of Abseil are you using?

The lts_2024_01_16 branch.

What operating system and version are you using?

ArchLinux

What compiler and version are you using?

GCC 14.2.1

What build system are you using?

cmake version 3.31.5

Additional context

No response

sergiud avatar Feb 20 '25 10:02 sergiud

There is not enough information in this bug report for me to quickly figure out the problem. Please post a full small reproduction of the problem. absl::FixedArray<double> a(n) is meaningless without the value of n, for example. I need all the code.

derekmauro avatar Feb 20 '25 14:02 derekmauro

absl::FixedArray<double> a(n) is not meaningless since any variation of this line and enabled LTO exactly triggers the warning. The reproducer also does not depend on a specific value of n, hence the placeholder. You can use any value greater 0.

sergiud avatar Feb 20 '25 14:02 sergiud

bazel test --copt=-flto=auto --linkopt=-flto=auto --test_tag_filters=-benchmark ... does not produce the above warning for me. The reproduction instructions are missing information.

derekmauro avatar Feb 21 '25 18:02 derekmauro