Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

atomic_add_fetch #16649

Closed Quuxplusone closed 8 years ago

Quuxplusone commented 11 years ago
Bugzilla Link PR16650
Status RESOLVED FIXED
Importance P normal
Reported by Tatrai Antal (tatraian@deverto.com)
Reported on 2013-07-18 10:19:24 -0700
Last modified on 2016-01-26 11:05:29 -0800
Version trunk
Hardware PC Linux
CC awg@embtoolkit.org, efriedma@quicinc.com, jyknight@google.com, liujiangning1@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments atomic.patch (2686 bytes, text/plain)
Blocks
Blocked by
See also
I cannot compile libstdc++'s atomic library with long long type on 32 bit
machine.

So the following code cannot be compiled:

    #include <atomic>

    int main()
    {
      std::atomic<long long> l(0);
      ++l;
      return 0;
    }

With the following error:
    clang++ -std=c++11 atomic.cpp
    In file included from atomic.cpp:1:
    In file included from /usr/lib/gcc/i486-linux-gnu/4.7/../../../../include/c++/4.7/atomic:41:
    /usr/lib/gcc/i486-linux-gnu/4.7/../../../../include/c++/4.7/bits/atomic_base.h:369:16: error: cannot compile this atomic
          library call yet
          { return __atomic_add_fetch(&_M_i, 1, memory_order_seq_cst); }
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
Quuxplusone commented 11 years ago

What version of clang is this?

Quuxplusone commented 11 years ago
I'm sorry. I forgot the revision number:

    tatraian@server09:~$ clang++ --version
    clang version 3.4 (186311)
    Target: i386--linux-gnu
    Thread model: posix

Last commit in llvm was 186311 and last commit in clang was 186306

In don't know does it matter but I send llc version as well:

tatraian@server09:~/tmp/llvm-svn/tools/clang$ llc --version
LLVM (http://llvm.org/):
  LLVM version 3.4svn
  Optimized build.
  Built Jul 15 2013 (09:42:58).
  Default target: i386-linux-gnu
  Host CPU: corei7-avx

  Registered Targets:
    aarch64  - AArch64 (ARM 64-bit target)
    arm      - ARM
    cpp      - C++ backend
    hexagon  - Hexagon
    mblaze   - MBlaze
    mips     - Mips
    mips64   - Mips64 [experimental]
    mips64el - Mips64el [experimental]
    mipsel   - Mipsel
    msp430   - MSP430 [experimental]
    nvptx    - NVIDIA PTX 32-bit
    nvptx64  - NVIDIA PTX 64-bit
    ppc32    - PowerPC 32
    ppc64    - PowerPC 64
    r600     - AMD GPUs HD2XXX-HD6XXX
    sparc    - Sparc
    sparcv9  - Sparc V9
    systemz  - SystemZ
    thumb    - Thumb
    x86      - 32-bit X86: Pentium-Pro and above
    x86-64   - 64-bit X86: EM64T and AMD64
    xcore    - XCore
Quuxplusone commented 11 years ago

That's strange... we really don't have an implementation of __atomic_add_fetch.

Quuxplusone commented 11 years ago
(In reply to comment #3)
> That's strange... we really don't have an implementation of
> __atomic_add_fetch.

Huh, that is strange. Since the atomic library specification doesn't include
__atomic_add_fetch functions, we are presumably supposed to call
__atomic_fetch_add_<n> here.
Quuxplusone commented 11 years ago

Oh, right, duh... __atomic_add_fetch_n doesn't exist because you can easily emulate it on top of __atomic_fetch_add_n. It's just that clang IRGen doesn't know how yet.

Quuxplusone commented 11 years ago

Attached atomic.patch (2686 bytes, text/plain): missing atomic__fetch calls

Quuxplusone commented 11 years ago

I wrote a quick fix for the issue. I patched CGAtomic.cpp.

I'm not sure about my code. As I could recognize (without any detailed knowledge of llvm and clang) the switch that cannot recognize the atomic instruction generate library calls. So I put the missing calls there. But there is a problem with this solution. GCC 4.7 does not provide any atomic library from its atomic calls. There is an example libatomic.c on the web:

http://gcc.gnu.org/wiki/Atomic/GCCMM

but his code contains no _atomic_fetch function. Finally I tried to use GCC 4.8 libatomic.so with my patch and that worked.

I attached the patch.

Quuxplusone commented 11 years ago

I wrote a quick fix for the issue. I patched CGAtomic.cpp.

I'm not sure about my code. As I could recognize (without any detailed knowledge of llvm and clang) the switch that cannot recognize the atomic instruction generate library calls. So I put the missing calls there. But there is a problem with this solution. GCC 4.7 does not provide any atomic library from its atomic calls. There is an example libatomic.c on the web:

http://gcc.gnu.org/wiki/Atomic/GCCMM

but his code contains no _atomic_fetch function. Finally I tried to use GCC 4.8 libatomic.so with my patch and that worked.

I attached the patch.

Quuxplusone commented 8 years ago

Works in current clang.