From 29289cbb4fb0bf5c8424519bf97220205f892151 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Sat, 5 Feb 2022 17:05:38 +0100 Subject: testsuite/synth: add a test for #1962 --- testsuite/synth/issue1962/bug.vhdl | 48 ++++++++++++++++++++++++++++++++++ testsuite/synth/issue1962/bug2.vhdl | 44 +++++++++++++++++++++++++++++++ testsuite/synth/issue1962/testsuite.sh | 9 +++++++ 3 files changed, 101 insertions(+) create mode 100644 testsuite/synth/issue1962/bug.vhdl create mode 100644 testsuite/synth/issue1962/bug2.vhdl create mode 100755 testsuite/synth/issue1962/testsuite.sh diff --git a/testsuite/synth/issue1962/bug.vhdl b/testsuite/synth/issue1962/bug.vhdl new file mode 100644 index 000000000..739d9c0ee --- /dev/null +++ b/testsuite/synth/issue1962/bug.vhdl @@ -0,0 +1,48 @@ +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.numeric_std.all; + +entity bug is + port ( + clk : in std_ulogic + ); +end bug; + +architecture struct of bug is + + type data_t is record + value : natural; + end record; + + type offset_array_t is array(natural range<>) of natural; + type data_array_t is array(natural range<>) of data_t; + + type collection_t is record + offset : offset_array_t; + data : data_array_t; + end record; + + -- This results in an error + function append(prefix : collection_t; data : data_array_t) return collection_t is + begin + return (offset => prefix.offset & prefix.data'length, + data => prefix.data & data); + end function; + + -- This works as a workaround + function append2(prefix : collection_t; data : data_array_t) return collection_t is + variable ret : collection_t(offset(0 to prefix.offset'length), data(0 to prefix.data'length+data'length-1)); + begin + ret := (offset => prefix.offset & prefix.data'length, + data => prefix.data & data); + return ret; + end function; + + --intentional null ranges for the initial value + constant initial_collection : collection_t(offset(0 to -1), data(0 to -1)) := (offset => (others => 0), data => (others => (value => 0))); + constant new_data : data_array_t(0 to 2) := (others => (value => 0)); + + constant final_collection : collection_t := append(initial_collection, new_data); +begin + +end architecture; diff --git a/testsuite/synth/issue1962/bug2.vhdl b/testsuite/synth/issue1962/bug2.vhdl new file mode 100644 index 000000000..b597fb89b --- /dev/null +++ b/testsuite/synth/issue1962/bug2.vhdl @@ -0,0 +1,44 @@ +entity bug is + port ( + clk : in bit + ); +end bug; + +architecture struct of bug is + + type data_t is record + value : natural; + end record; + + type offset_array_t is array(natural range<>) of natural; + type data_array_t is array(natural range<>) of data_t; + + type collection_t is record + offset : offset_array_t; + data : data_array_t; + end record; + + -- This results in an error + function append(prefix : collection_t; data : data_array_t) return collection_t is + begin + return (offset => prefix.offset & prefix.data'length, + data => prefix.data & data); + end function; + + -- This works as a workaround + function append2(prefix : collection_t; data : data_array_t) return collection_t is + variable ret : collection_t(offset(0 to prefix.offset'length), data(0 to prefix.data'length+data'length-1)); + begin + ret := (offset => prefix.offset & prefix.data'length, + data => prefix.data & data); + return ret; + end function; + + --intentional null ranges for the initial value + constant initial_collection : collection_t(offset(0 to -1), data(0 to -1)) := (offset => (others => 0), data => (others => (value => 0))); + constant new_data : data_array_t(0 to 2) := (others => (value => 0)); + + constant final_collection : collection_t := append(initial_collection, new_data); +begin + +end architecture; diff --git a/testsuite/synth/issue1962/testsuite.sh b/testsuite/synth/issue1962/testsuite.sh new file mode 100755 index 000000000..a27251178 --- /dev/null +++ b/testsuite/synth/issue1962/testsuite.sh @@ -0,0 +1,9 @@ +#! /bin/sh + +. ../../testenv.sh + +GHDL_STD_FLAGS=--std=08 +synth_only bug +synth_only bug2 + +echo "Test successful" -- cgit v1.2.3