www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22311] New: dmd slice length is wrong on DWARF

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

          Issue ID: 22311
           Summary: dmd slice length is wrong on DWARF
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: DebugInfo
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxhaton gmail.com

Compile this simple code (on 64 bit):

---
int[] x;
static assert(x.length.sizeof == 8);
---

Now run the binary through pahole, we get:

---
struct _Array_int {
        uint long                  length;               /*     0     4 */

        /* XXX 4 bytes hole, try to pack */

        int *                      ptr;                  /*     8     8 */

        /* size: 16, cachelines: 1, members: 2 */
        /* sum members: 12, holes: 1, sum holes: 4 */
        /* last cacheline: 16 bytes */
};
---

i.e. the debug info says the slice has a length of 4bytes, this is clearly
wrong.

GDB agrees
---
/* offset    |  size */  type = struct _Array_int {
/*    0      |     4 */    ulong length;
/* XXX  4-byte hole  */
/*    8      |     8 */    int *ptr;

                           /* total size (bytes):   16 */
                         }
---

--
Sep 17 2021