[cfe-dev] Cortex-M4F Assembly Code Generation Incorrect for float casting, causing HardFaults

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 10 07:36:02 PDT 2017


This seems to be as expected.  This pair of lines:

>     auto valuePtr = reinterpret_cast<T*> (data);
>     auto value = *valuePtr;


Is asserting to the compiler that data is correctly aligned for T, which in your case is a float.  Dereferencing this pointer is therefore allowed to assume alignment.  If you have an underaligned pointer, then C++ provides the alignas keyword that allows you to specify an under-aligned type.  If the VLDR instruction is still generated with an alignas(1) type, then this is a bug, otherwise this is the compiler generating code that does what you instructed it to do.

David



More information about the cfe-dev mailing list