VVP: initialize thread flags/words and codespace chunks

vthread_new only cleared flags[4..7] while codegen uses higher
indices; zero all flags and word registers. Value-initialize
codespace chunks so unused opcode slots are not indeterminate.
This commit is contained in:
mjoekhan 2026-07-21 13:18:16 +05:00
parent b8583dff86
commit 621f589e02
2 changed files with 10 additions and 3 deletions

View File

@ -46,7 +46,8 @@ static unsigned current_within_chunk = 0;
void codespace_init(void)
{
assert(current_chunk == 0);
first_chunk = new struct vvp_code_s [code_chunk_size];
/* Value-initialize so unused slots are not random (opcode NULL). */
first_chunk = new struct vvp_code_s [code_chunk_size]();
current_chunk = first_chunk;
current_chunk[0].opcode = &of_ZOMBIE;
@ -64,7 +65,7 @@ vvp_code_t codespace_next(void)
{
if (current_within_chunk == (code_chunk_size-1)) {
current_chunk[code_chunk_size-1].cptr
= new struct vvp_code_s [code_chunk_size];
= new struct vvp_code_s [code_chunk_size]();
current_chunk = current_chunk[code_chunk_size-1].cptr;
/* Put a link opcode on the end of the chunk. */

View File

@ -770,9 +770,15 @@ vthread_t vthread_new(vvp_code_t pc, __vpiScope*scope)
thr->flags[1] = BIT4_1;
thr->flags[2] = BIT4_X;
thr->flags[3] = BIT4_Z;
for (int idx = 4 ; idx < 8 ; idx += 1)
/* Initialize the remaining flags. Older code only cleared 4..7; the
codegen freely uses higher flag indices, so leave nothing
uninitialized for tools like valgrind. */
for (int idx = 4 ; idx < vthread_s::FLAGS_COUNT ; idx += 1)
thr->flags[idx] = BIT4_X;
for (int idx = 0 ; idx < vthread_s::WORDS_COUNT ; idx += 1)
thr->words[idx].w_uint = 0;
scope->threads .insert(thr);
return thr;
}