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

Automatic reallocation failed #5739

Open
harperjf opened this issue Dec 16, 2024 · 7 comments
Open

Automatic reallocation failed #5739

harperjf opened this issue Dec 16, 2024 · 7 comments

Comments

@harperjf
Copy link

In this program the second assignment to x requires x to be reallocated because its shape has changed.

  integer,allocatable:: x(:)
  x = [1,2,3,4]
  print "(*(1X,I0))",x
  x = [5,6]
  print "(*(1X,I0))",x
end program

Lfortran 0.42.0 output:

Segmentation fault (core dumped)

Four other compilers gave this output, which IMHO is correct:

 1 2 3 4
 5 6
@harperjf
Copy link
Author

As #5707 seemed to require the absence of a program statement I tried adding one to my little program, making it read

program test
  integer,allocatable:: x(:)
  x = [1,2,3,4]
  print "(*(1X,I0))",x
  x = [5,6]
  print "(*(1X,I0))",x
end program

Same output as before.

@kmr-srbh
Copy link
Member

We do not support implicit allocation by default. You can do so using the --realloc-lhs option.

(base) saurabh-kumar@Awadh:~/Projects/System/lfortran$ lfortran test.f90 --realloc-lhs
 1
 2
 3
 4

 5
 6

@harperjf
Copy link
Author

I tried using --realloc-lhs and got @kmr-srbh's output. That proves a bug in lfortran: printing each number on a separate line when the format asked for the whole array x to be printed on one line.

@kmr-srbh
Copy link
Member

@harperjf yes, I think we have some ongoing work to fix printing.

@assem2002
Copy link
Contributor

the printing issue should be fixed by #5039.

@harperjf
Copy link
Author

harperjf commented Dec 17, 2024

Having been misled by assuming that the --std=f23 option would enforce compliance with the Fortran standard I suggest that using that option should automatically use all the other options that make lfortran accept programs that comply with the standard, whether or not they agree with the opinions of lfortran's developers on what is good practice. I think the relevant options are

--realloc-lhs 
--use-loop-variable-after-loop 
--implicit-typing
--implicit-interface

but I may have missed some, or included some that would allow a non-conforming program.
If that is unacceptable to the developers I suggest that those options and --std=f23 be included in a new option, possibly called --STD=f23

@certik
Copy link
Contributor

certik commented Dec 17, 2024

Yes, that's a bug to not include all standard conforming options. Here are the current options: https://github.com/lfortran/lfortran/blob/main/src/bin/lfortran.cpp#L2336, the implicit ones are already enabled, so just the --realloc-lhs must be added, and also --use-loop-variable-after-loop (if it is conforming).

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

No branches or pull requests

4 participants