rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Missing validation for pointer to pointer - alias/reference to ref-assignments

Open mhasel opened this issue 1 year ago • 0 comments

When initializing an alias or reference to variable, we only check for the inner type, but not if the actual indirection-level matches the declaration.

FUNCTION main
VAR
    s1: REF_TO LINT;    
    s2 AT s1 : LINT;
    s3 : REFERENCE TO LINT REF= s1;
END_VAR
END_FUNCTION

Here, s2 and s3 should be REF_TO LINT but are declared as LINT. This leads to incorrect IR:

error[E071]: /tmp/.tmptgv8eP/target/demo.st.ll:12:9: error: stored value and pointer type do not match
  store i64** %s1, i64** %s2, align 8

While it seems like LLVM fixes this when compiling to an executable (no segfaults when assigning values, printf prints the expected values), we should still add a validation to check if the pointer-depth matches the declaration.

mhasel avatar Oct 23 '24 12:10 mhasel