[Issue 23815] New: closure allocated even if the escape is opnly used to access static members

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 29 19:41:05 UTC 2023


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

          Issue ID: 23815
           Summary: closure allocated even if the escape is opnly used to
                    access static members
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Keywords: performance
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: b2.temp at gmx.com

# Summary

D allocates a closure for an escaped aggregate instance even if only used to
access a static member.

# Example

```d
class C
{
    static int i;
}

auto v(C c)
{
    return {return c.i;}(); // it thinks `c` is escaped
}
```

# IR output

This is not a LDC bug but we can verify more easily that a closure is allocated
using its IR output: https://godbolt.org/z/j3EvorjzY.

Note that it is not a dup of 17804. Here the escape is well on the stack, it is
really that there should not be any escape.

--


More information about the Digitalmars-d-bugs mailing list