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

writing integer in unformatted form #3995

Open
gxyd opened this issue May 13, 2024 · 1 comment
Open

writing integer in unformatted form #3995

gxyd opened this issue May 13, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@gxyd
Copy link
Contributor

gxyd commented May 13, 2024

Recently, the PR: #3987 (enh: support "unformatted" write) was merged. It was supposed to handle unformatted write (for any string or an integer / real etc.). But writing integer doesn't work:

Fortran MRE

program expr2
    implicit none

    open(1, form="unformatted", file="tmp.txt")
    write(1) 35
    close(1)

end program

Generated LLVM IR

if we change write(1) 35 to write(1) "apple" it works just fine. On doing --show-llvm I get the below IR file:

; ModuleID = 'LFortran'
source_filename = "LFortran"

@0 = private unnamed_addr constant [8 x i8] c"tmp.txt\00", align 1
@1 = private unnamed_addr constant [12 x i8] c"unformatted\00", align 1
@2 = private unnamed_addr constant [2 x i8] c" \00", align 1
@3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
@4 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1

define i32 @main(i32 %0, i8** %1) {
.entry:
  call void @_lpython_call_initial_functions(i32 %0, i8** %1)
  %2 = call i64 @_lfortran_open(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @0, i32 0, i32 0), i8* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @1, i32 0, i32 0))
  %3 = alloca i32, align 4
  call void (i32, i32*, i8*, ...) @_lfortran_file_write(i32 1, i32* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i32 35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @3, i32 0, i32 0))
  call void @_lfortran_close(i32 1)
  ret i32 0
}

declare void @_lpython_call_initial_functions(i32, i8**)

declare i64 @_lfortran_open(i32, i8*, i8*, i8*)

declare void @_lfortran_file_write(i32, i32*, i8*, ...)

declare void @_lfortran_close(i32)
@gxyd gxyd self-assigned this May 13, 2024
@gxyd gxyd added the bug Something isn't working label May 13, 2024
@gxyd
Copy link
Contributor Author

gxyd commented May 16, 2024

@certik , could you please help me with this issue? I'm not able to understand for why this doesn't work. When passed an integer, it doesn't even enter execution of runtime _lfortran_file_write, do you think there is any issue in the signature of the generated LLVM IR? (it seems alright to me).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant