[Top][All Lists]

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

[Tinycc-devel] Bug in _Bool return values

From: Louis Botha
Subject: [Tinycc-devel] Bug in _Bool return values
Date: Mon, 4 Feb 2019 00:54:06 +0000

Hi TCC-fans,


Think I found a bug in the implementation of _Bool in return values in version 0.9.27, found on i386, probably applies to x86_64, and possibly others as well:

Since sizeof(_Bool) == 1 as implemented in TCC, I believe this comment in i386-gen.c applies:

extend the return value to the whole register if necessary

visual studio and gcc do not always set the whole eax register

when assigning the return value of a function


The scenario that broke for me was calling a function that only set the AL register on return, leaving the rest of EAX undefined, yet TCC checked the whole of EAX for the _Bool return value (true came out correct, but false tested as true when the undefined-bits were non-0)


Assigning the _Bool return value to a _Bool variable and then checking that variable instead of the return value is one confirmed workaround (the emitted TCC code then uses just AL to generate a full EAX before checking EAX), but I think I have found the proper fix:


Add “case VT_BOOL:” as shown here, just after line 365 of i386-gen.c:


switch (rt & VT_BTYPE) {

    case VT_BYTE:

    case VT_BOOL:


This modification fixed the problem I was having, I *think* the line in x86_64-gen.c that needs to change for the equivalent there is this (@ line 934):


else if (bt == VT_BYTE || bt == VT_BOOL)


Sorry, I don’t know the other architectures or TCC in general well enough to comment on other places that may also need this fix.


Best regards,



reply via email to

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