Add regression tests for checking constant function call scopes.

This commit is contained in:
Martin Whitaker 2024-06-30 11:52:00 +01:00
parent f3092bba93
commit 5cbdff202e
8 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,3 @@
ivltests/constfunccall3.v:21: error: A function invoked by a constant function must be a constant function local to the current module or provided by a package.
ivltests/constfunccall3.v:26: error: `f2' is not a constant function.
2 error(s) during elaboration.

View File

@ -0,0 +1,32 @@
// Check that a constant function call is permitted when the call is inside
// a named block (issue #1141)
module test;
function integer f1(input integer i);
begin
f1 = i + 1;
end
endfunction
function integer f2(input integer i);
begin : b2
f2 = f1(i);
end
endfunction
localparam p = f2(1);
initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,36 @@
// Check that a constant function call is permitted when the function is
// provided by a package.
package p1;
function integer f1(input integer i);
begin
f1 = i + 1;
end
endfunction
endpackage
module test;
function integer f2(input integer i);
begin
f2 = p1::f1(i);
end
endfunction
localparam p = f2(1);
initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end
endmodule

View File

@ -0,0 +1,36 @@
// Check that a constant function call is permitted when the function is
// provided by a package.
module m1;
function integer f1(input integer i);
begin
f1 = i + 1;
end
endfunction
endmodule
module test;
function integer f2(input integer i);
begin
f2 = m1.f1(i);
end
endfunction
localparam p = f2(1);
initial begin
$display(p);
if (p === 2)
$display("PASSED");
else
$display("FAILED");
end
endmodule

View File

@ -68,6 +68,9 @@ constfunc17 vvp_tests/constfunc17.json
constfunc18 vvp_tests/constfunc18.json
constfunc19 vvp_tests/constfunc19.json
constfunc20 vvp_tests/constfunc20.json
constfunccall1 vvp_tests/constfunccall1.json
constfunccall2 vvp_tests/constfunccall2.json
constfunccall3 vvp_tests/constfunccall3.json
decl_before_use1 vvp_tests/decl_before_use1.json
decl_before_use2 vvp_tests/decl_before_use2.json
decl_before_use3 vvp_tests/decl_before_use3.json

View File

@ -0,0 +1,4 @@
{
"type" : "normal",
"source" : "constfunccall1.v"
}

View File

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

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "constfunccall3.v",
"gold" : "constfunccall3"
}