File tree 6 files changed +25
-6
lines changed
6 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 1
- KNOWNBUG
1
+ CORE
2
2
const2.sv
3
3
4
- ^EXIT=10$
4
+ ^file .* line 9: assignment to const$
5
+ ^EXIT=2$
5
6
^SIGNAL=0$
6
7
--
7
8
^warning: ignoring
8
9
--
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)
94
94
IREP_ID_ONE (sva_not )
95
95
IREP_ID_ONE (sva_or )
96
96
IREP_ID_ONE (module_instance )
97
+ IREP_ID_TWO (C_const , #const )
97
98
IREP_ID_TWO (C_offset , #offset )
98
99
IREP_ID_TWO (C_increasing , #increasing )
99
100
IREP_ID_ONE (ports )
Original file line number Diff line number Diff line change @@ -1381,20 +1381,24 @@ data_declaration:
1381
1381
const_opt TOK_VAR lifetime_opt data_type_or_implicit list_of_variable_decl_assignments ' ;'
1382
1382
{ init ($$, ID_decl);
1383
1383
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 );
1385
1386
swapop ($$, $5 ); }
1386
1387
| const_opt lifetime_opt data_type list_of_variable_decl_assignments ' ;'
1387
1388
{ init ($$, ID_decl);
1388
1389
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 );
1390
1392
swapop ($$, $4 ); }
1391
1393
| type_declaration
1392
1394
| package_import_declaration
1393
1395
;
1394
1396
1395
1397
const_opt:
1396
1398
/* Optional */
1399
+ { init ($$, ID_nil); }
1397
1400
| TOK_CONST
1401
+ { init ($$, ID_const); stack_type ($$).add_subtype ().make_nil (); }
1398
1402
;
1399
1403
1400
1404
package_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)
468
468
tmp.subtype () = elaborate_type (tmp.subtype ());
469
469
return std::move (tmp);
470
470
}
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
+ }
471
478
else
472
479
{
473
480
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(
728
728
{
729
729
const symbolt &symbol=ns.lookup (to_symbol_expr (lhs));
730
730
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
+
731
738
switch (vassign)
732
739
{
733
740
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
66
66
67
67
void propagate_type (exprt &expr, const typet &type);
68
68
69
- typet elaborate_type (const typet &);
69
+ [[nodiscard]] typet elaborate_type (const typet &);
70
70
typet elaborate_package_scope_typedef (const verilog_package_scope_typet &);
71
71
typet convert_enum (const class verilog_enum_typet &);
72
72
array_typet convert_unpacked_array_type (const type_with_subtypet &);
You can’t perform that action at this time.
0 commit comments