From 5685eac1beae3cecb436dcc3ea30e6e3c7b2a2e0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sun, 25 Dec 2022 19:21:15 -0800 Subject: [PATCH] Add regression tests for invalid size casts Check that an error is reported for size casts with either a value of 0, a negative value or an undefined value. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/size_cast_fail1.v | 12 ++++++++++++ ivtest/ivltests/size_cast_fail2.v | 12 ++++++++++++ ivtest/ivltests/size_cast_fail3.v | 12 ++++++++++++ ivtest/regress-sv.list | 3 +++ 4 files changed, 39 insertions(+) create mode 100644 ivtest/ivltests/size_cast_fail1.v create mode 100644 ivtest/ivltests/size_cast_fail2.v create mode 100644 ivtest/ivltests/size_cast_fail3.v diff --git a/ivtest/ivltests/size_cast_fail1.v b/ivtest/ivltests/size_cast_fail1.v new file mode 100644 index 000000000..dbd520355 --- /dev/null +++ b/ivtest/ivltests/size_cast_fail1.v @@ -0,0 +1,12 @@ +// Check that an error is reported when using a zero value for a size cast. + +module test; + + localparam integer N = 0; + + initial begin + int x, y; + y = N'(x); // This should fail, N is zero + end + +endmodule diff --git a/ivtest/ivltests/size_cast_fail2.v b/ivtest/ivltests/size_cast_fail2.v new file mode 100644 index 000000000..c7a23ad87 --- /dev/null +++ b/ivtest/ivltests/size_cast_fail2.v @@ -0,0 +1,12 @@ +// Check that an error is reported when using a negative value for a size cast. + +module test; + + localparam integer N = -1; + + initial begin + int x, y; + y = N'(x); // This should fail, N is negative + end + +endmodule diff --git a/ivtest/ivltests/size_cast_fail3.v b/ivtest/ivltests/size_cast_fail3.v new file mode 100644 index 000000000..986c05281 --- /dev/null +++ b/ivtest/ivltests/size_cast_fail3.v @@ -0,0 +1,12 @@ +// Check that an error is reported when using an undefined value for a size cast. + +module test; + + localparam integer N = 32'hx; + + initial begin + int x, y; + y = N'(x); // This should fail, N is undefined + end + +endmodule diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index be291eb87..168f4b82c 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -465,6 +465,9 @@ size_cast2 normal,-g2005-sv ivltests size_cast3 normal,-g2009 ivltests size_cast4 normal,-g2009 ivltests size_cast5 normal,-g2009 ivltests +size_cast_fail1 CE,-g2009 ivltests +size_cast_fail2 CE,-g2009 ivltests +size_cast_fail3 CE,-g2009 ivltests slongint_test normal,-g2005-sv ivltests sshortint_test normal,-g2005-sv ivltests string_events normal,-g2009 ivltests gold=string_events.gold