Open
Description
Is your feature request related to a problem? Please describe.
Output assignment with direct access in function calls, e.g. fun(foo => bar.3)
, currently do not modify the right side (i.e. bar.3
) with the outputs result. Specifically the way we generate IR for output assignments in function calls works by
- Loading
bar
- Generating the expression for
bar.3
using some shifting magic and boolean operators - Storing the result of the generated expression into a temporary variable
- Calling the function, passing the temporary variable as a pointer
However, a 5th step is missing in which we store the temporary variable back into bar
. See
define i32 @main() section "fn-main:i32" {
entry:
; [...]
; Code for `fun(foo => bar.4)`
%load_bar1 = load i32, i32* %bar, align 4
%shift = ashr i32 %load_bar1, 4
%1 = trunc i32 %shift to i8
%2 = and i8 %1, 1
%load_bar2 = load i32, i32* %bar, align 4
%shift3 = ashr i32 %load_bar2, 4
%3 = trunc i32 %shift3 to i8
%4 = and i8 %3, 1
%5 = alloca i8, align 1
store i8 %4, i8* %5, align 1
call void @fun(i8* %5)
; Missing store call for `bar` variable
; [...]
}
FUNCTION fun
VAR_OUTPUT
foo : BOOL;
END_VAR
foo := TRUE;
END_FUNCTION
FUNCTION_BLOCK fb
VAR_OUTPUT
foo : BOOL;
END_VAR
foo := TRUE;
END_FUNCTION_BLOCK
FUNCTION main : DINT
VAR
bar : DINT;
myFb : fb;
END_VAR
bar := 0;
printf('%d$N', bar);
fun(foo => bar.4); // ..._0001_0000
printf('%d$N', bar);
bar := 0;
printf('%d$N', bar);
myFb(foo => bar.4); // ..._0001_0000
printf('%d$N', bar);
END_FUNCTION