tgt-vvp: Fix out-of-bounds compressed assignment to arrays

If the index of an array access is known to be out-of-bounds during
elaboration it is replaced with 'x. In the tgt-vvp backend that is handling
compressed array assignments there is an assert() that triggers if the
index is an undefined immediate.

There is already an existing code path that is capable of handling
out-of-bounds access. Remove the assert and set the index to ULONG_MAX to
trigger taking the out-of-bound access path.

On this out-of-bounds path the write to the array is skipped. But this
leaves the result on the vector stack. Insert the `%pop/vec4` instruction
to make sure it is removed.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-01-01 10:58:18 +01:00
parent e8bc3bf8dd
commit d746c592b2
1 changed files with 6 additions and 2 deletions

View File

@ -21,6 +21,7 @@
# include <string.h>
# include <assert.h>
# include <stdlib.h>
# include <limits.h>
/*
* These functions handle the blocking assignment. Use the %set
@ -101,8 +102,10 @@ static void get_vec_from_lval_slice(ivl_lval_t lval, struct vec_slice_info*slice
it to select the word, and pay no further heed to the
expression itself. */
if (word_ix && number_is_immediate(word_ix, IMM_WID, 0)) {
assert(! number_is_unknown(word_ix));
use_word = get_number_immediate(word_ix);
if (number_is_unknown(word_ix))
use_word = ULONG_MAX; // The largest valid index is ULONG_MAX - 1
else
use_word = get_number_immediate(word_ix);
word_ix = 0;
}
@ -321,6 +324,7 @@ static void put_vec_to_lval_slice(ivl_lval_t lval, struct vec_slice_info*slice,
clr_word(word_idx);
} else {
fprintf(vvp_out," ; Skip this slice write to v%p [%lu]\n", sig, slice->u_.memory_word_static.use_word);
fprintf(vvp_out," %%pop/vec4 1;\n");
}
break;