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

Added support for pointer in LC by porting integration_tests/associate_02.f90 from LFortran #83

Merged
merged 7 commits into from
Feb 2, 2024

Conversation

czgdp1807
Copy link
Collaborator

No description provided.

@czgdp1807 czgdp1807 marked this pull request as ready for review February 2, 2024 16:51
@czgdp1807
Copy link
Collaborator Author

I intend to merge it. Please feel free to make further improvements after this PR.

@czgdp1807 czgdp1807 enabled auto-merge February 2, 2024 16:58
@czgdp1807 czgdp1807 merged commit bed4733 into lcompilers:main Feb 2, 2024
2 checks passed
@czgdp1807 czgdp1807 deleted the ptr_01 branch February 2, 2024 17:06
@@ -311,6 +311,8 @@ expr
| DictLen(expr arg, ttype type, expr? value)

| Var(symbol v)
| AddressOf(symbol v, ttype type)
Copy link
Contributor

@certik certik Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to be careful here.

This seems to be the same as CLoc (or GetPointer). These two nodes should be merged then.

Also we want to be able to add an optional debug time checking for dangling pointers. So we have to be careful how these nodes are designed, so that it is possible to add checking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the same as CLoc (or GetPointer). These two nodes should be merged then.

AddressOf can be called on anything including array items, any type of variable, functions. However, c_loc can only be called on variables that too with target or pointer attribute. Also, AddressOf as a separate node will be very helpful when implementing pointer arithmetic features. Merging nodes can be option when we implement pointer arithmetic features, until then I would suggest not to merge nodes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not support pointer arithmetic, unless we absolutely have to. That's a feature that will be hard to check in Debug mode. We have to be extremely careful with introducing new features to ASR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here: lfortran/lfortran#3354.

I am afraid we'll have to revert this change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will revert this PR and turn off the test for llvm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #88

@@ -311,6 +311,8 @@ expr
| DictLen(expr arg, ttype type, expr? value)

| Var(symbol v)
| AddressOf(symbol v, ttype type)
| DereferencePointer(symbol v, ttype type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we introduce a node like this one, it should be consistently used everywhere. I think it might simplify the LLVM backend with all the loads.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a compile time value is needed. Furthermore, isn't this the same as Var? Var currently automatically dereferences.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a compile time value is needed.

I don't think so. Pointer is an address, available at runtime. So we can only know what's in the address when we run the code. Consider the following example,

#include <iostream>

int main() {

    int p = 10;
    const int* ptr = &p;

    p = 20;

    std::cout << *ptr << std::endl;

    return 0;
}
(lc) 14:43:21:~/lc_project/lc % ./a.out             
20

@certik
Copy link
Contributor

certik commented Feb 2, 2024

Can you test this in LFortran to make sure all these changes are ok?

@czgdp1807
Copy link
Collaborator Author

Sure. I will find time to do it on Friday I think.

certik added a commit that referenced this pull request Feb 8, 2024
Revert commits from #83 which added support for C style pointers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants