tinycc-devel
[Top][All Lists]
Advanced

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

RE: [Tinycc-devel] wrong preprocessor shift operation


From: Christian Jullien
Subject: RE: [Tinycc-devel] wrong preprocessor shift operation
Date: Tue, 30 Dec 2008 11:38:45 +0100

I think you're right.
Bug occurs when int (0xffffffff) is promoted to long long
(0xffffffffffffffff). Then right shift and back to int conversion returns a
false result.
Another possible fix is to cast to (unsigned int) as with

if (t1 == VT_LLONG) {
   l1 = v1->c.ll;
} else {
   l1 = (unsigned int)v1->c.i;
}

For my test case it works but will probably break many things.

As professional software developer I know how long it takes to test
everything after a fix. This fix can break many things and I don't want
(have to time) to become a TinyCC maintainer.

I think that long long computation/promotion should only occur when type is
declared as long long.

I let you decide how you want to address this bug.

Christian

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
grischka
Sent: Monday, December 29, 2008 19:59
To: address@hidden
Subject: Re: [Tinycc-devel] wrong preprocessor shift operation


Christian Jullien wrote:
> Simple code below is wrong, even when forcing to long or unsigned long :
>
>             printf("%08x\n", ((~0) >> 1));
>             printf("%08x\n", (unsigned long)((~(unsigned long)0) >> 1));
>             printf("%08x\n", (long)((~(long)0) >> 1));
>
> It prints
>
> ffffffff while 7fffffff is expected.

Well, shouldn't it be:
ffffffff
7fffffff
ffffffff

> I played a little bit with sources and
>
> F:\tmp\tinycc\win32>diff ..\tcc.BAK ..\tcc.c
> 5559,5560c5559,5572
> <     l1 = (t1 == VT_LLONG) ? v1->c.ll : v1->c.i;
> <     l2 = (t2 == VT_LLONG) ? v2->c.ll : v2->c.i;
> ---
>>     if (t1 == VT_LLONG) {
>>       l1 = v1->c.ll;
>>     } else {
>>       l1 = v1->c.i;
>>       l1 &= 0xffffffff;
>>     }
>>
>>     if (t2 == VT_LLONG) {
>>       l2 = v2->c.ll;
>>     } else {
>>       l2 = v2->c.i;
>>       l2 &= 0xffffffff;
>>     }
>

Probably "unsigned int" needs to be distinguished from "int".

Anyway, if you want to you can push a fix on our "mob" branch, See:
http://lists.gnu.org/archive/html/tinycc-devel/2008-11/msg00035.html

Thanks.



_______________________________________________
Tinycc-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel
----------------------------------------------------------------------------
-----------
Orange vous informe que cet  e-mail a ete controle par l'anti-virus mail. 
Aucun virus connu a ce jour par nos services n'a ete detecte.









reply via email to

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