P4087

Code

P4087

Message

Shift or rotate input is a BOOL rather than a multi-bit bit string

This error occurs when the value that SHL, SHR, ROL or ROR shifts is a BOOL.

A shift or rotation moves the bits of a bit string of 8 or more bits: BYTE, WORD, DWORD or LWORD. A BOOL holds one bit, so shifting it either keeps it or clears it depending on how wide the implementation computes, and rotating it leaves it as it is. The value is reported whatever gives it the type BOOL: a BOOL variable, a comparison, a bit access such as flags.3 or a BOOL literal, passed by position or as IN :=.

Example

The following code will generate error P4087:

PROGRAM main
VAR
    ready : BOOL;
END_VAR
    ready := SHL(ready, 1);
END_PROGRAM

The variable ready is a BOOL, but SHL shifts a bit string of 8 or more bits.

To fix this error, shift the bit string the flag belongs to, and read the bit where the shift moved it:

PROGRAM main
VAR
    flags : BYTE;
    ready : BOOL;
END_VAR
    flags := SHL(flags, 1);  (* bit 0 moves to bit 1 *)
    ready := flags.1;
END_PROGRAM

See SHL for the shift functions.

Think IronPLC is wrong about this?

If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.