A strange div bug on Linux x86_64, (both dmd & ldc2): long -5000 / size_t 2 = 9223372036854773308

mw mingwu at gmail.com
Thu Aug 13 07:22:18 UTC 2020

I post here because I think this bug's impact maybe pretty wide, 
it's a div bug  on Linux x86_64, (both dmd & ldc2).  I'm 
interested in knowing what caused this bug.

On Windows, I only tested dmd.exe, it correctly outputs -2500.

size_t: because I was taking array length, maybe many people do 
that too.


import std.stdio;

void main() {
   long   a = -5000;
   size_t b = 2;
   long   c = a / b;

$ dmd divbug.d
$ ./divbug

$ ldc2 divbug.d
$ ./divbug

x86_64 x86_64 x86_64 GNU/Linux

$ dmd --version
DMD64 D Compiler v2.092.0

$ ldc2 --version
LDC - the LLVM D compiler (1.21.0):
   based on DMD v2.091.1 and LLVM 10.0.0
   built with LDC - the LLVM D compiler (1.21.0)
   Default target: x86_64-unknown-linux-gnu
   Host CPU: bdver2

More information about the Digitalmars-d mailing list