PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
181 stars 47 forks source link

llvm-verify errs on bool-arrays #1178

Open mhasel opened 1 month ago

mhasel commented 1 month ago

Describe the bug When initializing an array of booleans with literals, llvm will fail to verify the generated IR with the following error:

error[E071]: /tmp/.tmpZqD0kW/target/demo.st.ll:4:56: error: constant expression type mismatch: got type 'i1' but expected 'i8'
@__main.arr__init = unnamed_addr constant [2 x i8] [i8 false, i8 true]
                                                       ^

regressed commit: 28e89cc

To Reproduce demo.st:

FUNCTION main : DINT 
VAR
    arr: ARRAY[0..1] OF BOOL := [FALSE, TRUE];
END_VAR
END_FUNCTION

Compile to IR with plc demo.st --ir

Additional context When assigning boolean references to the array or initializing boolean references, the IR is okay.

FUNCTION main : DINT 
VAR
    a: BOOL := TRUE;
    arr: ARRAY[0..1] OF BOOL;
END_VAR
    arr[0] := a;
END_FUNCTION

Related issues/commits

1041

444