[LLVMdev] Wrong types in inline assembly?

Marcelo Sousa dipython at gmail.com
Mon Sep 23 13:21:02 PDT 2013


Hello,

I'm confused about a particular snippet of code related to inline
assembly. From the Linux kernel:

bool llist_add_batch(struct llist_node *new_first, struct llist_node
*new_last, struct llist_head *head){
struct llist_node *first;

do {
new_last->next = first = ACCESS_ONCE(head->first);
} while (cmpxchg(&head->first, first, new_first) != first);

return !first;
}

The generated code in the IR for the cmpxchg call is:
%struct.llist_node = type { %struct.llist_node* }

%tmp8 = tail call %struct.llist_node* asm sideeffect ".pushsection
.smp_locks,\22a\22\0A.balign 4\0A.long 671f -
.\0A.popsection\0A671:\0A\09lock; cmpxchgq $2,$1",
"={ax},=*m,r,0,*m,~{memory},~{dirflag},~{fpsr},~{flags}"(i64* %tmp2,
%struct.llist_node* %tmp7, %struct.llist_node* %entry.0, i64* %tmp2)


Can someone explain how cmpxchg can receive a struct type? That seems
a potential bug to me.
Moreover, shouldn't there be bitcasts from %struct.llist_node* to i64*?

-- 
Kind Regards,
Marcelo Sousa



More information about the llvm-dev mailing list