Fix VPI memory word indexing (#2695)

* Test that indexing into memory word fails

* VPI: don't index into memory word

Memory and memory words share a VerilatedVar, so check for memory word before attempting to index.
This commit is contained in:
Marlon James 2020-12-12 19:47:47 -08:00 committed by GitHub
parent b04a1caeac
commit 457d1a66f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -1146,8 +1146,11 @@ vpiHandle vpi_handle_by_index(vpiHandle object, PLI_INT32 indx) {
// Used to get array entries
VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_handle_by_index %p %d\n", object, indx););
VerilatedVpiImp::assertOneCheck();
VerilatedVpioVar* varop = VerilatedVpioVar::castp(object);
_VL_VPI_ERROR_RESET();
// Memory words are not indexable
VerilatedVpioMemoryWord* vop = VerilatedVpioMemoryWord::castp(object);
if (VL_UNLIKELY(vop)) return nullptr;
VerilatedVpioVar* varop = VerilatedVpioVar::castp(object);
if (VL_LIKELY(varop)) {
if (varop->varp()->dims() < 2) return nullptr;
if (VL_LIKELY(varop->varp()->unpacked().left() >= varop->varp()->unpacked().right())) {

View File

@ -377,7 +377,17 @@ int _mon_check_quad() {
TestVpiHandle vhidx2 = vpi_handle_by_index(vh2, 2);
CHECK_RESULT_NZ(vhidx2);
TestVpiHandle vhidx3 = vpi_handle_by_index(vh2, 3);
CHECK_RESULT_NZ(vhidx2);
CHECK_RESULT_NZ(vhidx3);
// Memory words should not be indexable
TestVpiHandle vhidx3idx0 = vpi_handle_by_index(vhidx3, 0);
CHECK_RESULT(vhidx3idx0, 0);
TestVpiHandle vhidx2idx2 = vpi_handle_by_index(vhidx2, 2);
CHECK_RESULT(vhidx2idx2, 0);
TestVpiHandle vhidx3idx3 = vpi_handle_by_index(vhidx3, 3);
CHECK_RESULT(vhidx3idx3, 0);
TestVpiHandle vhidx2idx61 = vpi_handle_by_index(vhidx2, 61);
CHECK_RESULT(vhidx2idx61, 0);
v.format = vpiVectorVal;
v.value.vector = vv;