[sv-bc] RE: Enum assignment via packed struct

From: Steven Sharp <sharp@cadence.com>
Date: Wed Jun 20 2012 - 13:08:27 PDT

Note that unions already provide a loophole for assigning an arbitrary value to an enum. You can create a union between an enum and a bit vector and assign an arbitrary value to the bit vector, then read it back from the enum.

A packed struct is effectively a union between the struct and the bit vector that is referenced when you refer to the entire struct, so this is effectively the same situation.

From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Surya Pratik Saha
Sent: Wednesday, June 20, 2012 8:50 AM
To: sv-bc@eda.org
Subject: [sv-bc] Enum assignment via packed struct

Hi,
As per LRM, an enum variable can only be assigned to another enum variable of same type or enum member. But if it is part of a packed struct, then the restriction can be overridden. Please see the following e.g.:

module top;
    typedef enum bit [1:0] {X, Y, Z} et;
    typedef struct packed {
        et e;
    } st;
    et e;
    st s;
    initial begin
        s = 4; // Passing
        e = 4; // Failing
    end
endmodule

Does LRM say anything about that? Should it not be disallowed by some way?

Regards
Surya

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
Received on Wed Jun 20 13:08:31 2012

This archive was generated by hypermail 2.1.8 : Wed Jun 20 2012 - 13:08:36 PDT