Add additional regression for package scoped function calls

Check that width and sign determination works correctly for package scoped
function calls.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-26 12:36:47 -08:00
parent 5634dc6915
commit 7df00d3070
5 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,66 @@
// Check that the signedness of package scoped functions is handled correctly.
package P;
function shortint s();
return -1;
endfunction
function bit [15:0] u();
return -1;
endfunction
endpackage
module test;
bit failed = 1'b0;
`define check(x) \
if (!(x)) begin \
$display("FAILED(%0d): ", `__LINE__, `"x`"); \
failed = 1'b1; \
end
int unsigned x = 10;
int y = 10;
int z;
initial begin
// These all evaluate as signed
`check(P::s() < 0)
`check($signed(P::u()) < 0)
// These all evaluate as unsigned
`check(P::u() > 0)
`check({P::s()} > 0)
`check($unsigned(P::s()) > 0)
`check(P::s() > 16'h0)
// In arithmetic expressions if one operand is unsigned all operands are
// considered unsigned
z = P::u() + x;
`check(z === 65545)
z = P::u() + y;
`check(z === 65545)
z = P::s() + x;
`check(z === 65545)
z = P::s() + y;
`check(z === 9)
// For ternary operators if one operand is unsigned the result is unsigend
z = x ? P::u() : x;
`check(z === 65535)
z = x ? P::u() : y;
`check(z === 65535)
z = x ? P::s() : x;
`check(z === 65535)
z = x ? P::s() : y;
`check(z === -1)
if (!failed) begin
$display("PASSED");
end
end
endmodule

View File

@ -0,0 +1,28 @@
// Check that the signedness of package scoped functions is handled correctly,
// when passing the result of the function to a system function
package P;
function shortint s();
return -1;
endfunction
function bit [15:0] u();
return -1;
endfunction
endpackage
module test;
string s;
initial begin
s = $sformatf("%0d %0d", P::s(), P::u());
if (s == "-1 65535") begin
$display("PASSED");
end else begin
$display("FAILED s=%s", s);
end
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that the width of a package scoped function is reported correctly.
package P;
function bit [22:0] s();
return 0;
endfunction
endpackage
module test;
initial begin
if ($bits(P::s()) == 23) begin
$display("PASSED");
end else begin
$display("FAILED $bits(P::s()) = %0d", $bits(P::s()));
end
end
endmodule

View File

@ -689,6 +689,9 @@ sv_ps_function1 normal,-g2009 ivltests
sv_ps_function2 normal,-g2009 ivltests sv_ps_function2 normal,-g2009 ivltests
sv_ps_function3 normal,-g2009 ivltests sv_ps_function3 normal,-g2009 ivltests
sv_ps_function4 normal,-g2009 ivltests sv_ps_function4 normal,-g2009 ivltests
sv_ps_function5 normal,-g2009 ivltests
sv_ps_function6 normal,-g2009 ivltests
sv_ps_function7 normal,-g2009 ivltests
sv_ps_type1 normal,-g2009 ivltests sv_ps_type1 normal,-g2009 ivltests
sv_ps_type_cast1 normal,-g2009 ivltests sv_ps_type_cast1 normal,-g2009 ivltests
sv_ps_type_cast2 normal,-g2009 ivltests sv_ps_type_cast2 normal,-g2009 ivltests

View File

@ -309,6 +309,7 @@ sv_string5 CE,-g2009 ivltests
sv_string6 CE,-g2009,-pallowsigned=1 ivltests sv_string6 CE,-g2009,-pallowsigned=1 ivltests
sv_string7 CE,-g2009,-pallowsigned=1 ivltests sv_string7 CE,-g2009,-pallowsigned=1 ivltests
sv_string7b CE,-g2009,-pallowsigned=1 ivltests sv_string7b CE,-g2009,-pallowsigned=1 ivltests
sv_ps_function6 CE,-g2009,-pallowsigned=1 ivltests
sv_typedef_fwd_base CE,-g2009 ivltests sv_typedef_fwd_base CE,-g2009 ivltests
vhdl_string_lim CE,-g2005-sv,-pallowsigned=1,ivltests/vhdl_string_lim.vhd ivltests vhdl_string_lim CE,-g2005-sv,-pallowsigned=1,ivltests/vhdl_string_lim.vhd ivltests
vhdl_textio_write CE,-g2005-sv,-pallowsigned=1,ivltests/vhdl_textio_write.vhd ivltests vhdl_textio_write CE,-g2005-sv,-pallowsigned=1,ivltests/vhdl_textio_write.vhd ivltests
@ -989,6 +990,7 @@ sv_package2 normal,-g2009,-pallowsigned=1 ivltests
sv_package5 normal,-g2009,-pallowsigned=1 ivltests sv_package5 normal,-g2009,-pallowsigned=1 ivltests
sv_port_default10 normal,-g2009,-pallowsigned=1 ivltests sv_port_default10 normal,-g2009,-pallowsigned=1 ivltests
sv_port_default11 normal,-g2009,-pallowsigned=1 ivltests sv_port_default11 normal,-g2009,-pallowsigned=1 ivltests
sv_ps_function5 normal,-g2009,-pallowsigned=1 ivltests
sv_root_func normal,-g2009,-pallowsigned=1 ivltests gold=sv_root_func.gold sv_root_func normal,-g2009,-pallowsigned=1 ivltests gold=sv_root_func.gold
sv_root_task normal,-g2009,-pallowsigned=1 ivltests gold=sv_root_task.gold sv_root_task normal,-g2009,-pallowsigned=1 ivltests gold=sv_root_task.gold
sv_var_block normal,-g2005-sv,-pallowsigned=1 ivltests sv_var_block normal,-g2005-sv,-pallowsigned=1 ivltests