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

enh: Fortran backend : Fix C_ptr #5278

Merged
merged 5 commits into from
Nov 11, 2024
Merged

Conversation

adit4443ya
Copy link
Contributor

Towards Fortran Backend

Starting with minimal fix

@gxyd
Copy link
Contributor

gxyd commented Nov 7, 2024

A test case would be nice here.

@gxyd gxyd marked this pull request as draft November 7, 2024 08:55
@adit4443ya
Copy link
Contributor Author

It will work on every openmp testcase
If there is some new testcase needed then i will add it

A test case would be nice here.

@adit4443ya
Copy link
Contributor Author

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

A test case would be nice here.

@gxyd
Copy link
Contributor

gxyd commented Nov 7, 2024

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 integration_tests/CMakeLists.txt (pertaining to openmp), you can probably just add a label fortran to it (those can act as a good test case for this).

I moved this PR to draft mode until then.

@Pranavchiku
Copy link
Member

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.

@adit4443ya
Copy link
Contributor Author

This fix now generates dump passes which uses omp_lib

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 DoConcurrentLoop in next PR

@adit4443ya adit4443ya marked this pull request as ready for review November 7, 2024 18:45
@adit4443ya adit4443ya marked this pull request as draft November 8, 2024 10:31
@certik
Copy link
Contributor

certik commented Nov 8, 2024

The error is:

CMakeFiles/openmp_40.dir/openmp_40.f90.o.tmp.f90:95:20:

   95 |         type(c_ptr), value :: data
      |                    1
Error: Derived type ‘c_ptr’ at (1) is being used before it is defined

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.

Comment on lines 1 to 7
program openmp_40
use omp_lib
integer :: i
do i = 1, 5
print *, i
end do
end program
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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

Copy link
Contributor Author

@adit4443ya adit4443ya Nov 11, 2024

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)";
Copy link
Member

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.

Copy link
Member

@Pranavchiku Pranavchiku left a 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

Copy link
Member

@Pranavchiku Pranavchiku left a comment

Choose a reason for hiding this comment

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

left few comments

@Pranavchiku Pranavchiku marked this pull request as ready for review November 11, 2024 11:49
@Pranavchiku Pranavchiku merged commit e872a85 into lfortran:main Nov 11, 2024
27 checks passed
@certik
Copy link
Contributor

certik commented Nov 11, 2024

Let's get into the habit of creating a nice set of commits. Or squash it.

@adit4443ya adit4443ya changed the title enh: Fortran backend to support openmp dump enh: Fortran backend : Fix C_ptr Nov 12, 2024
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.

4 participants