Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning new values to arguments #9

Open
Sh3b0 opened this issue Mar 6, 2022 · 0 comments
Open

Assigning new values to arguments #9

Sh3b0 opened this issue Mar 6, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@Sh3b0
Copy link
Owner

Sh3b0 commented Mar 6, 2022

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)
@Sh3b0 Sh3b0 added the bug Something isn't working label Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant