www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23514] New: Incorrect compilation when adding a 64-bit

https://issues.dlang.org/show_bug.cgi?id=23514

          Issue ID: 23514
           Summary: Incorrect compilation when adding a 64-bit constant to
                    a link-time address
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: zyedidia stanford.edu

This code adds a large constant to the address of main, but the offset is
truncated to 32 bits by the compiler, resulting in an incorrect result.

```
enum offset = 0xFFFF_FFFF_0000_0000UL;
extern (C) void main() {
    assert((cast(ulong)&main) != (cast(ulong)&main + offset));
}
```

The assertion should pass (&main should not equal &main + 64-bit constant), but
it fails.

The assertion fails with DMD master and LDC 1.30.0 (didn't test on master), but
passes with GDC 10.3.0.

I will open a PR with the small fix for this shortly.

--
Nov 27 2022