Skip to content

Commit 18f0827

Browse files
authored
Merge pull request #1273 from diffblue/input_and_output
Verilog: prevent redeclaration of module ports
2 parents 9be7670 + cf84872 commit 18f0827

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
KNOWNBUG
1+
CORE
22
input_and_output.v
33

4+
^file .* line 4: port `x' is alrady declared$
45
^EXIT=2$
56
^SIGNAL=0$
67
--
78
--
8-
This should be errored, as some_var must not be both input and output.

src/verilog/verilog_elaborate.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,23 @@ void verilog_typecheckt::collect_symbols(const verilog_declt &decl)
286286
{
287287
symbolt &osymbol = *result;
288288

289+
// 1800-2017 23.2.2.1
290+
// "Once a name is used in a port declaration, it shall not be declared
291+
// again in another port declaration"
292+
if(osymbol.is_input || osymbol.is_output)
293+
{
294+
throw errort().with_location(declarator.source_location())
295+
<< "port `" << symbol.base_name << "' is alrady declared";
296+
}
297+
289298
if(symbol.type != osymbol.type)
290299
{
291300
if(get_width(symbol.type) > get_width(osymbol.type))
292301
osymbol.type = symbol.type;
293302
}
294303

295-
osymbol.is_input = symbol.is_input || osymbol.is_input;
296-
osymbol.is_output = symbol.is_output || osymbol.is_output;
304+
osymbol.is_input = symbol.is_input;
305+
osymbol.is_output = symbol.is_output;
297306
osymbol.is_state_var = symbol.is_state_var || osymbol.is_state_var;
298307

299308
// a register can't be an input as well

0 commit comments

Comments
 (0)