Skip to content

IndexError in RangelistModel.intersect() when using ignore_bins/illegal_bins that fully overlap a bin #269

@BanuAdrian

Description

@BanuAdrian

Description

Defining ignore_bins/illegal_bins that fully overlap one or more coverpoint bins causes an IndexError during covergroup construction. The crash occurs in RangelistModel.intersect() in rangelist_model.py.

Minimal Reproducible Example

@vsc.randobj
class Item:
    def __init__(self):
        self.x = vsc.rand_uint8_t()

@vsc.covergroup
class Cg:
    def __init__(self):
        self.with_sample(dict(it=Item()))
        self.options.name = "cg"

        self.cp = vsc.coverpoint(
            self.it.x,
            bins={
                "min": vsc.bin(0),
                "mid": vsc.bin([1, 254]),
                "max": vsc.bin(255)
            },
            ignore_bins={
                "ignore_0": vsc.bin(0),
                "ignore_1": vsc.bin(1)
            }
        )

cg = Cg()

Expected behavior

Covergroup constructs successfully. Bins fully covered by ignore_bins are removed, partially overlapping bins are trimmed.

Actual output

...coverage.py:216, in covergroup.<locals>.build_model(self)
...
---> 81             self.range_l[rng_i],
     82             r)
     83     rng_i += 1

IndexError: list index out of range

The above exception is thrown.

Root Cause

In RangelistModel.intersect(), when _intersect() pops a range (because it is fully included in an ignore bin), rng_i is decremented to -1. The outer for loop over other.range_l then continues iterating and accesses self.range_l[rng_i] - which is self.range_l[-1], i.e. the last element - causing incorrect behavior or an IndexError on the next iteration of the while loop when the list is empty.

Additional Notes

The same issue occurs with illegal_bins, as they use the same intersect() code path during covergroup construction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions