New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 24875 - member alignment ignored when generating atomic load
Summary: member alignment ignored when generating atomic load
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: 3.7
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-18 11:47 PDT by Davin McCall
Modified: 2015-09-18 11:49 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Davin McCall 2015-09-18 11:47:52 PDT
LLVM 3.7, x86_64-pc-linux-gnu. The following program fails to link (using libstdc++ from GCC 5.2.0):

--- begin ---
constexpr int memory_order_seq_cst = 5;

struct /* alignas(8) */ Term
{
    int a;
    int b;
};

class Atomic
{
    alignas(8) Term mm;
    
    public:
    
    Term load()
    {
        Term tmp;
        __atomic_load(&mm, &tmp, memory_order_seq_cst);
        return tmp;
    }
};

int main(int argc, char **argv)
{
    Atomic a;
    a.load();
    return 0;
}
--- end ---

Error at link is:
$ clang++ -std=c++11  clangatomic.cc 
/tmp/clangatomic-3242b4.o: In function `Atomic::load()':
clangatomic.cc:(.text._ZN6Atomic4loadEv[_ZN6Atomic4loadEv]+0x16): undefined reference to `__atomic_load_8'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)
$ 


If the 'alignas(8)' for struct Term is uncommented, the code compiles and links ok. IIUC this shouldn't be required because there is an alignas(...) on the 'mm' member.

This may be related to: https://llvm.org/bugs/show_bug.cgi?id=23262
(but that is marked INVALID due to a bug in libstdc++. The example above however does not use libstdc++).

This problem prevents using clang++ + libstdc++ with atomic operations.