Closed ohno-fj closed 10 months ago
@llvm/issue-subscribers-flang-frontend
Author: None (ohno-fj)
@llvm/issue-subscribers-bug
Author: None (ohno-fj)
The problem here is not the intrinsic, it's the nested call. Here is a smaller reproducer:
program main
call bar(foo)
end program main
subroutine foo(x)
x=x+1
end subroutine foo
subroutine bar(func)
call func(1.0)
end subroutine bar
I'll take a look at this.
The problem here is not the intrinsic, it's the nested call. Here is a smaller reproducer:
In your reproducer, call bar(foo)
passes the address of an implicit local object variable foo
on the stack, hence the segfault. You should add external :: foo
, and then it does not segfault.
Oh, correct! I'll keep digging the original testcase then. Thanks!
The problem here is not the intrinsic, it's the nested call. Here is a smaller reproducer:
In your reproducer,
call bar(foo)
passes the address of an implicit local object variablefoo
on the stack, hence the segfault. You should addexternal :: foo
, and then it does not segfault.
Btw, shouldn't Flang be emitting an error in this case? In addition to your observation, there is also a type mismatch, no?
The problem here is not the intrinsic, it's the nested call. Here is a smaller reproducer:
In your reproducer,
call bar(foo)
passes the address of an implicit local object variablefoo
on the stack, hence the segfault. You should addexternal :: foo
, and then it does not segfault.Btw, shouldn't Flang be emitting an error in this case? In addition to your observation, there is also a type mismatch, no?
It is emitting a warning: If the procedure's interface were explicit, this reference would be in error
.
The reason it is only a warning is that some very old Fortran code out there is happy propagating procedures as data dummy and back to procedure dummy. Being very strict with implicit interface checks would break a lot of old code where the compiler did not checked against the actual definitions. But flang-new has option to turn warnings into errors.
BTW, the same waring is occurring in your original test case, which points that the INTRINSIC attribute of DCOS was somehow lost/ignored in the main program (flang-new -fc1 -debug-dump-symbols
tells DCOS in main is an implicit object and not the one from the module: dcos (Implicit) size=4 offset=0: ObjectEntity type: REAL(4)
). Unless there is some Fortran rules that justify this, this could be a name resolution bug. @klausler.
@jeanPerier I think I have an idea of what's going on. The original reproducer declares a language standard intrinsic inside a module. If I understand correctly how genIntrinsicRef
works, it will never process this correctly because intrinsic
won't be null in this particular case. Does that make sense?
There is indeed a bug here in name resolution with an explicit INTRINSIC
statement in a module. It's happening because the Fortran language is unclear about what should happen in a related case. Should COS
be viewed as part of the module, or not, in the following:
module m
real :: one.= cos(0.)
end
program t
use m
real :: cos = 2. ! error or not?
end
gfortran and others do NOT use-associate COS
from the module; Intel and other do. f18 is trying to follow the gfortran precedent, and does so by not importing any intrinsics from modules. But clearly we should import intrinsic procedures with explicit INTRINSIC
attributes. Will fix.
Patch has been merged into llvm-project/main, and the original test case above now compiles cleanly and runs successfully. Closing this bug report.
When an intrinsic function name declared in an
intrinsic
statement is specified as an argument of a subroutine, the function cannot be used at the callee.The following lines terminate abnormally at runtime..
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
ie500_dcos.f90: