digitalmars.D.bugs - [Issue 21504] New: Incorrect eponymous overload called by codegen
- d-bugmail puremagic.com (50/50) Dec 26 2020 https://issues.dlang.org/show_bug.cgi?id=21504
https://issues.dlang.org/show_bug.cgi?id=21504 Issue ID: 21504 Summary: Incorrect eponymous overload called by codegen Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: safe, wrong-code Severity: critical Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: dlang-bugzilla thecybershadow.net See the following program. According to semantics (return value), we call one overload, but codegen actually calls another: //////////////////////////// test.d /////////////////////////// safe: template toHex() { char[] toHex(in ubyte[] data, char[] buf) pure { assert(false, "Completely irrelevant overload"); } char[n*2] toHex(size_t n)(in ubyte[n] data) pure { char[n*2] buf; return buf; } string toHex(in ubyte[] data) pure { assert(false, "Should not be called"); // Is called } } void main() { ubyte[40] hmacBytes; // Semantics thinks that this will call the second overload // (returning a static array), // but codegen actually calls the third overload! auto hmac = hmacBytes.toHex(); // Yes, according to the type of the return value, // we called the second overload: static assert(is(typeof(hmac) == char[80])); } /////////////////////////////////////////////////////////////// This seems to further confuse the compiler, and cause invalid slices to be passed to further consumers of the return value, leading to segfaults / memory corruption. --
Dec 26 2020