Skip to content

Commit

Permalink
Merge pull request #3479 from 9rnsr/fix11535
Browse files Browse the repository at this point in the history
Issue 11535 - CTFE ICE on reassigning a static array initialized with block assignment
  • Loading branch information
AndrejMitrovic committed Apr 21, 2014
2 parents 107999e + 64c27cb commit 0a95cd4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/constfold.c
Expand Up @@ -1366,7 +1366,7 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
return e;
}

/* Set a slice of char array literal 'existingAE' from a string 'newval'.
/* Set a slice of char/integer array literal 'existingAE' from a string 'newval'.
* existingAE[firstIndex..firstIndex+newval.length] = newval.
*/
void sliceAssignArrayLiteralFromString(ArrayLiteralExp *existingAE, StringExp *newval, size_t firstIndex)
Expand Down
4 changes: 2 additions & 2 deletions src/interpret.c
Expand Up @@ -4517,9 +4517,9 @@ class Interpreter : public Visitor
return newval;
}
else if (newval->op == TOKstring && existingAE
&& existingAE->type->isString())
&& existingAE->type->nextOf()->isintegral())
{
/* Mixed slice: it was initialized as an array literal of chars.
/* Mixed slice: it was initialized as an array literal of chars/integers.
* Now a slice of it is being set with a string.
*/
sliceAssignArrayLiteralFromString(existingAE, (StringExp *)newval, (size_t)firstIndex);
Expand Down
26 changes: 26 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -6073,6 +6073,32 @@ bool test11941b()
}
static assert(test11941b());

/**************************************************
11535 - element-wise assignment from string to ubyte array literal
**************************************************/

struct Hash11535
{
ubyte[6] _buffer;

void put(scope const(ubyte)[] data...)
{
uint i = 0, index = 0;
auto inputLen = data.length;

(&_buffer[index])[0 .. inputLen-i] = (&data[i])[0 .. inputLen-i];
}
}

auto md5_digest11535(T...)(scope const T data)
{
Hash11535 hash;
hash.put(cast(const(ubyte[]))data[0]);
return hash._buffer;
}

static assert(md5_digest11535(`TEST`) == [84, 69, 83, 84, 0, 0]);

/**************************************************
11540 - goto label + try-catch-finally / with statement
**************************************************/
Expand Down

0 comments on commit 0a95cd4

Please sign in to comment.