Add regression tests for void casts

Check that it is possible to use a function with a return type as a
statement by using a void cast.

Also check that trying to void cast a void function, a task or an
expression results in an error.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-15 21:14:33 -08:00
parent 0e62ff153d
commit 269e1ca88d
9 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// Check that void casts are supported
module test;
int a;
real b;
string c;
function int f1(int x);
a = x;
return x;
endfunction
function real f2(real x);
b = x;
return x;
endfunction
function string f3(string x);
c = x;
return x;
endfunction
initial begin
void'(f1(10));
void'(f2(1.0));
void'(f3("10"));
if (a === 10 && b == 1.0 && c == "10") begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,41 @@
// Check that void casts on class methods are supported
module test;
int a;
real b;
string c;
class C;
function int f1(int x);
a = x;
return x;
endfunction
function real f2(real x);
b = x;
return x;
endfunction
function string f3(string x);
c = x;
return x;
endfunction
endclass
C d;
initial begin
d = new;
void'(d.f1(10));
void'(d.f2(1.0));
void'(d.f3("10"));
if (a === 10 && b == 1.0 && c == "10") begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that void casts on methods of built-in types is supported
module test;
int q[$];
initial begin
q.push_back(1);
void'(q.pop_back());
if (q.size() === 0) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,11 @@
// Check that void casts on SystemFunctions is supported
module test;
initial begin
void'($clog2(10));
$display("PASSED");
end
endmodule

View File

@ -0,0 +1,12 @@
// Check that void casting a void function results in an error
module test;
function void f(int x);
endfunction
initial begin
void'(f(10));
end
endmodule

View File

@ -0,0 +1,12 @@
// Check that void casting a task results in an error
module test;
task t(int x);
endtask
initial begin
void'(t(10));
end
endmodule

View File

@ -0,0 +1,9 @@
// Check that void casting an expression results in an error
module test;
initial begin
void'(1+2);
end
endmodule

View File

@ -803,6 +803,13 @@ sv_var_module_output1 normal,-g2005-sv ivltests
sv_var_module_output2 normal,-g2005-sv ivltests
sv_var_package normal,-g2005-sv ivltests
sv_var_task normal,-g2005-sv ivltests
sv_void_cast1 normal,-g2005-sv ivltests
sv_void_cast2 normal,-g2005-sv ivltests
sv_void_cast3 normal,-g2005-sv ivltests
sv_void_cast4 normal,-g2005-sv ivltests
sv_void_cast_fail1 CE,-g2005-sv ivltests
sv_void_cast_fail2 CE,-g2005-sv ivltests
sv_void_cast_fail3 CE,-g2005-sv ivltests
sv_wildcard_import1 normal,-g2009 ivltests
sv_wildcard_import2 normal,-g2009 ivltests
sv_wildcard_import3 normal,-g2009 ivltests

View File

@ -515,6 +515,9 @@ sv_typedef_queue_base1 CE,-g2009 ivltests # queue
sv_typedef_queue_base2 CE,-g2009 ivltests # queue
sv_typedef_queue_base3 CE,-g2009 ivltests # queue
sv_typedef_queue_base4 CE,-g2009 ivltests # queue
sv_void_cast1 CE,-g2009,-pallowsigned=1 ivltests # string
sv_void_cast2 CE,-g2009,-pallowsigned=1 ivltests # string, class
sv_void_cast3 CE,-g2009,-pallowsigned=1 ivltests # queue
wait_fork CE,-g2009 ivltests # wait fork and join_*
wild_cmp_err CE,-g2009 ivltests # ==?/!=?
wild_cmp_err2 CE,-g2009 ivltests # ==?/!=?
@ -977,6 +980,7 @@ sv_var_module_output1 normal,-g2005-sv,-pallowsigned=1 ivltests
sv_var_module_output2 normal,-g2005-sv,-pallowsigned=1 ivltests
sv_var_package normal,-g2005-sv,-pallowsigned=1 ivltests
sv_var_task normal,-g2005-sv,-pallowsigned=1 ivltests
sv_void_cast4 normal,-g2009,-pallowsigned=1 ivltests
test_dispwided normal,-pallowsigned=1 ivltests gold=test_dispwided.gold
test_inc_dec normal,-g2009,-pallowsigned=1 ivltests
test_enumsystem normal,-g2009,-pallowsigned=1,ivltests/enumsystem.vhd ivltests