User: Password:
|
|
Subscribe / Log in / New account

Betrayed by a bitfield

Betrayed by a bitfield

Posted Feb 2, 2012 13:57 UTC (Thu) by Lovechild (guest, #3592)
Parent article: Betrayed by a bitfield

I wonder if LLVM/Clang behaves differently in this case.


(Log in to post comments)

Betrayed by a bitfield

Posted Feb 2, 2012 16:31 UTC (Thu) by darthscsi (subscriber, #8111) [Link]

It does it correctly. Se the load, or, store (extended to i32 in the padded bytes), then load of the volatile. compiled on x86-64 at O3.

struct example {
volatile int a;
int b:1;
};

int foo(struct example* e) {
e->b = 1;
return e->a;
}

%struct.example = type { i32, i8 }

define i32 @foo(%struct.example* nocapture %e) nounwind uwtable {
entry:
%0 = getelementptr %struct.example* %e, i64 0, i32 1
%1 = bitcast i8* %0 to i32*
%2 = load i32* %1, align 4
%3 = or i32 %2, 1
store i32 %3, i32* %1, align 4
%a = getelementptr inbounds %struct.example* %e, i64 0, i32 0
%4 = load volatile i32* %a, align 4, !tbaa !0
ret i32 %4
}

Betrayed by a bitfield

Posted Feb 2, 2012 16:33 UTC (Thu) by darthscsi (subscriber, #8111) [Link]

Oh, and the assembly:

0000000000000000 <foo>:
0: 80 4f 04 01 orb $0x1,0x4(%rdi)
4: 8b 07 mov (%rdi),%eax
6: c3 retq

Betrayed by a bitfield

Posted Feb 2, 2012 16:47 UTC (Thu) by khim (subscriber, #9252) [Link]

This looks like x86-64 assembler to me, not IA64.

Are you even sure we are talking about the same case? x86-64 works just fine with GCC, too. PowerPC, Sparc and IA-64 (which started the thread) work incorrectly...


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds