Skip to content

Commit 634595e

Browse files
authored
Merge pull request #700 from diffblue/wire_and_reg-fix
Verilog: error redeclaration of variable
2 parents 2a0e75f + 43573b7 commit 634595e

File tree

4 files changed

+19
-21
lines changed

4 files changed

+19
-21
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
inout_and_reg.v
33

4-
^file .* line 4: symbol `some_var' is declared both as input and as register$
4+
^file .* line 4: variable `some_var' is already declared, at file .* line 3$
55
^EXIT=2$
66
^SIGNAL=0$
77
--
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
input_and_reg.v
33

4-
^file .* line 4: symbol `some_var' is declared both as input and as register$
4+
^file .* line 4: variable `some_var' is already declared, at file .* line 3$
55
^EXIT=2$
66
^SIGNAL=0$
77
--
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
wire_and_reg.v
33

4+
^file .* line 4: variable `some_var' is already declared, at file .* line 3$
45
^EXIT=2$
56
^SIGNAL=0$
67
--
78
--
8-
This should be errored, as some_var must not be both wire and reg.

src/verilog/verilog_elaborate.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -485,34 +485,32 @@ void verilog_typecheckt::collect_symbols(const verilog_declt &decl)
485485

486486
if(result == nullptr)
487487
{
488+
// fresh identifier
488489
symbol_table.add(symbol);
489490
}
490491
else
491492
{
492493
symbolt &osymbol = *result;
493494

494-
if(osymbol.type.id() == ID_code)
495+
// we allow re-declaration if the original symbol
496+
// is an output (not: an input/output).
497+
if(osymbol.is_output && !osymbol.is_input)
495498
{
496-
throw errort().with_location(decl.source_location())
497-
<< "symbol `" << symbol.base_name << "' is already declared";
498-
}
499+
// The type isn't required to match.
500+
// We'll make it bigger, if need be.
501+
if(symbol.type != osymbol.type)
502+
{
503+
if(get_width(symbol.type) > get_width(osymbol.type))
504+
osymbol.type = symbol.type;
505+
}
499506

500-
if(symbol.type != osymbol.type)
501-
{
502-
if(get_width(symbol.type) > get_width(osymbol.type))
503-
osymbol.type = symbol.type;
507+
osymbol.is_state_var = true;
504508
}
505-
506-
osymbol.is_input = symbol.is_input || osymbol.is_input;
507-
osymbol.is_output = symbol.is_output || osymbol.is_output;
508-
osymbol.is_state_var = symbol.is_state_var || osymbol.is_state_var;
509-
510-
// a register can't be an input as well
511-
if(osymbol.is_input && osymbol.is_state_var)
509+
else
512510
{
513511
throw errort().with_location(decl.source_location())
514-
<< "symbol `" << symbol.base_name
515-
<< "' is declared both as input and as register";
512+
<< "variable `" << symbol.base_name << "' is already declared, at "
513+
<< osymbol.location;
516514
}
517515
}
518516

0 commit comments

Comments
 (0)