-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
DEV: Added support for & (address of) operator DEV: Added support for * (dereference) operator
I intend to merge it. Please feel free to make further improvements after this PR. |
@@ -311,6 +311,8 @@ expr | |||
| DictLen(expr arg, ttype type, expr? value) | |||
|
|||
| Var(symbol v) | |||
| AddressOf(symbol v, ttype type) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Can you test this in LFortran to make sure all these changes are ok? |
Sure. I will find time to do it on Friday I think. |
Revert commits from #83 which added support for C style pointers
No description provided.