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

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-10T03:16:03Z
Last change time
2020-03-21T03:56:36Z
Keywords
wrong-code
Assigned to
No Owner
Creator
asumface

Comments

Comment #0 by asumface — 2019-11-10T03:16:03Z
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 by b2.temp — 2019-11-10T03:53:35Z
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 by dlang-bot — 2019-11-11T09:29:18Z
@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 by dlang-bot — 2019-11-12T10:51:26Z
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