Add regression tests for for and foreach type identifier names

Check that a for loop variable declaration can use the same name as a
visible typedef, including references from the loop condition and step
expressions.

Also check that procedural foreach can parse an array expression name that
is initially seen as a type identifier. Declare the array after the loop so
the parser sees the outer typedef while parsing the foreach header, then
elaboration resolves the array declaration as a module item.

Use unsigned variables and omit the foreach iterator because these tests do
not depend on signed values or iteration behavior. This lets both tests run
through the vlog95 backend as normal regressions.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2026-07-03 18:54:39 -07:00
parent 9ec8f8e2dd
commit a540a7a163
5 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,32 @@
// Check that for loop variables can shadow visible type identifiers.
typedef int T;
module test;
reg failed;
int unsigned values [3];
initial begin
int unsigned total;
failed = 1'b0;
total = 0;
for (int unsigned T = 0; T < 3; T += 1) begin
total += T;
values[T] = 10 + T;
end
if (total != 3 || values[0] != 10 ||
values[1] != 11 || values[2] != 12) begin
$display("FAILED(%0d). for loop variable did not hide typedef", `__LINE__);
failed = 1'b1;
end
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,25 @@
// Check that foreach array expressions can shadow visible type identifiers.
typedef int A;
module test;
reg failed;
initial begin
failed = 1'b0;
// The array declaration follows the foreach loop, so the lexer only sees
// the visible typedef when parsing the array expression name.
foreach (A[]) begin
failed = 1'b1;
end
if (!failed) begin
$display("PASSED");
end
end
int unsigned A [3];
endmodule

View File

@ -398,6 +398,8 @@ sv_type_identifier_block_label_name vvp_tests/sv_type_identifier_block_label_nam
sv_type_identifier_config_name vvp_tests/sv_type_identifier_config_name.json
sv_type_identifier_enum_item_name vvp_tests/sv_type_identifier_enum_item_name.json
sv_type_identifier_event_name vvp_tests/sv_type_identifier_event_name.json
sv_type_identifier_for_name vvp_tests/sv_type_identifier_for_name.json
sv_type_identifier_foreach_array_name vvp_tests/sv_type_identifier_foreach_array_name.json
sv_type_identifier_foreach_name vvp_tests/sv_type_identifier_foreach_name.json
sv_type_identifier_fork_label_name vvp_tests/sv_type_identifier_fork_label_name.json
sv_type_identifier_function_name vvp_tests/sv_type_identifier_function_name.json

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_type_identifier_for_name.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_type_identifier_foreach_array_name.v",
"iverilog-args" : [ "-g2005-sv" ]
}