Cause and fix

downs default_357-line at yahoo.de
Sun Jun 29 13:18:53 PDT 2008


Simon Buerger wrote:
> hi
> 
> From my point of view, the following piece of code does really strange
> thing:
> 
> write("{}", cast(void*)0xFFFF_FFFF_FFFF_FFFF_UL); // prints
> ffffffffffff, OK
> write(cast(ulong*)0xFFFF_FFFF_FFFF_FFFF_UL); // prints ffffffffffff, OK
> write("{}", cast(ulong*)cast(void*)0xFFFF_FFFF_FFFF_FFFF_UL); // prints
> ffffffff,  not OK
> 
> Its not a question of output routine, I've checked it in different
> envirovments and with different values. It simply cuts of the higher 32
> bit part of the address. Could, please, somebody explain me that
> behavior? For me, it looks like a compiler bug, but that seems
> impossible for such an obvious thing...
> 
> my system:
> AMD64, Ubuntu Linux,
> gdc (GCC) 4.1.2 20070214 ( gdc 0.24, using dmd 1.024)
> (according to gdc --version)

It's a bug with the integer conversion routines in DMD's frontend.

I quote expression.c: IntegerExp::toInteger
	    case Tpointer:
	    case Tdchar:
	    case Tuns32:	value = (d_uns32) value;	break;

The following (SVN) patch fixes it:

Index: expression.c
===================================================================
--- expression.c        (Revision 231)
+++ expression.c        (Arbeitskopie)
@@ -1128,10 +1128,15 @@
            case Twchar:
            case Tuns16:        value = (d_uns16) value;        break;
            case Tint32:        value = (d_int32) value;        break;
+#ifndef __x86_64__
            case Tpointer:
+#endif
            case Tdchar:
            case Tuns32:        value = (d_uns32) value;        break;
            case Tint64:        value = (d_int64) value;        break;
+#ifdef __x86_64__
+           case Tpointer:
+#endif
            case Tuns64:        value = (d_uns64) value;        break;

            case Tenum:


More information about the D.gnu mailing list