[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Bug in _Bool return values

From: Giovanni Mascellani
Subject: Re: [Tinycc-devel] Bug in _Bool return values
Date: Tue, 5 Feb 2019 10:12:06 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0


Il 04/02/19 23:31, Louis Botha ha scritto:
> With out the fix the program prints:  1000 > 2000 : true
> With this fix described below the program prints:  1000 > 2000 : false

Yes, it seems there is an inconsistency between gcc and tcc, because if
you compile the "outer" program with tcc, then everything works. If you
do use gcc, then you can see the bug.

It seems that gcc uses only the lowest byte to return a _Bool from a
function (but, interestingly, it zero-extends it when passing as an


System V ABI[1] seems to be rather laconic on this matter: "Booleans,
when stored in a memory object, are stored as single byte objects the
value of which is always 0 (false) or 1 (true). When stored in integer
registers (except for passing as arguments), all 4 bytes of the register
are significant; any nonzero value is considered true".

 [1] https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-1.1.pdf

I would personally interpret that gcc is wrong here, because the _Bool
is being passed as return value, not as argument. However, it is
probably easier that tcc conform to gcc than the other way around.

There is also an old gcc bug on more or less the same matter[2], from
which I understand that apparently the ABI used to be different in the past.

 [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42324

Giovanni Mascellani <address@hidden>
Postdoc researcher - Université Libre de Bruxelles

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]