File tree Expand file tree Collapse file tree 6 files changed +25
-6
lines changed Expand file tree Collapse file tree 6 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1- KNOWNBUG
1+ CORE
22const2.sv
33
4- ^EXIT=10$
4+ ^file .* line 9: assignment to const$
5+ ^EXIT=2$
56^SIGNAL=0$
67--
78^warning: ignoring
89--
9- Should be rejected owing to assignment to const variable.
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ IREP_ID_ONE(sva_implies)
9494IREP_ID_ONE (sva_not )
9595IREP_ID_ONE (sva_or )
9696IREP_ID_ONE (module_instance )
97+ IREP_ID_TWO (C_const , #const )
9798IREP_ID_TWO (C_offset , #offset )
9899IREP_ID_TWO (C_increasing , #increasing )
99100IREP_ID_ONE (ports )
Original file line number Diff line number Diff line change @@ -1381,20 +1381,24 @@ data_declaration:
13811381 const_opt TOK_VAR lifetime_opt data_type_or_implicit list_of_variable_decl_assignments ' ;'
13821382 { init ($$, ID_decl);
13831383 stack_expr ($$).set (ID_class, ID_var);
1384- addswap ($$, ID_type, $4 );
1384+ add_as_subtype (stack_type ($1 ), stack_type ($4 ));
1385+ addswap ($$, ID_type, $1 );
13851386 swapop ($$, $5 ); }
13861387 | const_opt lifetime_opt data_type list_of_variable_decl_assignments ' ;'
13871388 { init ($$, ID_decl);
13881389 stack_expr ($$).set (ID_class, ID_reg);
1389- addswap ($$, ID_type, $3 );
1390+ add_as_subtype (stack_type ($1 ), stack_type ($3 ));
1391+ addswap ($$, ID_type, $1 );
13901392 swapop ($$, $4 ); }
13911393 | type_declaration
13921394 | package_import_declaration
13931395 ;
13941396
13951397const_opt:
13961398 /* Optional */
1399+ { init ($$, ID_nil); }
13971400 | TOK_CONST
1401+ { init ($$, ID_const); stack_type ($$).add_subtype ().make_nil (); }
13981402 ;
13991403
14001404package_import_declaration_brace:
Original file line number Diff line number Diff line change @@ -468,6 +468,13 @@ typet verilog_typecheck_exprt::elaborate_type(const typet &src)
468468 tmp.subtype () = elaborate_type (tmp.subtype ());
469469 return std::move (tmp);
470470 }
471+ else if (src.id () == ID_const)
472+ {
473+ auto tmp = to_type_with_subtype (src).subtype ();
474+ tmp = elaborate_type (tmp);
475+ tmp.set (ID_C_const, true );
476+ return tmp;
477+ }
471478 else
472479 {
473480 throw errort ().with_location (source_location)
Original file line number Diff line number Diff line change @@ -728,6 +728,13 @@ void verilog_typecheckt::check_lhs(
728728 {
729729 const symbolt &symbol=ns.lookup (to_symbol_expr (lhs));
730730
731+ // check for 'const'
732+ if (symbol.type .get_bool (ID_C_const))
733+ {
734+ throw errort ().with_location (lhs.source_location ())
735+ << " assignment to const" ;
736+ }
737+
731738 switch (vassign)
732739 {
733740 case A_CONTINUOUS:
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ class verilog_typecheck_exprt:public verilog_typecheck_baset
6666
6767 void propagate_type (exprt &expr, const typet &type);
6868
69- typet elaborate_type (const typet &);
69+ [[nodiscard]] typet elaborate_type (const typet &);
7070 typet elaborate_package_scope_typedef (const verilog_package_scope_typet &);
7171 typet convert_enum (const class verilog_enum_typet &);
7272 array_typet convert_unpacked_array_type (const type_with_subtypet &);
You can’t perform that action at this time.
0 commit comments