Skip to content

Fix more gcc compiler warnings / sort-of bugs

Reference issue

What does this implement/fix?

Fixes several subtle issues that were triggering lots of verbose compiler warnings in gcc:

  1. Blocks with zero columns are permitted in the comma initializer (and perhaps other situations). These zero-size blocks are harmless (probably), but may hold a pointer that is incremented beyond the bounds of the allocated memory.
Matrix2d A(2, 2);
MatrixXd A1(1, 2);
Matrix<double,1,0> A2(1, 0);
(A << A1, A2, 
      A1, A2).finished();

Here, the bottom right block of A is constructed to have pointer A.data() + 5, which is clearly beyond the bounds of A.data(). This pointer is never dereferenced, as the evaluator loop won't execute anything, but gcc can't deduce that. This patch always nulls the pointer if the block size is 0, which suppresses the warning. In the block test, we must check if the block object is zero-sized before calling coeff. This is usually implicit in a loop for(int i = 0; i < rows; i++), but in this particular case we (unconditionally) check a single coefficient's value.

  1. VectorBlock explicitly declared the = assignment operator, but no copy constructor. This patch uses the built-in macro EIGEN_INHERIT_ASSIGNMENT_OPERATORS to do that.
  2. The triangular solver does a runtime check if the result and rhs are in fact the same object. I suspect this is causing the -Wmaybe-uninitialized warning which only seems to happen for fixed size objects. Perhaps this is also the reason for the SVD warnings?
if(!is_same_dense(dst,m_rhs))
  dst = m_rhs;

If dst is an implicitly declared fixed-size matrix, the storage is allocated on the stack and is not initialized, and gcc can't deduce whether dst = m_rhs will be run. This patch changes the test so that dst is unambiguously initialized. I'm not sure if this is actually the cause of the warning, but it works. 4) explicitly initialize matrix in random_matrix test

build:linux:cross:x86-64:gcc-10:avx2 log files:

Before: 5220 lines

After: 2363 lines

Additional information

Edited by Charles Schlosser

Merge request reports

Loading