Alignment problem on MacOS
The simple test code below is compiled on MacOS (clang version 17.0.0) with Eigen 5.0.0, via
g++ -Wall foo.cc -Ieigen-5.0.0 -std=c++20 -fsanitize=undefined
and runs successfully, but generates the error
assume_aligned.h:35:55: runtime error: assumption of 128 byte alignment for pointer of type 'const double *' failed
0x00016f5cb020: note: address is 32 aligned, misalignment offset is 32 bytes
00 00 10 40 00 00 00 00 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 70 b2 5c 6f
^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
4
6
When compiled without -fsanitize=undefined it runs and produces the expected output. When compiled as
g++ -Wall foo.cc -Ieigen-5.0.0 -std=c++20 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE
(which activates Apple's extra libcpp runtime checks), it fails with a trap. The stack backtrace is attached.
The code foo.cc:
#include "Eigen/Dense"
#include <iostream>
int main() {
Eigen::Vector2d a, b, c;
a << 1, 2;
b << 3, 4;
c = a + b;
std::cout << c << "\n";
}