Bug 14979 – [REG2.068] Wrong tempCString result on x64 with ternary operator

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2015-08-30T02:05:00Z
Last change time
2015-09-02T12:58:56Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
dlang-bugzilla
Depends on
14696

Comments

Comment #0 by dlang-bugzilla — 2015-08-30T02:05:10Z
////////////////////// test.d ///////////////////// enum testStr = "Hello, beautiful world!"; void funA(const char* node) { import core.stdc.string; assert(strcmp(node, testStr)==0); } unittest { string node = testStr; import std.internal.cstring; funA(node is null ? null : node.tempCString()); } /////////////////////////////////////////////////// Introduced in https://github.com/D-Programming-Language/phobos/pull/3415/files Happens only on x64, perhaps this is a codegen bug?
Comment #1 by k.hara.pg — 2015-08-30T02:26:08Z
Perhaps the root is issue 14696.
Comment #2 by k.hara.pg — 2015-08-30T13:51:23Z
OK, I confirmed this is actually a dup of issue 14696. To reproduce the issue, we need to specify -unittest. By that, tempCString will make the buffer size smaller and the used heap memory will be destructed at the wrong timing. auto tempCString(To = char, From)(From str) if (isSomeChar!To && (isInputRange!From || isSomeString!From) && isSomeChar!(ElementEncodingType!From)) { ... static struct Res { ... private: To* _ptr; version (unittest) { enum buffLength = 16 / To.sizeof; // smaller size to trigger reallocations } else { enum buffLength = 256 / To.sizeof; // production size } To[256 / To.sizeof] _buff; // the 'small string optimization'
Comment #3 by k.hara.pg — 2015-08-31T13:15:43Z
Comment #4 by k.hara.pg — 2015-09-02T12:58:56Z