Menu

#953 Variable out of bound multi-dim array accesses are broken

devel
open
nobody
None
7
2014-03-20
2014-03-19
Cary R.
No

Since Icarus currently implements arrays with multiple dimensions as a single dimensional array that just has a complicated index calculation the index can wrap around for variable out of bound cases. For constant values the compiler appears to do the correct thing (alter the index to be 'bx). In a procedural context if any part of the index is variable either a reference or an assignment will not work correctly. I believe the VPI interface has the same issue. I have not checked arrays in a continuous assignment context, but my assumption is they will have the same problem

I believe the original array bounds information needs to be passed to the run time so that the index calculation can be checked. For procedural code it may make sense to create a new operator (stack based?) that takes the array (to get the index ranges) and the index values and then checks that the index values are in range and returns the canonical index of the underlying array or 'bx if a value is out of range. For a continuous assignment it may make sense to have an index check operator that takes an array, an index value and an index number that returns the index value if it is in range for the numbered array index (e.g. check_index array, value, number would check if value was in range for array index number). It would return 'bx if the value was out of range.

We can discuss this more here or on the development mailing list if needed.

The attached code checks a simple two dimensional array for various procedural references and assignments. It should be fairly simple to add similar code to check arrays in a continuous assignment.

Since this issue cannot be worked around and is producing invalid results without a warning I am setting this as a priority 7 bug. Currently I do not have time to work on this so it is open if other want to look at what is involved in fixing this.

1 Attachments

Discussion

  • Cary R.

    Cary R. - 2014-03-20
    • summary: Variable out of bound multi-dim array accessesare broken --> Variable out of bound multi-dim array accesses are broken
     
  • Cary R.

    Cary R. - 2014-03-20

    Note, for fixed arrays you could just pass the array size information to the checking routine, but for dynamic arrays this is not possible since the compiler/code generator does not have any size information for the dynamic part. For this reason it is probably easier/best to pass a handle to the array and have the checking routine extract the relevant information for all array types in a uniform manner.

     

Log in to post a comment.