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

Allocatable array #22

Open
bingao opened this issue Jan 9, 2019 · 3 comments
Open

Allocatable array #22

bingao opened this issue Jan 9, 2019 · 3 comments

Comments

@bingao
Copy link

bingao commented Jan 9, 2019

Hi,

I just built Fort together with the latest LLVM and Clang. I tried to compile the following simple Fortran code a.f95:

program test
    implicit none
    real(kind=8), allocatable :: ptr
    integer i
    allocate(ptr(10))
    do i = 1, 10
        ptr(i) = i
        write(6,*) ptr(i)
    end do
    deallocate(ptr)
end program test

But I got the following errors:

a.f95:5:5: error: use of undeclared identifier 'allocate'
    allocate(ptr(10))
    ^
a.f95:7:16: error: expression is not assignable
        ptr(i) = i
               ^
a.f95:10:5: error: use of undeclared identifier 'deallocate'
    deallocate(ptr)
    ^

I wonder if Fort supports allocatable array and pointer now or not? If yes, how can I solve the errors? Thank you in advance.

@ppenzin
Copy link
Contributor

ppenzin commented Jan 10, 2019

You need deferred shape to declare an allocatable (Fort would allow you to specify rank exactly, but I don't think that is necessarily correct):

    real(kind=8), allocatable :: ptr(:)

With this Fort still has trouble, it would work only on exact rank. Another thing that is missing is allocate/deallocate statements.

I have filed #23 for the shape and #24 for the allocation statements.

Thank you for the submission, implementing those would be a step in the right direction.

@bingao
Copy link
Author

bingao commented Jan 10, 2019

Thank you @ppenzin and hope to be able to use allocatable array with Fort soon.

One more thing: once this issue is solved, will I be able to use, for instance,

real(kind=8), pointer :: ptr(:)

as well?

@ppenzin
Copy link
Contributor

ppenzin commented Jan 15, 2019

For clarity sake let's dedicate this issue to allocation/deallocation statements only and use #23 for the deferred shape.

ppenzin added a commit to ppenzin/fort that referenced this issue Feb 27, 2019
Implement full path to produce it in Parser and Sema.

For llvm-fortran#22
ppenzin added a commit to ppenzin/fort that referenced this issue Mar 1, 2019
Print deallocate statement in AST dumps. For llvm-fortran#22
ppenzin added a commit to ppenzin/fort that referenced this issue Mar 1, 2019
Emitting allocatable arrays as poitners in IR. Emit call to `libfort_free` for all arguments to DEALLOCATE statement. Add a CodeGen test for dynamic memory managment.

For llvm-fortran#22
ppenzin added a commit to ppenzin/fort that referenced this issue Mar 15, 2019
Add types for allocation statement and array expression. Do basic verification
for the array alocation semantics in ALLOCATE. Minor additition to the test.

Create a more general type for allocation expression (instead of array
allocation), but leave other cases unimplemented for now. Type of the
allocation is the type of the target expression, which may not be correct in
all cases.

Add Sema support for ALLOCATE statements.

For llvm-fortran#22
ppenzin added a commit to ppenzin/fort that referenced this issue Mar 21, 2019
Produce a call to malloc with the right size, store ptr to allocated memory in
the variable.

Bitcast malloc's return value to the right pointer size, store to the target
symbol.

Add all of that to the test.

For llvm-fortran#22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants