[Issue 19668] New: calling a function causes crash - frame pointer access error can be bypassed with typeof(this).init

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 11 18:15:45 UTC 2019


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

          Issue ID: 19668
           Summary: calling a function causes crash - frame pointer access
                    error can be bypassed with typeof(this).init
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ali.akhtarzada at gmail.com

The following code causes a crash at runtime:

struct S(alias fun) {
    auto call(Args...)(Args args) {
        return fun(args);
    }
    static auto construct() {
        auto a = typeof(this).init; // 1
        return a;
    }
}

void main() {
    int count = 0;
    auto func() {
        return count++; // 2
    }

    auto s = S!func.construct; // 3

    s.call(); // crashes
}

@1 if you change it to S!fun you get a compiler Error: cannot access frame
pointer of onlineapp.main.S!(func).S.

@2 if you remove the "count" variable access from inside func, and just return
some literal, then there's no crash (no frame pointer access)

@3 if you don't use construct and just call S!func() then s.call doesn't crash
(frame pointer is accessed fine in this case??)

It seems like a regression from dmd version 2.071.2 since it gave a compiler
error from 2.061 up till 2.071.2

Up to      2.060  : Failure with output: --- killed by signal 11
2.061   to 2.071.2: Failure with output:
-----
onlineapp.d(5): Error: function onlineapp.main.S!(func).S.call!().call cannot
access frame of function D main
onlineapp.d(20): Error: template instance onlineapp.main.S!(func).S.call!()
error instantiating
-----

Since      2.072.2: Failure with output: Error: program killed by signal 11

--


More information about the Digitalmars-d-bugs mailing list