You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the following code, ghdl gives a "hides constant" warning, but nvc gives no warning.
$ nvc --version
nvc 1.12.2 (764659a) (Using LLVM 10.0.0)
Copyright (C) 2011-2024 Nick Gasson
This program comes with ABSOLUTELY NO WARRANTY. This is free software, and
you are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.
$ nvc -a const_hides.vhd
$ ghdl -a const_hides.vhd
const_hides.vhd:40:33:warning: declaration of "i" hides constant "i" [-Whide]
loop_part : for i in 0 to i loop
^
"const_hides.vhd" code :
library ieee;
use ieee.std_logic_1164.all;
entityconst_hidesisport (
rst : instd_logic;
clk : instd_logic;
i_part : instd_logic;
o_result : outstd_logic
);
endentityconst_hides;
architecturertlofconst_hidesisconstant C_NB : positive:=4;
signal partA : std_logic_vector(C_NB downto0);
signal partB : std_logic_vector(C_NB downto0);
begin
partA(0) <= i_part;
gen_i : for i in0to C_NB-1generateproc_i : process(clk, rst)
beginif (rst ='1') then
partA(i+1) <='0';
elsifrising_edge(clk) then
partA(i+1) <= partA(i);
--loop_part : for k in 0 to i looploop_part : for i in0to i loop-- reusing the same generate loop index by accident if (partA(i) ='1') then--partB(k+1) <= partB(k);
partB(i+1) <= partB(i);
endif;
endlooploop_part;
endif;
endprocessproc_i;
endgenerategen_i;
o_result <= partB(C_NB);
endarchitecturertl;
The text was updated successfully, but these errors were encountered:
I'm not a huge fan of these kinds of warnings as they tend to generate many false positives which are annoying. However in this case I think a warning would be helpful. I've tried to implement it in such a way that it only warns when the hidden declaration has the same type, and it doesn't warn if a declaration in a subprogram hides something outside the subprogram (e.g. if a parameter and an entity port have the same name). For your example it now reports:
** Warning: declaration of I hides an earlier declaration with the same type
> test.vhd:40
|
27 | gen_i : for i in 0 to C_NB-1 generate
| ^ this declaration is hidden
...
40 | loop_part : for i in 0 to i loop -- reusing the same generate loop index by accident
| ^ by the constant declaration here
With the following code, ghdl gives a "hides constant" warning, but nvc gives no warning.
"const_hides.vhd" code :
The text was updated successfully, but these errors were encountered: