digging deeper, it seems it really is an issue with the clang
.
This simple test program
#include <arm_neon.h>
#include <stdio.h>
#include <assert.h>
class MyClass {
public:
float32x4_t c;
};
int main()
{
printf("alignof(MyClass): %d\n", alignof(MyClass));
printf("alignof(float32x4_t): %d\n", alignof(float32x4_t));
for(int n = 0; n < 100; ++n)
{
auto ptr = new MyClass;
printf("ptr: %p\n", ptr);
printf("c: %p\n", &ptr->c);
assert(((unsigned int)ptr & (alignof(MyClass) - 1)) == 0);
}
return 0;
}
fails with clang
. It work with gcc
, but then gcc
claims that alignof(float32x4_t)
is 8 instead of 16, which I don't understand ...
So, a current workaround would be to override operator new
in the Heavy_bela
class adding to the class Heavy_bela
class declaration in Heavy_bela.hpp
:
#include <new>
....
class Heavy_bela {
...
void* operator new(size_t sz) {
auto ptr = aligned_alloc(16, sz);
if(!ptr)
{
std::bad_alloc exception;
throw exception;
}
return ptr;
}
...
}
however, the issue is fairly worrying and I need to find out if this is related to the version of clang
, and if there is a more up-to-date one we can use instead.
If this turns out to be needed, we could add the change to the hvcc
template files.