From 780165a75ed4eeb1657d9dde79576ff9883ec82b Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 25 Jul 2022 08:05:23 +0200 Subject: testsuite/gna: add a test for #2138 --- testsuite/gna/issue2138/testsuite.sh | 11 ++++++++ .../issue2138/variable_assignment_with_when.vhdl | 29 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 testsuite/gna/issue2138/testsuite.sh create mode 100644 testsuite/gna/issue2138/variable_assignment_with_when.vhdl (limited to 'testsuite') diff --git a/testsuite/gna/issue2138/testsuite.sh b/testsuite/gna/issue2138/testsuite.sh new file mode 100755 index 000000000..0d1ff08be --- /dev/null +++ b/testsuite/gna/issue2138/testsuite.sh @@ -0,0 +1,11 @@ +#! /bin/sh + +. ../../testenv.sh + +export GHDL_STD_FLAGS=--std=08 +analyze variable_assignment_with_when.vhdl +elab_simulate variable_assignment_with_when + +clean + +echo "Test successful" diff --git a/testsuite/gna/issue2138/variable_assignment_with_when.vhdl b/testsuite/gna/issue2138/variable_assignment_with_when.vhdl new file mode 100644 index 000000000..06349788a --- /dev/null +++ b/testsuite/gna/issue2138/variable_assignment_with_when.vhdl @@ -0,0 +1,29 @@ +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity variable_assignment_with_when is + port( + x : in std_logic_vector(7 downto 0); + y : out std_logic_vector(3 downto 0) + ); +end entity; + +architecture arch of variable_assignment_with_when is +begin + + process (all) is + variable sum : natural; + begin + sum := 0; + for i in x'range loop + sum := sum + 1 when x(i) = '1'; + -- this works: + -- if x(i) then + -- sum := sum + 1; + -- end if; + end loop; + y <= std_logic_vector(to_unsigned(sum, y'length)); + end process; + +end architecture; -- cgit v1.2.3