-
-
Notifications
You must be signed in to change notification settings - Fork 169
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
enh: Fortran backend : Fix C_ptr #5278
Conversation
A test case would be nice here. |
It will work on every openmp testcase
|
For time being we can consider this as an example program openmp_36
integer :: i
do concurrent ( i =1:5 )
print *, i
end do
end program
|
I see, that's a good start, once you get any of the program present in I moved this PR to draft mode until then. |
Let's add a test which this PR fixes, a minimal, close this and do improvements in next PR. Let's not carry longer PRs. |
This fix now generates dump passes which uses program openmp_40
use omp_lib
integer :: i
do i = 1, 5
print *, i
end do
end program So i can add this test if required and then we will move on to merge it and then I will fix for the |
cb570c2
to
8ebd274
Compare
The error is:
This error comes from GFortran, since the generated code is incorrect. One must insert "import :: c_ptr", or "use iso_c_binding, only: c_ptr" in the interfaces. |
integration_tests/openmp_40.f90
Outdated
program openmp_40 | ||
use omp_lib | ||
integer :: i | ||
do i = 1, 5 | ||
print *, i | ||
end do | ||
end program |
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.
program openmp_40 | |
use omp_lib | |
integer :: i | |
do i = 1, 5 | |
print *, i | |
end do | |
end program | |
program main | |
use iso_c_binding, only: c_ptr!, c_loc | |
implicit none | |
integer, pointer :: x | |
type(c_ptr) :: ptr | |
!ptr = c_loc(x) | |
end program |
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.
Use this instead, you'll need c_loc
as well so slowly keep adding all these. These are minor changes and can be done in small but multiple PRs
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.
For now i guess this PR is ready to go, in next PR i would handle c_loc
case,
And if not then let me know
@@ -246,6 +246,9 @@ class ASRToFortranVisitor : public ASR::BaseVisitor<ASRToFortranVisitor> | |||
import_struct_type.push_back(struct_name); | |||
} | |||
break; | |||
} case ASR::ttypeType::CPtr: { | |||
r = "type(c_ptr)"; |
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.
The fact that if the code has c_ptr
usage it will eventually be doing use iso_c_binding
, so it should work, maybe the example you used is complex.
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.
left few comments to get this PR in shape
59c515b
to
8e634bd
Compare
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.
left few comments
Let's get into the habit of creating a nice set of commits. Or squash it. |
Towards Fortran Backend
Starting with minimal fix