D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)
Summary: @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bound...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2019-11-10 03:16 UTC by asumface
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description asumface 2019-11-10 03:16:03 UTC
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.
Comment 1 basile-z 2019-11-10 03:53:35 UTC
reduced w/o phobos. should not compile

---
struct Foo
{
    this(ref scope Foo);
}

ubyte fun()
{
    return Foo();
}

void main(){} 
---

should fail with

---
Error: cannot implicitly convert expression `Foo()` of type `Foo` to `ubyte`
---
Comment 2 Dlang Bot 2019-11-11 09:29:18 UTC
@RazvanN7 created dlang/dmd pull request #10558 "Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)" mentioning this issue:

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

https://github.com/dlang/dmd/pull/10558
Comment 3 Dlang Bot 2019-11-12 10:51:26 UTC
dlang/dmd pull request #10558 "Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)" was merged into stable:

- ab5518692cbe8b1d2ab2618c093ca3a569a63ace by RazvanN7:
  Fix Issue 20376 - @disable this(ref return scope Foo rhs) enables broken binaries (out-of-bounds access)

https://github.com/dlang/dmd/pull/10558