Bug 14207 – [REG2.065] [CTFE] ICE on unsupported reinterpret cast in compile time
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-20T13:01:00Z
Last change time
2015-06-17T21:04:09Z
Keywords
CTFE, ice, pull
Assigned to
nobody
Creator
electrolysis.jp+d
Comments
Comment #0 by electrolysis.jp+d — 2015-02-20T13:01:18Z
test.d:
---
import std.digest.sha;
enum h = digest!SHA1("abc"); // I'm not interested in whether this is valid
---
DMD 2.067.0-b2 dies with:
Assertion failure: '(vd->storage_class & (STCout | STCref)) ? isCtfeReferenceValid(newval) : isCtfeValueValid(newval)' on line 6724 in file 'interpret.c'
On the other hand, DMD 2.066.1 throws:
D:\d\dmd2\windows\bin\..\..\src\phobos\std\digest\sha.d(757): Error: cannot cast ubyte[8] to const(ubyte)[]
D:\d\dmd2\windows\bin\..\..\src\phobos\std\digest\sha.d(765): called from here: this.put(cast(const(ubyte)[])bits)
D:\d\dmd2\windows\bin\..\..\src\phobos\std\digest\digest.d(435): called from here: hash.finish()
test.d(2): called from here: digest("abc")
Comment #1 by k.hara.pg — 2015-04-02T02:28:44Z
This is a regression from 2.065, introduced by the pull request:
https://github.com/D-Programming-Language/dmd/pull/2612
And in 2.067, my CTFE interpreter improvement changed the appearance of the issue.
Reduced case:
ubyte[8] nativeToBigEndian()
{
immutable ulong res = 1;
return *cast(ubyte[8]*) &res;
}
auto digest()
{
ubyte[8] bits = nativeToBigEndian();
return bits;
}
// With 2.064, CTFE makes errors, but with 2.065 or later, it's silently accepted.
enum h = digest();
void main()
{
// With 2.065 or later, following code makes ICE in 'expression.c'
//pragma(msg, h);
// With 2.065 or later, following code makes ICE in 'expression.c' or 'e2ir.c'
import std.stdio;
auto a = h;
writeln(a);
}
Compiler fix:
https://github.com/D-Programming-Language/dmd/pull/4545
Comment #2 by github-bugzilla — 2015-04-04T20:49:10Z