Unexpected result when the function with BIND(C) attribute has ENTRY statements.
xinliu-hnc opened this issue · comments
Consider following Fortran code:
module m
contains
function f1() bind(C)
complex :: f1
integer :: e1
f1 = (2.0, 0.0)
return
entry e1() bind(C)
e1 = 2
end function
end module
program test
use m
print *, f1(),e1()
end program
the result of flang and gfortran:
$ flang test.f90
$ ./a.out
(2.000000,0.000000) -993867848
$ gfortran test.f90
$ ./a.out
(2.00000000,0.00000000) 2
As shown in the LLVM IR below, __master_entry_rslt355
stores the address of the return value of the entry instead of the expected return value of the entry, which results in an incorrect result.
define void @m__master___f1_(i32 %__master_entry_choice354.arg, i64* %__master_entry_rslt355) {
...
%10 = bitcast i64* %__master_entry_rslt355 to i32**
store i32* %e1_333, i32** %10, align 4
ret void, !dbg !5
...
}
define i32 @m_e1() {
...
%0 = bitcast i32* %e1_333 to i64*
call void @m__master___f1_(i32 1, i64* %0)
%1 = load i32, i32* %e1_333, align 4
ret i32 %1
}
Hi,
I am seeing errors while compiling this program. Are you using any specific flags to compile the program?
flang entry.F90
/tmp/entry-cedfb3.ll:81:6: error: value doesn't match function result type 'double'
ret <{float, float}> %0
^
1 error generated.
If not, let me know the revision of flang that you are using.
Hi,
I am seeing errors while compiling this program. Are you using any specific flags to compile the program?
flang entry.F90 /tmp/entry-cedfb3.ll:81:6: error: value doesn't match function result type 'double' ret <{float, float}> %0 ^ 1 error generated.
If not, let me know the revision of flang that you are using.
I compiled the above program on AArch64 before and didn't use any specific flags. I just tested the latest version(commit: f78c449) of the master
branch on both AArch64 and X86, and there is no error on AArch64 but there is the error you mentioned on X86.
Fixed by PR #1362