Skip to content

Commit

Permalink
Fix some cppcheck warnings and bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
caryr committed Dec 20, 2015
1 parent 2aaa050 commit 399384d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
3 changes: 2 additions & 1 deletion Module.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998-2010 Stephen Williams ([email protected])
* Copyright (c) 1998-2015 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -32,6 +32,7 @@ Module::Module(LexicalScope*parent, perm_string n)
{
library_flag = false;
is_cell = false;
is_interface = false;
program_block = false;
uc_drive = UCD_NONE;
timescale_warn_done = false;
Expand Down
4 changes: 2 additions & 2 deletions cppcheck.sup
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// These are correct and are used to find the base (zero) pin.
thisSubtraction:netlist.h:4976
thisSubtraction:netlist.h:4985
thisSubtraction:netlist.h:4991
thisSubtraction:netlist.h:5000
28 changes: 12 additions & 16 deletions elab_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ unsigned PECallFunction::test_width_method_(Design*des, NetScope*scope,
return 0;

perm_string member_name;
ivl_type_t member_type = 0;
pform_name_t use_path = path_;
perm_string method_name = peek_tail_name(use_path);
use_path.pop_back();
Expand Down Expand Up @@ -1317,11 +1316,8 @@ unsigned PECallFunction::test_width_method_(Design*des, NetScope*scope,

const netclass_t* class_type = net->class_type();
int midx = class_type->property_idx_from_name(member_name);
if (midx >= 0)
member_type = class_type->get_prop_type(midx);
else
member_type = 0;
use_path = tmp_path;
ivl_type_t member_type = 0;
if (midx >= 0) member_type = class_type->get_prop_type(midx);

use_darray = dynamic_cast<const netdarray_t*> (member_type);

Expand Down Expand Up @@ -1410,7 +1406,7 @@ NetExpr*PECallFunction::cast_to_width_(NetExpr*expr, unsigned wid) const
if (debug_elaborate) {
cerr << get_fileline() << ": PECallFunction::cast_to_width_: "
<< "cast to " << wid
<< " bits " << (signed_flag_?"signed":"unsigned")
<< " bits " << (signed_flag_ ? "signed" : "unsigned")
<< " from expr_width()=" << expr->expr_width() << endl;
}

Expand Down Expand Up @@ -1535,7 +1531,7 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope,

PExpr*expr = parms_[0];

verinum val (expr->has_sign()? verinum::V1 : verinum::V0, 1);
verinum val (expr->has_sign() ? verinum::V1 : verinum::V0, 1);
NetEConst*sub = new NetEConst(val);
sub->set_line(*this);

Expand Down Expand Up @@ -2017,7 +2013,7 @@ static NetExpr* check_for_struct_members(const LineInfo*li,
}

NetESignal*sig = new NetESignal(net);
NetExpr *base = packed_base? packed_base : make_const_val(off);
NetExpr *base = packed_base ? packed_base : make_const_val(off);

if (debug_elaborate) {
cerr << li->get_fileline() << ": debug: check_for_struct_members: "
Expand Down Expand Up @@ -2681,7 +2677,7 @@ unsigned PEConcat::test_width(Design*des, NetScope*scope, width_mode_t&)
expr_is_string = NO;
}

expr_type_ = (expr_is_string==YES)? IVL_VT_STRING : IVL_VT_LOGIC;
expr_type_ = (expr_is_string==YES) ? IVL_VT_STRING : IVL_VT_LOGIC;
signed_flag_ = false;

// If there is a repeat expression, then evaluate the constant
Expand Down Expand Up @@ -3035,7 +3031,7 @@ bool PEIdent::calculate_up_do_width_(Design*des, NetScope*scope,
NetExpr*wid_ex = elab_and_eval(des, scope, index_tail.lsb, -1, true);
NetEConst*wid_c = dynamic_cast<NetEConst*>(wid_ex);

wid = wid_c? wid_c->value().as_ulong() : 0;
wid = wid_c ? wid_c->value().as_ulong() : 0;
if (wid == 0) {
cerr << index_tail.lsb->get_fileline() << ": error: "
"Indexed part widths must be constant and greater than zero."
Expand Down Expand Up @@ -3184,7 +3180,7 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)
bool parts_defined;
calculate_parts_(des, scope, msb, lsb, parts_defined);
if (parts_defined)
use_width = 1 + ((msb>lsb)? (msb-lsb) : (lsb-msb));
use_width = 1 + ((msb>lsb) ? (msb-lsb) : (lsb-msb));
else
use_width = UINT_MAX;
break;
Expand Down Expand Up @@ -3218,7 +3214,7 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)
ivl_assert(*this, 0);
}

if (const netdarray_t*darray = net? net->darray_type() : 0) {
if (const netdarray_t*darray = net ? net->darray_type() : 0) {
switch (use_sel) {
case index_component_t::SEL_BIT:
case index_component_t::SEL_BIT_LAST:
Expand Down Expand Up @@ -3272,7 +3268,7 @@ unsigned PEIdent::test_width(Design*des, NetScope*scope, width_mode_t&mode)
<< net->name() << " is a net, "
<< "type=" << expr_type_
<< ", width=" << expr_width_
<< ", signed_=" << (signed_flag_?"true":"false")
<< ", signed_=" << (signed_flag_ ? "true" : "false")
<< ", use_depth=" << use_depth
<< ", packed_dimensions=" << net->packed_dimensions()
<< ", unpacked_dimensions=" << net->unpacked_dimensions()
Expand Down Expand Up @@ -3936,7 +3932,7 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
if ( !(SYS_TASK_ARG & flags) ) {
// I cannot interpret this identifier. Error message.
cerr << get_fileline() << ": error: Unable to bind "
<< (NEED_CONST & flags ? "parameter" : "wire/reg/memory")
<< ((NEED_CONST & flags) ? "parameter" : "wire/reg/memory")
<< " `" << path_ << "' in `" << scope_path(scope) << "'"
<< endl;
if (scope->need_const_func()) {
Expand Down Expand Up @@ -5626,7 +5622,7 @@ NetEConst* PENumber::elaborate_expr(Design*, NetScope*,
unsigned PEString::test_width(Design*, NetScope*, width_mode_t&)
{
expr_type_ = IVL_VT_BOOL;
expr_width_ = text_? verinum(text_).len() : 0;
expr_width_ = text_ ? verinum(text_).len() : 0;
min_width_ = expr_width_;
signed_flag_ = false;

Expand Down
10 changes: 8 additions & 2 deletions expr_synth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,18 @@ NetNet* NetEConcat::synthesize(Design*des, NetScope*scope, NetExpr*root)
}
}

if (flag == false) return 0;
if (flag == false) {
delete[]tmp;
return 0;
}

ivl_assert(*this, data_type != IVL_VT_NO_TYPE);

/* If this is a replication of zero just return 0. */
if (expr_width() == 0) return 0;
if (expr_width() == 0) {
delete[]tmp;
return 0;
}

/* Make a NetNet object to carry the output vector. */
perm_string path = scope->local_symbol();
Expand Down
8 changes: 4 additions & 4 deletions link_const.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ verinum::V Nexus::driven_value() const
if ((sig->type() == NetNet::SUPPLY0) ||
(sig->type() == NetNet::TRI0)) {
// Multiple drivers are not currently supported.
ivl_assert(*obj, val == verinum::Vz);
ivl_assert(*sig, val == verinum::Vz);
val = verinum::V0;
}
if ((sig->type() == NetNet::SUPPLY1) ||
(sig->type() == NetNet::TRI1)) {
// Multiple drivers are not currently supported.
ivl_assert(*obj, val == verinum::Vz);
ivl_assert(*sig, val == verinum::Vz);
val = verinum::V1;
}
}
Expand Down Expand Up @@ -222,13 +222,13 @@ verinum Nexus::driven_vector() const
if ((sig->type() == NetNet::SUPPLY0) ||
(sig->type() == NetNet::TRI0)) {
// Multiple drivers are not currently supported.
ivl_assert(*obj, val.len() == 0);
ivl_assert(*sig, val.len() == 0);
val = verinum(verinum::V0, width);
}
if ((sig->type() == NetNet::SUPPLY1) ||
(sig->type() == NetNet::TRI1)) {
// Multiple drivers are not currently supported.
ivl_assert(*obj, val.len() == 0);
ivl_assert(*sig, val.len() == 0);
val = verinum(verinum::V1, width);
}
}
Expand Down
4 changes: 2 additions & 2 deletions net_design.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2013 Stephen Williams ([email protected])
* Copyright (c) 2000-2015 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -890,8 +890,8 @@ void Design::add_node(NetNode*net)

void Design::del_node(NetNode*net)
{
assert(net->design_ == this);
assert(net != 0);
assert(net->design_ == this);

/* Interact with the Design::functor method by manipulating the
cur and nxt pointers that it is using. */
Expand Down
5 changes: 3 additions & 2 deletions symbol_search.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003-2012 Stephen Williams ([email protected])
* Copyright (c) 2003-2015 Stephen Williams ([email protected])
* Copyright CERN 2012 / Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
Expand Down Expand Up @@ -66,6 +66,7 @@ static bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
bool prefix_scope = false;
bool recurse_flag = false;

assert(li);
ivl_assert(*li, ! path.empty());
name_component_t path_tail = path.back();
path.pop_back();
Expand Down Expand Up @@ -94,7 +95,7 @@ static bool symbol_search(const LineInfo*li, Design*des, NetScope*scope,
scope = recurse.scope;
prefix_scope = true;

if (scope->is_auto() && li) {
if (scope->is_auto()) {
cerr << li->get_fileline() << ": error: Hierarchical "
"reference to automatically allocated item "
"`" << path_tail.name << "' in path `" << path << "'" << endl;
Expand Down
6 changes: 3 additions & 3 deletions version.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 Stephen Williams ([email protected])
* Copyright (c) 2009-2015 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -29,10 +29,10 @@ static void run_string(const char*txt)
if (cp[0] == '%' && cp[1] != 0) {
switch (cp[1]) {
case 'M':
fprintf(stdout, "%u", VERSION_MAJOR);
fprintf(stdout, "%d", VERSION_MAJOR);
break;
case 'n':
fprintf(stdout, "%u", VERSION_MINOR);
fprintf(stdout, "%d", VERSION_MINOR);
break;
case 'E':
fprintf(stdout, "%s", VERSION_EXTRA);
Expand Down

0 comments on commit 399384d

Please sign in to comment.