Skip to content

fix: handle indices correctly in cshift intrinsic #6372

Merged
certik merged 2 commits into
lfortran:mainfrom
HarshitaKalani:cshift_02
Feb 20, 2025
Merged

fix: handle indices correctly in cshift intrinsic #6372
certik merged 2 commits into
lfortran:mainfrom
HarshitaKalani:cshift_02

Conversation

@HarshitaKalani

@HarshitaKalani HarshitaKalani commented Feb 20, 2025

Copy link
Copy Markdown
Contributor

towards: #6370
Also addresses: #6352 (comment)

@HarshitaKalani HarshitaKalani marked this pull request as ready for review February 20, 2025 15:44
@HarshitaKalani

HarshitaKalani commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

With this, the error is now different:

$ cat lf.sh
lfortran a.f90 --dump-all-passes-fortran --apply-fortran-mangling
gfortran -fcheck=all -g -c pass_fortran_31_insert_deallocate.f90
gfortran pass_fortran_31_insert_deallocate.o -o pass_fortran_31_insert_deallocate
./pass_fortran_31_insert_deallocate
$ sh lf.sh 
At line 10 of file pass_fortran_31_insert_deallocate.f90
Fortran runtime error: Attempt to DEALLOCATE unallocated 'r_g'

Error termination. Backtrace:
#0  0x7a2747823960 in ???
#1  0x7a27478244d9 in ???
#2  0x7a2747824ad6 in ???
#3  0x5953aa69777e in pot3d
        at /home/harshita/Desktop/lfortran/pass_fortran_31_insert_deallocate.f90:10
#4  0x5953aa697a2a in main
        at /home/harshita/Desktop/lfortran/pass_fortran_31_insert_deallocate.f90:10

which is because there are two consecutive deallocate statements after the insert_deallocate pass

! Fortran code after applying the pass: insert_deallocate
program pot3d
implicit none
integer(4), parameter :: dp = 8
integer(4), save :: n = 3
real(8), dimension(:), allocatable :: r_g
allocate(r_g(n))
call genmesh(n, r_g)

! here
deallocate(r_g)
deallocate(r_g) ! Implicit deallocate

contains

...

@gxyd gxyd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks good to me. I'm still thinking if there is a way to add a test case here.

Also, I checked it locally on my machine and this change allows us to remove the workaround from POT3D

Comment thread src/libasr/pass/intrinsic_array_function_registry.h
Comment thread src/libasr/codegen/asr_to_llvm.cpp
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.

3 participants