[Top][All Lists]

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

[Tinycc-devel] Buggy left shift on x86_64

From: Vincent Lefevre
Subject: [Tinycc-devel] Buggy left shift on x86_64
Date: Tue, 13 Mar 2012 15:28:37 +0100
User-agent: Mutt/1.5.21-6201-vl-r48020 (2011-12-20)

I've found the following bug when compiling and testing MPFR with
Debian's tcc 0.9.26~git20120104.83d57c0-4 package.

On x86_64 (but not on i386), the left shift is buggy:

#include <stdio.h>
#include <limits.h>

#define SH (CHAR_BIT * sizeof(unsigned long) / 2)

int main (void)
  unsigned long m;
  int sh = SH;

  printf ("SH = %d\n", (int) SH);
  m = 1UL << SH;
  printf ("m = 0x%lx\n", m);
  m = 1UL << sh;
  printf ("m = 0x%lx\n", m);
  m = 1UL << (SH/2);
  m *= m;
  printf ("m = 0x%lx\n", m);

  return 0;


SH = 32
m = 0x0
m = 0x1
m = 0x100000000

The correct result (as obtained with gcc) is:

SH = 32
m = 0x100000000
m = 0x100000000
m = 0x100000000

I've also reported it on the Debian BTS:


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]