Skip to content

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

Open
@mhasel

Description

@mhasel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions