<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - C11 atomics always yielding library call with -mcpu=cortex-m0plus"
   href="https://bugs.llvm.org/show_bug.cgi?id=43603">43603</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>C11 atomics always yielding library call with -mcpu=cortex-m0plus
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>marian.buschsieweke@ovgu.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using this minimum example code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <stdatomic.h>

void foo(void);
extern atomic_int_least16_t bar;

void foo(void)
{
        atomic_store_explicit(&bar, 0x1337, memory_order_relaxed);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Compiling with "clang -mcpu=cortex-m3 -mlittle-endian -mthumb -mfloat-abi=soft
-target arm-none-eabi -Weverything -Werror -c -o test.o test.c" works fine.

Compiling with "clang -mcpu=cortex-m0plus -mlittle-endian -mthumb
-mfloat-abi=soft -target arm-none-eabi -Weverything -Werror -c -o test.o
test.c" yields:

<span class="quote">> test.c:8:2: error: large atomic operation may incur significant performance
>       penalty [-Werror,-Watomic-alignment]
>         atomic_store_explicit(&bar, 0x1337, memory_order_relaxed);
>         ^
> /usr/lib/clang/9.0.0/include/stdatomic.h:118:31: note: expanded from macro
>       'atomic_store_explicit'
> #define atomic_store_explicit __c11_atomic_store
>                               ^
> 1 error generated.</span >


However, compiling with "arm-none-eabi-gcc -mcpu=cortex-m0plus -mlittle-endian
-mthumb -mfloat-abi=soft -Wall -Wextra -pedantic -Werror -c -o test.o test.c"
works fine and generates:

<span class="quote">> arm-none-eabi-objdump -d test.o

> test.o:     file format elf32-littlearm


> Disassembly of section .text:

> 00000000 <foo>:
>    0:      b580            push    {r7, lr}
>    2:      b082            sub     sp, #8
>    4:      af00            add     r7, sp, #0
>    6:      4b07            ldr     r3, [pc, #28]   ; (24 <foo+0x24>)
>    8:      607b            str     r3, [r7, #4]
>    a:      1cbb            adds    r3, r7, #2
>    c:      4a06            ldr     r2, [pc, #24]   ; (28 <foo+0x28>)
>    e:      801a            strh    r2, [r3, #0]
>   10:      1cbb            adds    r3, r7, #2
>   12:      2200            movs    r2, #0
>   14:      5e9b            ldrsh   r3, [r3, r2]
>   16:      b29a            uxth    r2, r3
>   18:      687b            ldr     r3, [r7, #4]
>   1a:      801a            strh    r2, [r3, #0]
>   1c:      46c0            nop                     ; (mov r8, r8)
>   1e:      46bd            mov     sp, r7
>   20:      b002            add     sp, #8
>   22:      bd80            pop     {r7, pc}
>   24:      00000000        .word   0x00000000
>   28:      00001337        .word   0x00001337</span >

Therefore, I assume that the atomic store can be implemented without resorting
a a library call to __atomic_store_2().</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>