https://bugs.llvm.org/show_bug.cgi?id=50785

            Bug ID: 50785
           Summary: clang incorrectly produces ARM STM instead of STR in
                    thumb mode
           Product: clang
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

When compiling to ARM (32-bit) thumb mode, clang incorrectly produces stm
instead of str in some cases. This is causing issues (sigbus: illegal
alignment) if the destination pointer is not aligned.

This can be reproduced with the following minimal C code:

    #include <stdint.h>

    uint8_t *f(uint8_t *buf)
    {
        *(uint32_t*)buf = 0;
        return buf + 4;
    }

which, when compiled with -O2 -mthumb, produces the following ARM ASM:

    f:
        movs    r1, #0
        stm     r0!, {r1}
        bx      lr

whereas GCC (or clang without -mthumb) produces:

    f:
        movs    r3, #0
        str     r3, [r0], #4
        bx      lr


This happens on clang 9.x, 10.x, 11.x and 12.x as well as the versions provided
by the Android NDK (r21e, r22b).

This issue was found when debugging a crash occurring in libjpeg-turbo 2.1.0
when compiled to ARM (32-bit) thumb node / Android. The crash happens at:
https://github.com/libjpeg-turbo/libjpeg-turbo/blob/1a1fb615db39880044b789bdb36b351865d9ec4a/simd/arm/jchuff.h#L84
(called by
https://github.com/libjpeg-turbo/libjpeg-turbo/blob/1a1fb615db39880044b789bdb36b351865d9ec4a/simd/arm/aarch32/jchuff-neon.c#L295)

where:

    *((uint32_t *)buffer) = BUILTIN_BSWAP32(put_buffer);
    buffer += 4;

gets compiled to rev + stm instead of rev + str, causing a sigbus error
(illegal alignment) because buffer is not necessarily aligned.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to