From 031fbac5be92e57113ca6cebf6aab504ef6cf5ac Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 7 Apr 2022 11:52:56 +0200 Subject: [PATCH] Add regression tests for signed class properties Check that the signedness of class properties is handled correctly * When sign extending * When passing as a value to a system function Check this for both when accessing the property from within a class method as well as accessing it on a class object. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_class_property_signed1.v | 66 +++++++++++++++++++ ivtest/ivltests/sv_class_property_signed2.v | 25 ++++++++ ivtest/ivltests/sv_class_property_signed3.v | 71 +++++++++++++++++++++ ivtest/ivltests/sv_class_property_signed4.v | 30 +++++++++ ivtest/regress-sv.list | 4 ++ ivtest/regress-vlog95.list | 4 ++ 6 files changed, 200 insertions(+) create mode 100644 ivtest/ivltests/sv_class_property_signed1.v create mode 100644 ivtest/ivltests/sv_class_property_signed2.v create mode 100644 ivtest/ivltests/sv_class_property_signed3.v create mode 100644 ivtest/ivltests/sv_class_property_signed4.v diff --git a/ivtest/ivltests/sv_class_property_signed1.v b/ivtest/ivltests/sv_class_property_signed1.v new file mode 100644 index 000000000..b59f2973c --- /dev/null +++ b/ivtest/ivltests/sv_class_property_signed1.v @@ -0,0 +1,66 @@ +// Check that the signedness of class properties are handled correctly when +// accessing the property on a class object. + +module test; + + bit failed = 1'b0; + + `define check(x) \ + if (!(x)) begin \ + $display("FAILED(%0d): ", `__LINE__, `"x`"); \ + failed = 1'b1; \ + end + + class C; + shortint s = -1; + bit [15:0] u = -1; + endclass + + C c; + + int unsigned x = 10; + int y = 10; + int z; + + initial begin + c = new; + + // These all evaluate as signed + `check(c.s < 0) + `check($signed(c.u) < 0) + + // These all evaluate as unsigned + `check(c.u > 0) + `check({c.s} > 0) + `check($unsigned(c.s) > 0) + `check(c.s > 16'h0) + + // In arithmetic expressions if one operand is unsigned all operands are + // considered unsigned + z = c.u + x; + `check(z === 65545) + z = c.u + y; + `check(z === 65545) + + z = c.s + x; + `check(z === 65545) + z = c.s + y; + `check(z === 9) + + // For ternary operators if one operand is unsigned the result is unsigend + z = x ? c.u : x; + `check(z === 65535) + z = x ? c.u : y; + `check(z === 65535) + + z = x ? c.s : x; + `check(z === 65535) + z = x ? c.s : y; + `check(z === -1) + + if (!failed) begin + $display("PASSED"); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_class_property_signed2.v b/ivtest/ivltests/sv_class_property_signed2.v new file mode 100644 index 000000000..01745dcd2 --- /dev/null +++ b/ivtest/ivltests/sv_class_property_signed2.v @@ -0,0 +1,25 @@ +// Check that the signedness of class properties are handled correctly when +// accessing the property on a class object and passing it to a system function. + +module test; + + class C; + shortint s = -1; + bit [15:0] u = -1; + endclass + + C c; + string s; + + initial begin + c = new; + + s = $sformatf("%0d %0d", c.s, c.u); + if (s == "-1 65535") begin + $display("PASSED"); + end else begin + $display("FAILED s=%s", s); + end + end + +endmodule diff --git a/ivtest/ivltests/sv_class_property_signed3.v b/ivtest/ivltests/sv_class_property_signed3.v new file mode 100644 index 000000000..9b4a81f5e --- /dev/null +++ b/ivtest/ivltests/sv_class_property_signed3.v @@ -0,0 +1,71 @@ +// Check that the signedness of class properties are handled correctly when +// accessing the property in a class method. + +module test; + + bit failed = 1'b0; + + `define check(x) \ + if (!(x)) begin \ + $display("FAILED: ", `"x`", `__LINE__); \ + failed = 1'b1; \ + end + + int unsigned x = 10; + int y = 10; + int z; + + class C; + shortint s = -1; + bit [15:0] u = -1; + + task test; + + // These all evaluate as signed + `check(s < 0) + `check($signed(u) < 0) + + // These all evaluate as unsigned + `check(u > 0) + `check({s} > 0) + `check($unsigned(s) > 0) + `check(s > 16'h0) + + // In arithmetic expressions if one operand is unsigned all operands are + // considered unsigned + z = u + x; + `check(z === 65545) + z = u + y; + `check(z === 65545) + + z = s + x; + `check(z === 65545) + z = s + y; + `check(z === 9) + + // For ternary operators if one operand is unsigned the result is unsigend + z = x ? u : x; + `check(z === 65535) + z = x ? u : y; + `check(z === 65535) + + z = x ? s : x; + `check(z === 65535) + z = x ? s : y; + `check(z === -1) + + if (!failed) begin + $display("PASSED"); + end + endtask + + endclass + + C c; + + initial begin + c = new; + c.test(); + end + +endmodule diff --git a/ivtest/ivltests/sv_class_property_signed4.v b/ivtest/ivltests/sv_class_property_signed4.v new file mode 100644 index 000000000..2d636861b --- /dev/null +++ b/ivtest/ivltests/sv_class_property_signed4.v @@ -0,0 +1,30 @@ +// Check that the signedness of class properties are handled correctly when +// accessing the property in a class method and passing it to a system function. + +module test; + + class C; + shortint s = -1; + bit [15:0] u = -1; + + task test; + string str; + + str = $sformatf("%0d %0d", s, u); + if (str == "-1 65535") begin + $display("PASSED"); + end else begin + $display("FAILED s=%s", s); + end + endtask + + endclass + + C c; + + initial begin + c = new; + c.test(); + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index d1c7b3823..e0503d23c 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -494,6 +494,10 @@ sv_class_new_init normal,-g2009 ivltests sv_class_in_module_decl normal,-g2009 ivltests sv_class_method_signed1 normal,-g2009 ivltests sv_class_method_signed2 normal,-g2009 ivltests +sv_class_property_signed1 normal,-g2009 ivltests +sv_class_property_signed2 normal,-g2009 ivltests +sv_class_property_signed3 normal,-g2009 ivltests +sv_class_property_signed4 normal,-g2009 ivltests sv_class_static_prop1 normal,-g2009 ivltests sv_class_static_prop2 normal,-g2009 ivltests sv_class_static_prop3 normal,-g2009 ivltests diff --git a/ivtest/regress-vlog95.list b/ivtest/regress-vlog95.list index 55628348e..7aa9989e8 100644 --- a/ivtest/regress-vlog95.list +++ b/ivtest/regress-vlog95.list @@ -386,6 +386,10 @@ sv_class_new_init CE,-g2009 ivltests sv_class_in_module_decl CE,-g2009 ivltests sv_class_method_signed1 CE,-g2009,-pallowsigned=1 ivltests sv_class_method_signed2 CE,-g2009,-pallowsigned=1 ivltests +sv_class_property_signed1 CE,-g2009,-pallowsigned=1 ivltests +sv_class_property_signed2 CE,-g2009,-pallowsigned=1 ivltests +sv_class_property_signed3 CE,-g2009,-pallowsigned=1 ivltests +sv_class_property_signed4 CE,-g2009,-pallowsigned=1 ivltests sv_class_static_prop1 CE,-g2009 ivltests sv_class_static_prop2 CE,-g2009 ivltests sv_class_static_prop3 CE,-g2009 ivltests