Requirement to initialize dynamic variables within property/sequence

Hi All,
While trying a solution using dynamic variables as counter in thread ,
I tried an alternative where the dynamic variable need not be initialized to -1 in each attempt.
For property ‘p_inter_pos_length2’ in edalink

property p_inter_pos_length2(s1, s2, len);
  int v_cnt=0;  // Doubt here . Initialized during declaration itself
  $rose(s1) ##0 ( first_match( (s1 , v_cnt++)[*0:$] ##1 $rose(s2) ) ) |-> (v_cnt == len);
endproperty

I notice that if the dynamic variable ‘v_cnt’ isn’t initialized to 0 the output varies across tools.
Some throw a warning message if I don’t initialize it to 0 while some throw a compilation error saying

** Error: testbench.sv(18): Local variable v_cnt referenced in expression before getting initialized.**
** Error: testbench.sv(18): Local variable v_cnt referenced in expression where it does not flow.
** Error: testbench.sv(18): Local variable v_cnt referenced in expression before getting initialized.

Since default value of ‘int’ type is 0 , shouldn’t the default value be used in consequent expression for +define+ST1 ?

1 Like

In 1800’2017 we added the capability to initialize a property local variable upon its declaration.
I don’t know why we did not allow or clarify its default value set by the type.
Maybe we wanted SVA to be precise about the values used.
Thus, initialization at declaration time or within a sequence match item is required.
en Cohen
Ben@systemverilog.us
Link to the list of papers and books that I wrote, many are now donated.

1 Like

Thanks Ben.

LRM 16.10 mentions

A local variable may be referenced within the sequence or property in which it is declared.
The sequence or property shall assign a value to the local variable prior to the point at which the reference is made. 
The prior assignment may be an initialization assignment or an assignment attached to a subsequence.

LRM has following example

sequence rep_v;
  int x=0; 
   @(posedge clk) (a[->1], x += data)[*4] ##1 b ##1 c && (data_out == x);
 endsequence

If the local variable ‘x’ isn’t initialized in it’s declaration I observe similar compilation error ,
as the local variable is being referenced in ‘x += data’ without initialization