Description
GHDL is able to process a string definition which is outside the predefined range of string (natural range <>) which does not include 0
Expected behaviour
In the case of the EDA Playground example below, it should fail at run time when a dynamic string with range that includes 0 is attempted.
How to reproduce?
https://www.edaplayground.com/x/5smV
NOTE:
:file:and:image:identifiers are specific to issue-runner. We suggest to use these, since it allows continuous integration workflows to automatically test the MWE. Usingghdl/ghdl:*docker images to run the MWEs ensures that the latest available GHDL is used.
NOTE: Large files can be uploaded one-by-one or in a tarball/zipfile.
Context
Please, provide the following information:
versiontarball_urlcommit SHAIf a GHDL Bug occurred block is shown in the log, please paste it here:
******************** GHDL Bug occurred ***************************
Please report this bug on https://github.com/ghdl/ghdl/issues
...
******************************************************************
Additional context
Add any other context about the problem here. If applicable, add screenshots to help explain your problem.
FTR:
entity ent is
end;
architecture arch of ent is
signal strt: string(0 to 4);
signal strd: string(4 downto 0);
begin
process
variable strvt: string(0 to 4);
variable strvd: string(4 downto 0);
begin
report "HELLO" severity note;
wait;
end process;
end;
# ghdl -a test.vhd
test.vhd:5:23:warning: static range violates bounds [-Wruntime-error]
test.vhd:5:23:warning: static range violates bounds [-Wruntime-error]
test.vhd:6:23:warning: static range violates bounds [-Wruntime-error]
test.vhd:6:23:warning: static range violates bounds [-Wruntime-error]
test.vhd:9:26:warning: static range violates bounds [-Wruntime-error]
test.vhd:9:26:warning: static range violates bounds [-Wruntime-error]
test.vhd:10:26:warning: static range violates bounds [-Wruntime-error]
test.vhd:10:26:warning: static range violates bounds [-Wruntime-error]
entity ent is
end;
architecture arch of ent is
begin
process
function bv2str(bv: bit_vector) return string is
variable st_out : string(bv'high downto bv'low);
--variable st_out : string(bv'range); -- produces the same result
begin
for i in bv'range loop
if(bv(i) = '0') then
st_out(i) := '0';
else
st_out(i) := '1';
end if;
end loop;
return st_out;
end function;
variable bitv : bit_vector(4 downto 0);
begin
report bv2str(bitv);
wait;
end process;
end;
# ./ent
test.vhd:22:1:@0ms:(report note): 00000
entity ent is
end;
architecture arch of ent is
begin
process
function bv2str(bv: bit_vector) return string is
variable st_out : string(4 downto 0);
begin
for i in bv'range loop
if(bv(i) = '0') then
st_out(i) := '0';
else
st_out(i) := '1';
end if;
end loop;
return st_out;
end function;
variable bitv : bit_vector(4 downto 0);
begin
report "HELLO" severity note;
report bv2str(bitv);
wait;
end process;
end;
# ghdl -a test.vhd
test.vhd:8:30:warning: static range violates bounds [-Wruntime-error]
test.vhd:8:30:warning: static range violates bounds [-Wruntime-error]
This is the expected behavior.
The string type is defines as:
type STRING is array (POSITIVE range <>) of CHARACTER;
The zero index violates the positive range constraint.
@alemuller that is the point. When variable bitv : bit_vector(4 downto 0); is passed to bv2str(bitv), variable st_out : string(bv'high downto bv'low); is variable st_out : string(4 downto 0);, which we think it should produce a range violation error. However, that's not the case.
The first and third example of my previous comment show that in some contexts GHDL produces a warning/error, as expected. However, in the second example (which is @sckoarn's), no warning/error is produced, and we would expect it.
I see.
MWE:
entity ent is
generic (g : integer := 4);
end;
architecture arch of ent is
signal str : string (g downto 0) := (others=>'a');
begin
process
begin
report str;
wait;
end process;
end;
I'm note sure what the spec says about using globally static expression to define range boundary.
Most helpful comment
I see.
MWE:
I'm note sure what the spec says about using globally static expression to define range boundary.