[Issue 20376] New: @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 10 03:16:03 UTC 2019


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

          Issue ID: 20376
           Summary: @disable this(ref return scope Foo rhs) enables broken
                    binaries (out-of-bounds access)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: asumface at gmail.com

Consider this example:

struct Foo
{
    @disable this(ref return scope Foo rhs);
}

uint[2000] fun() @safe
{
    return Foo();
}

void main() @safe
{
    import std;
    writeln(fun);
}

This will compile and print garbage data, (although a segfault is probably
possible as well), despite there being an obvious type mismatch.


If the function signature is changed to a non-array type, e. g.

float fun() @safe

LDC will raise:
Invalid bitcast
  %4 = bitcast %onlineapp.Foo* %1 to float, !dbg !1241
in function _D9onlineapp3funFNfZf
LLVM ERROR: Broken function found, compilation aborted!

DMD will not complain and complete the compilation as before.

run.dlang.org suggests that this happens since release 2.086.

--


More information about the Digitalmars-d-bugs mailing list