mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
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:
parent
b04a1caeac
commit
457d1a66f2
@ -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())) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user