Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REG2.065] Issue 14207 - [CTFE] ICE on unsupported reinterpret cast in compile time #4545

Merged
merged 1 commit into from Apr 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/ctfeexpr.c
Expand Up @@ -652,8 +652,15 @@ bool isSafePointerCast(Type *srcPointee, Type *destPointee)
// It's OK if they are the same size (static array of) integers, eg:
// int* --> uint*
// int[5][] --> uint[5][]
return srcPointee->baseElemOf()->isintegral() &&
destPointee->baseElemOf()->isintegral() &&
if (srcPointee->ty == Tsarray && destPointee->ty == Tsarray)
{
if (srcPointee->size() != destPointee->size())
return false;
srcPointee = srcPointee->baseElemOf();
destPointee = destPointee->baseElemOf();
}
return srcPointee->isintegral() &&
destPointee->isintegral() &&
srcPointee->size() == destPointee->size();
}

Expand Down
8 changes: 8 additions & 0 deletions src/interpret.c
Expand Up @@ -6834,6 +6834,14 @@ void setValueWithoutChecking(VarDeclaration *vd, Expression *newval)

void setValue(VarDeclaration *vd, Expression *newval)
{
#if 0
if (! ((vd->storage_class & (STCout | STCref))
? isCtfeReferenceValid(newval)
: isCtfeValueValid(newval)) )
{
printf("[%s] vd = %s %s, newval = %s\n", vd->loc.toChars(), vd->type->toChars(), vd->toChars(), newval->toChars());
}
#endif
assert((vd->storage_class & (STCout | STCref))
? isCtfeReferenceValid(newval)
: isCtfeValueValid(newval));
Expand Down
22 changes: 22 additions & 0 deletions test/fail_compilation/ctfe14207.d
@@ -0,0 +1,22 @@
/*
TEST_OUTPUT:
---
fail_compilation/ctfe14207.d(13): Error: cannot convert &immutable(ulong) to ubyte[8]* at compile time
fail_compilation/ctfe14207.d(18): called from here: nativeToBigEndian()
fail_compilation/ctfe14207.d(22): called from here: digest()
---
*/

ubyte[8] nativeToBigEndian()
{
immutable ulong res = 1;
return *cast(ubyte[8]*) &res;
}

auto digest()
{
ubyte[8] bits = nativeToBigEndian();
return bits;
}

enum h = digest();