std::array assignment causes hardfault

Bug #1868070 reported by David Osborne
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

I asked this question on the forum. I got no responses so I'm trying it here:

When a std::array is assigned to another it may result in a hardfault ('usage' I think). The code the compiler generates to perform the copy uses 32-bit registers to transfer the data. If the source array or destination are not on a 32-bit boundary, a hardfault will occur. I thought the compiler always put class members on 32-bit boundaries, however, these std:array can actually be 16-bit aligned.

The following code is likely to generate a hardfault:

Compiler:
arm-none-eabi-gcc.exe (GNU Tools for Arm Embedded Processors 9-2019-q4-major) 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599]

class ArrayTest
{
public:
    ArrayTest() {}
    ~ArrayTest()
    {
    }

    void MakeEqual()
    {
        mArrayA = mArrayB;
    }

private:
    std::array<bool, 10> mArrayA = { 0 };
    std::array<bool, 10> mArrayB = { 0 };
};

Calling MakeEqual() will likely cause a hardfault if either array is on a 16-bit boundary instead of a 32-bit boundary.

Is this a defect, or is it the programmers responsibility to ensure std:arrays are on 32-bit boundaries?
If this is a defect, should it be logged here or in GCC bugzilla?

Thanks

Tags: array
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.