I have an enum
typedef enum { YES = 0u, NO = 1u } AnswerType;
Which is used as a bit field element in a struct
typedef struct { uint8_t messageField; uint8_t padding : 7; AnswerType answer : 1; } MessageType;
When attempting to access this field, Polyspace is confusing the enum to be a signed 1 bit bitfield with a range of [-1..0], when in fact it's unsigned [0..1]. This of course causes a chain of errors due to incorrect range values.
Forcing the "auto-unsigned-first" option in Polyspace for "-enum-type-definition" will treat this enum as a u8, however it's actually compiled as u32, thus causing problems in other areas of the analysis (where we rely on it being a u32).
Is there a way to override the range values for enums and struct elements?
Best Answer