Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #234 (closed defect: fixed)

Opened 15 years ago

Last modified 15 years ago

64 bit pointer assignment truncates to 32 bits

Reported by: wilkie Assigned to: ChristianK
Priority: major Milestone:
Component: unspecified Version: hg tip
Keywords: Cc:

Description

Using: ldc rev 1099

Targeting: x86-64

In Production: xomb:kernel/dev/console:line_65

Note that the print outputs 0xb8000.

First, the code:

void foo() { ubyte* ptr = cast(ubyte*)0xffff8000000b8000UL; }

Produces:

movq $0xb8000, (%RBX) (gas) mov [RBX], 0xb8000 (intel)

Most likely a backend issue, when targeting 64 bit code, a 64 bit (note that here it is a sign extended 48 bit immediate) assignment to a pointer will be truncated to be a 32 bit operation.

Workaround:

void foo() { ulong ptrVal = 0xffff8000000b8000UL; ubyte* ptr = cast(ubyte*)ptrVal; }

Change History

03/15/09 15:04:21 changed by fvbommel

  • status changed from new to closed.
  • resolution set to fixed.

Not a backend issue, a frontend issue. A DMD frontend issue, to be precise: when an IntegerExp? has a pointer type (which is what happens when you cast an integer constant to a pointer), the frontend assumed it was 32-bit, and cleared the upper 32 bits...

Fixed in [1120].

Copyright © 2008, LDC Development Team.