B2031: a record representation clause that places its components illegally
Catalog status: active. Default severity: error. Stable name: record-layout. Family: Types and constraints.
A record representation clause (for R use record ... end record;) says where each component of R is stored: C at P range F .. L puts C in bits F to L counted from the low-order bit of storage unit P. Verada stores the record that way, and 'Size, 'Position, 'First_Bit, 'Last_Bit and Unchecked_Conversion read the same layout, so the clause must describe storage that can hold every value:
- each component is named once, and is a component of the record;
- the position and bits are static, not negative, and the last bit is not before the first less one;
- a scalar component has bits enough for every value of its subtype (two's complement where it has negative values); a composite one starts and ends on a storage unit;
- components do not share bits, unless they belong to different variants;
- no component ends beyond the record's
Size, where it has one.
Example (Vada)
type Status is record
Ready : Boolean;
Count : Integer range 0 .. 300;
end record with Size => 16;
for Status use record
Ready at 0 range 0 .. 0;
Count at 0 range 1 .. 8;
end record;Count needs 9 bits for 300, and is given 8.
What to do (Vada)
Widen the component's bits, or narrow its subtype to the values the bits hold:
for Status use record
Ready at 0 range 0 .. 0;
Count at 0 range 1 .. 9;
end record;Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See types and constraints, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.