[llvmlinux] Wrong types in inline assembly?

Tim Northover t.p.northover at gmail.com
Fri Sep 27 06:46:29 UTC 2013

Hi Marcelo,

> Can someone explain how cmpxchg can receive a struct type? That seems
> a potential bug to me.

In both cases it's a pointer-to-struct type being used for a
constraint that's effectively "r" (i.e. the value) rather than "m"
(i.e. a location to be loaded from/stored to).

The key point is that the "value" is just a 64-bit pointer no matter
how big struct.llist_node is.

In pseudo C/Asm mixed, something like this is happening:

    llist_node *rax = first;
    llist_node *r8 = new_first;
    if (head->first == rax) head->first = new_first;
    else rax = head->first;

where the last two lines might be captured by a "cmpxchg %r8, %headreg".

> Moreover, shouldn't there be bitcasts from %struct.llist_node* to i64*?

If anything, casting %tmp2 to "%struct.llist_node**" would be more
semantically accurate, since what's actually being stored is actually
a "%struct.llist_node*". But since all pointers are 64-bits wide it
doesn't matter really.



More information about the LLVMLinux mailing list