[llvm-bugs] [Bug 34143] New: Hardfault when dereferencing unaligned float

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 10 06:49:07 PDT 2017


            Bug ID: 34143
           Summary: Hardfault when dereferencing unaligned float
           Product: clang
           Version: 4.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dan at walms.co.uk
                CC: llvm-bugs at lists.llvm.org

Code to reproduce:

template <typename T> inline T Read (uint8_t* data)
    auto valuePtr = reinterpret_cast<T*> (data);
    auto value = *valuePtr;
    return value;
static float test = 180.0f;
int main (void)
    uint8_t* data = new uint8_t[8];
    memcpy (data, &test, sizeof (float));
    auto value = Read<float> (data);

    memcpy (data + 1, &test, sizeof (float));
    value = Read<float> (data + 1); // hard fault here!
    return value;

first call to Read will cause an aligned dereferencing of the pointer.
second call will cause an in-aligned deferencing of pointer to float.

second call causes a hard fault.

Wall -c -fshort-enums -ggdb3 -std=c++14 -fno-rtti -fno-exceptions
-mfpu=fpv4-sp-d16 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mfloat-abi=hard
-ffunction-sections -fdata-sections -O1 -target arm-none-eabi -mcpu=cortex-m4

When code is compiled with -O0, it works.

with -01 it uses VLDR instruction which can not be used unaligned.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170810/65b2405c/attachment.html>

More information about the llvm-bugs mailing list