B3022: function reads an object something else may change
Catalog status: active. Default severity: error. Stable name: volatile-function-input. Family: Flow and effects.
An object with Async_Writers may be changed by something outside the program (a device, or another processor) between any two reads, and reading an object with Effective_Reads is itself an effect (it may consume a value from a hardware queue). Volatile alone gives both. An ordinary function must give the same result for the same inputs, so it may not read such an object, directly or through the subprograms it calls. Read the object in a procedure instead, and give the value to the function.
Verada proves each read of an Async_Writers object as a new value, and the generated code reads and writes effectively volatile objects with volatile loads and stores, every time and in order.
Example (Vada)
package Sensors is
Reading : Integer := 0 with Volatile, Async_Writers;
function Current return Integer is (Reading); -- B3022
end Sensors;Example (Varc)
package Sensors {
pub var Reading: Integer = 0 @Volatile @Async_Writers;
pub fn Current() -> Integer = Reading; // B3022
}
Fix
procedure Sample (Value : out Integer) is
begin
Value := Reading;
end Sample;Alternatively, a suitable Volatile_Function declaration permits the supported special input behavior and imposes whole-value call restrictions. This is not permission for arbitrary function side effects; see volatile and asynchronous state.
Regression source and further reading
Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.
See flow and effects, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.