This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug in x86-64 psABI or in gcc?


On Tue, Dec 8, 2009 at 8:50 AM, Michael Matz <matz@suse.de> wrote:
> Hi,
>
> On Mon, 7 Dec 2009, H.J. Lu wrote:
>
>> ---
>> When a value of type _Bool is passed in a register or on the stack,
>> the upper 63 bits of the eightbyte shall be zero.
>> ---
>
> That was the outcome of a discussion in 2005/2006. ?We put this language
> in because at that time all compilers booleanized at the caller.
> GCC also makes use of this guarantee (although limited to the
> 8 bit):
>
> _Bool bartmp;
> void foo(_Bool bar)
> {
> ?bartmp = bar;
> }
>
> will generate
>
> foo:
> ? ? ? ?movb ? ?%dil, bartmp(%rip)
> ? ? ? ?ret
>
> I do see value in limiting the zeroing to bits 1-31 when passed on stack.
> But we'd need agreement on the discuss@ list, which for some reason didn't
> seem to get any of these mails.
>

Both icc and gcc generate:

[hjl@gnu-26 pr42324]$ cat b4.c
extern unsigned int bartmp;

void foo(_Bool bar)
{
 bartmp = bar;
}
[hjl@gnu-26 pr42324]$ /usr/gcc-4.4/bin/gcc -O2 b4.c -S
[hjl@gnu-26 pr42324]$ cat b4.s
	.file	"b4.c"
	.text
	.p2align 4,,15
.globl foo
	.type	foo, @function
foo:
.LFB2:
	movzbl	%dil, %edi
	movl	%edi, bartmp(%rip)
	ret

We should just drop

---
When a value of type _Bool is passed in a register or on the stack,
the upper 63 bits of the eightbyte shall be zero.
---

from psABI. Since _Bool has one byte in size with values of 0 and 1.
Compilers have to clear upper 7 bits in one byte.


-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]