From 225ee65c31f9f90ff5f869bd4698d65c2ef6cd4a Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 10 Oct 2010 15:14:29 -0700 Subject: [PATCH] Fix some vvp initialization problems found with cppcheck. This patch adds a few missing initializations to various constructors in the vvp directory. It also enhances the array alias code to copy more values from the aliased array. --- vvp/array.cc | 39 ++++++++++++++++++-------------- vvp/compile.cc | 12 +++++++--- vvp/compile.h | 4 +++- vvp/delay.h | 5 ++++- vvp/island_tran.cc | 55 ++++++++++++++++++++++++++-------------------- vvp/main.cc | 5 ++++- vvp/schedule.cc | 19 ++++++++++++---- vvp/udp.h | 2 -- vvp/vvp_net.cc | 9 +++++--- 9 files changed, 95 insertions(+), 55 deletions(-) diff --git a/vvp/array.cc b/vvp/array.cc index 1b18175f4..ddb63f9d2 100644 --- a/vvp/array.cc +++ b/vvp/array.cc @@ -81,8 +81,6 @@ vvp_array_t array_find(const char*label) * vector4 array works. */ struct __vpiArray { - __vpiArray() { } - struct __vpiHandle base; struct __vpiScope*scope; const char*name; /* Permanently allocated string */ @@ -1092,11 +1090,8 @@ void compile_real_array(char*label, char*name, int last, int first, arr->valsr = new vvp_realarray_t(arr->array_count); arr->vals_width = 1; - /* Do these even make sense for real arrays? These are the - part select of a vector, but the real value is not - vectorable. */ - vpip_make_dec_const(&arr->msb, msb); - vpip_make_dec_const(&arr->lsb, lsb); + /* For a real array the MSB and LSB must be zero. */ + assert(msb == 0 && lsb == 0); count_real_arrays += 1; count_real_array_words += arr->array_count; @@ -1449,7 +1444,8 @@ bool array_resolv_list_t::resolve(bool mes) class array_port_resolv_list_t : public resolv_list_s { public: - explicit array_port_resolv_list_t(char*lab) : resolv_list_s(lab) { } + explicit array_port_resolv_list_t(char* lab, bool use_addr__, + long addr__); vvp_net_t*ptr; bool use_addr; @@ -1459,6 +1455,13 @@ class array_port_resolv_list_t : public resolv_list_s { private: }; +array_port_resolv_list_t::array_port_resolv_list_t(char *lab, bool use_addr__, + long addr__) +: resolv_list_s(lab), use_addr(use_addr__), addr(addr__) +{ + ptr = new vvp_net_t; +} + bool array_port_resolv_list_t::resolve(bool mes) { vvp_array_t mem = array_find(label()); @@ -1513,10 +1516,8 @@ void vpip_array_change(struct __vpiCallback*cb, vpiHandle obj) void compile_array_port(char*label, char*array, char*addr) { array_port_resolv_list_t*resolv_mem - = new array_port_resolv_list_t(array); + = new array_port_resolv_list_t(array, false, 0); - resolv_mem->ptr = new vvp_net_t; - resolv_mem->use_addr = false; define_functor_symbol(label, resolv_mem->ptr); free(label); // Connect the port-0 input as the address. @@ -1528,11 +1529,8 @@ void compile_array_port(char*label, char*array, char*addr) void compile_array_port(char*label, char*array, long addr) { array_port_resolv_list_t*resolv_mem - = new array_port_resolv_list_t(array); + = new array_port_resolv_list_t(array, true, addr); - resolv_mem->ptr = new vvp_net_t; - resolv_mem->use_addr = true; - resolv_mem->addr = addr; define_functor_symbol(label, resolv_mem->ptr); free(label); @@ -1551,16 +1549,25 @@ void compile_array_alias(char*label, char*name, char*src) obj->scope = vpip_peek_current_scope(); obj->name = vpip_name_string(name); obj->array_count = mem->array_count; + obj->signed_flag = mem->signed_flag; - // XXXX Need to set an accurate range of addresses. + // Need to set an accurate range of addresses. vpip_make_dec_const(&obj->first_addr, mem->first_addr.value); vpip_make_dec_const(&obj->last_addr, mem->last_addr.value); + obj->swap_addr = mem->swap_addr; + + vpip_make_dec_const(&obj->msb, mem->msb.value); + vpip_make_dec_const(&obj->lsb, mem->lsb.value); // Share the words with the source array. obj->nets = mem->nets; obj->vals4 = mem->vals4; + obj->valsr = mem->valsr; + obj->vals_width = mem->vals_width; + obj->vals_words = mem->vals_words; obj->ports_ = 0; + obj->vpi_callbacks = 0; assert(array_table); assert(!array_find(label)); diff --git a/vvp/compile.cc b/vvp/compile.cc index bebf3b4c5..60af5af09 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -432,7 +432,9 @@ void functor_ref_lookup(vvp_net_t**ref, char*lab) */ struct vpi_handle_resolv_list_s: public resolv_list_s { - explicit vpi_handle_resolv_list_s(char*lab) : resolv_list_s(lab) { } + explicit vpi_handle_resolv_list_s(char*lab) : resolv_list_s(lab) { + handle = NULL; + } virtual bool resolve(bool mes); vpiHandle *handle; }; @@ -531,7 +533,9 @@ void compile_vpi_lookup(vpiHandle *handle, char*label) */ struct code_label_resolv_list_s: public resolv_list_s { - code_label_resolv_list_s(char*lab) : resolv_list_s(lab) { } + code_label_resolv_list_s(char*lab) : resolv_list_s(lab) { + code = NULL; + } struct vvp_code_s *code; virtual bool resolve(bool mes); }; @@ -564,7 +568,9 @@ void code_label_lookup(struct vvp_code_s *code, char *label) } struct code_array_resolv_list_s: public resolv_list_s { - code_array_resolv_list_s(char*lab) : resolv_list_s(lab) { } + code_array_resolv_list_s(char*lab) : resolv_list_s(lab) { + code = NULL; + } struct vvp_code_s *code; virtual bool resolve(bool mes); }; diff --git a/vvp/compile.h b/vvp/compile.h index 57d1bf111..c94a1a542 100644 --- a/vvp/compile.h +++ b/vvp/compile.h @@ -273,7 +273,9 @@ extern void compile_param_real(char*label, char*name, char*value, class resolv_list_s { public: - explicit resolv_list_s(char*lab) : label_(lab) { } + explicit resolv_list_s(char*lab) : label_(lab) { + next = NULL; + } virtual ~resolv_list_s(); virtual bool resolve(bool mes = false) = 0; diff --git a/vvp/delay.h b/vvp/delay.h index d5f8beefe..567abe4dd 100644 --- a/vvp/delay.h +++ b/vvp/delay.h @@ -75,7 +75,10 @@ class vvp_fun_delay : public vvp_net_fun_t, private vvp_gen_event_s { enum delay_type_t {UNKNOWN_DELAY, VEC4_DELAY, VEC8_DELAY, REAL_DELAY}; struct event_ { - event_(vvp_time64_t s) : sim_time(s) { } + event_(vvp_time64_t s) : sim_time(s) { + ptr_real = 0.0; + next = NULL; + } void (vvp_fun_delay::*run_run_ptr)(struct vvp_fun_delay::event_*cur); const vvp_time64_t sim_time; vvp_vector4_t ptr_vec4; diff --git a/vvp/island_tran.cc b/vvp/island_tran.cc index 14b9bbdcb..091e648e1 100644 --- a/vvp/island_tran.cc +++ b/vvp/island_tran.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 2008-2010 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -36,12 +36,11 @@ struct vvp_island_branch_tran : public vvp_island_branch { // Behavior. (This stuff should be moved to a derived // class. The members here are specific to the tran island // class.) + vvp_island_branch_tran(vvp_net_t*en__, bool active_high__, + unsigned width__, unsigned part__, + unsigned offset__); bool run_test_enabled(); void run_resolution(); - bool active_high; - bool enabled_flag; - vvp_net_t*en; - unsigned width, part, offset; void clear_resolution_flags() { flags_ &= ~0x0f; } @@ -55,10 +54,27 @@ struct vvp_island_branch_tran : public vvp_island_branch { // Use the peek only for diagnostic purposes. int peek_flags() const { return flags_; } + vvp_net_t*en; + unsigned width, part, offset; + bool active_high; + bool enabled_flag; + private: int flags_; }; +vvp_island_branch_tran::vvp_island_branch_tran(vvp_net_t*en__, + bool active_high__, + unsigned width__, + unsigned part__, + unsigned offset__) +: en(en__), width(width__), part(part__), offset(offset__), + active_high(active_high__) +{ + flags_ = 0; + enabled_flag = en__ ? false : true; +} + static inline vvp_island_branch_tran* BRANCH_TRAN(vvp_island_branch*tmp) { vvp_island_branch_tran*res = dynamic_cast(tmp); @@ -410,23 +426,18 @@ void compile_island_tranif(int sense, char*island, char*pa, char*pb, char*pe) assert(use_island); free(island); - vvp_island_branch_tran*br = new vvp_island_branch_tran; - if (sense) - br->active_high = true; - else - br->active_high = false; + vvp_net_t*en = NULL; - if (pe == 0) { - br->en = 0; - } else { - br->en = use_island->find_port(pe); - assert(br->en); + if (pe) { + en = use_island->find_port(pe); + assert(en); free(pe); } - br->width = 0; - br->part = 0; - br->offset = 0; + vvp_island_branch_tran*br = new vvp_island_branch_tran(en, + sense ? true : + false, + 0, 0, 0); use_island->add_branch(br, pa, pb); @@ -442,12 +453,8 @@ void compile_island_tranvp(char*island, char*pa, char*pb, assert(use_island); free(island); - vvp_island_branch_tran*br = new vvp_island_branch_tran; - br->active_high = false; - br->en = 0; - br->width = wid; - br->part = par; - br->offset = off; + vvp_island_branch_tran*br = new vvp_island_branch_tran(NULL, false, + wid, par, off) ; use_island->add_branch(br, pa, pb); diff --git a/vvp/main.cc b/vvp/main.cc index 38f740a92..49df4a98c 100644 --- a/vvp/main.cc +++ b/vvp/main.cc @@ -79,7 +79,10 @@ static void my_getrusage(struct rusage *a) perror("/proc/self/statm"); return; } - if (3<=fscanf(statm, "%u%u%u", &siz, &rss, &shd)) { + /* Given that these are in pages we'll limit the value to + * what will fit in a 32 bit integer to prevent undefined + * behavior in fscanf(). */ + if (3 == fscanf(statm, "%9u %9u %9u", &siz, &rss, &shd)) { a->ru_maxrss = page_size * siz; a->ru_idrss = page_size * rss; a->ru_ixrss = page_size * shd; diff --git a/vvp/schedule.cc b/vvp/schedule.cc index 46091e27f..3b1949914 100644 --- a/vvp/schedule.cc +++ b/vvp/schedule.cc @@ -75,6 +75,7 @@ struct event_time_s { rwsync = 0; rosync = 0; del_thr = 0; + next = NULL; } vvp_time64_t delay; @@ -160,10 +161,16 @@ void del_thr_event_s::single_step_display(void) struct assign_vector4_event_s : public event_s { /* The default constructor. */ - assign_vector4_event_s(const vvp_vector4_t&that) : val(that) { } + assign_vector4_event_s(const vvp_vector4_t&that) : val(that) { + base = 0; + vwid = 0; + } /* A constructor that makes the val directly. */ assign_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid) - : val(that,adr,wid) { } + : val(that,adr,wid) { + base = 0; + vwid = 0; + } /* Where to do the assign. */ vvp_net_ptr_t ptr; @@ -324,10 +331,14 @@ unsigned long count_assign_aword_pool(void) { return array_w_heap.pool; } */ struct propagate_vector4_event_s : public event_s { /* The default constructor. */ - propagate_vector4_event_s(const vvp_vector4_t&that) : val(that) { } + propagate_vector4_event_s(const vvp_vector4_t&that) : val(that) { + net = NULL; + } /* A constructor that makes the val directly. */ propagate_vector4_event_s(const vvp_vector4_t&that, unsigned adr, unsigned wid) - : val(that,adr,wid) { } + : val(that,adr,wid) { + net = NULL; + } /* Propagate the output of this net. */ vvp_net_t*net; diff --git a/vvp/udp.h b/vvp/udp.h index 484cde19a..ee7774b16 100644 --- a/vvp/udp.h +++ b/vvp/udp.h @@ -191,8 +191,6 @@ class vvp_udp_seq_s : public vvp_udp_s { private: - vvp_bit4_t init_; - vvp_bit4_t test_levels_(const udp_levels_table&cur); // Level sensitive rows of the device. diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 976b55cda..5e0bb4fe6 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -42,9 +42,9 @@ permaheap vvp_net_fil_t::heap_; // Allocate around 1Megbytes/chunk. static const size_t VVP_NET_CHUNK = 1024*1024/sizeof(vvp_net_t); -static vvp_net_t*vvp_net_alloc_table = 0; +static vvp_net_t*vvp_net_alloc_table = NULL; #ifdef CHECK_WITH_VALGRIND -static vvp_net_t **vvp_net_pool = 0; +static vvp_net_t **vvp_net_pool = NULL; static unsigned vvp_net_pool_count = 0; #endif static size_t vvp_net_alloc_remaining = 0; @@ -140,7 +140,7 @@ void vvp_net_pool_delete() ::delete [] vvp_net_pool[idx]; } free(vvp_net_pool); - vvp_net_pool = 0; + vvp_net_pool = NULL; vvp_net_pool_count = 0; } #endif @@ -155,6 +155,9 @@ vvp_net_t::vvp_net_t() out_ = vvp_net_ptr_t(0,0); fun = 0; fil = 0; +#ifdef CHECK_WITH_VALGRIND + pool = NULL; +#endif } void vvp_net_t::link(vvp_net_ptr_t port_to_link)