Skip to content

Assigning new values to arguments #9

@Sh3b0

Description

@Sh3b0

Code to reproduce

routine modify(x : integer) is
    x := 2;
    println x;
    return;
end

routine main() is
    modify(5);
    return;
end

Expected behavior

Prints 2

Actual behavior

[AST]:
<Program>
|   <RoutineDeclaration>
|   |   <Body>
|   |   |   <AssignmentStatement>
|   |   |   |   <Identifier>
|   |   |   |   </Identifier>
cplus: /usr/lib/llvm-10/include/llvm/IR/Type.h:382: llvm::Type* llvm::Type::getPointerElementType() const: Assertion `getTypeID() == PointerTyID' failed.
./run.sh: line 5: 73279 Aborted                 (core dumped) ./build/cplus -d examples/sample.cp

Notes

  • This happens because the assignment statement tries to access the location of x by visiting the identifier node, which assigns to tmp_v rather than tmp_p in cast of argument (from args_table)
  • One way to solve this would be to make args_table return pointers instead of values (like ptrs_table), but this would require modifications in RoutineDeclarations.
  • We may actually use only one table (ptrs_table) and remove (args_table)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions