[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Tinycc-devel Digest, Vol 134, Issue 16
From: |
Michael Matz |
Subject: |
Re: [Tinycc-devel] Tinycc-devel Digest, Vol 134, Issue 16 |
Date: |
Mon, 23 Jun 2014 12:01:07 +0200 (CEST) |
User-agent: |
Alpine 2.00 (LNX 1167 2008-08-23) |
Hi,
On Sun, 22 Jun 2014, jiang wrote:
This is my patch (see Annex)
tcc result is correct
--> 254 / 30 / 126
That's not the correct result. If you think it is the probably because
you're confused by the semantics of assignments as rvalue.
I guess gcc & mvc repeated use of the register, so wrong
No, GCC and MSVC are correct.
struct {
unsigned a:9, b:5, c:7;
} _s, *s = &_s;
int n = 250;
s->a = s->b = s->c = n + 4;
To show that GCC is correct (and TCC wrong, and your patch still wrong)
rewrite the above into the explicit expansion according to associativity
of '=':
s->c = n + 4; // s->c == 254 & 127 == 126
s->b = s->c; // s->b == 126 & 31 == 30
s->a = s->b; // s->a == 30
In particular the value loaded into s->a comes from s->b, and hence is the
truncated value, which isn't changed anymore as 5 bits fits into 9 bits.
Ciao,
Michael.