tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Incorrect shift result type with 64-bit ABI


From: Vincent Lefevre
Subject: [Tinycc-devel] Incorrect shift result type with 64-bit ABI
Date: Tue, 26 Jun 2012 15:07:57 +0200
User-agent: Mutt/1.5.21-6205-vl-r52214 (2012-05-24)

Hi,

The behavior on the following program is incorrect with Debian's
tcc (at least up to 0.9.26~git20120612.ad5f375-3) on x86_64
(64-bit ABI).

#include <stdio.h>

#define M1 (1 << (int) 1)
#define M2 (1 << (unsigned int) 1)
#define M3 (1 << (long) 1)
#define M4 (1 << (unsigned long) 1)
#define M5 (1 << (long long) 1)
#define M6 (1 << (unsigned long long) 1)

#define OUT(M) \
  printf ("%d %s\n", (int) sizeof(M), -M < 0 ? "signed" : "unsigned")

int main (void)
{
  OUT(M1);
  OUT(M2);
  OUT(M3);
  OUT(M4);
  OUT(M5);
  OUT(M6);
  return 0;
}

ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on
each of the operands. The type of the result is that of the promoted
left operand."

Thus the type of the shift result should be int in the 6 cases.

Correct behavior:
4 signed
4 signed
4 signed
4 signed
4 signed
4 signed

Incorrect behavior (with 64-bit tcc 0.9.26~git20120612.ad5f375-3):
4 signed
4 unsigned
8 signed
8 unsigned
8 signed
8 unsigned

-- 
Vincent Lefèvre <address@hidden> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://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]