tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] incorrect bit-field behavior


From: Vincent Lefevre
Subject: [Tinycc-devel] incorrect bit-field behavior
Date: Tue, 7 Jun 2016 02:35:01 +0200
User-agent: Mutt/1.6.1-6659-vl-r88942 (2016-05-31)

tcc does not follow the integer promotion rules on bit-fields.
For instance, consider the following code:

#include <stdio.h>

union ui
{
  struct
    {
      unsigned int manl:32;
      unsigned int manh:20;
      unsigned int exp:11;
      unsigned int sig:1;
    } s;
  double d;
};

union ul
{
  struct
    {
      unsigned long manl:32;
      unsigned long manh:20;
      unsigned long exp:11;
      unsigned long sig:1;
    } s;
  double d;
};

int main (void)
{
  union ui xi;
  union ul xl;

  xi.d = 0.5;
  xl.d = 0.5;

  printf ("%d %lx\n", xi.s.exp - 1023 < 0, (unsigned long) (xi.s.exp - 1023));
  printf ("%d %lx\n", xl.s.exp - 1023 < 0, (unsigned long) (xl.s.exp - 1023));
  return 0;
}

With GCC and ICC, I get:

1 ffffffffffffffff
1 ffffffffffffffff

But with tcc, I get:

0 ffffffff
0 ffffffffffffffff

Since all the values of xi.s.exp and xl.s.exp are representable
in an int, the bit-field type should be converted to int for the
subtraction, so that the < 0 should be true in both cases.

-- 
Vincent Lefèvre <address@hidden> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



reply via email to

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