You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat bug_name.f90
subroutine mysub(x,y)
character :: x, y
y = x
end
program p
external mysub
character c,d
c = 'a'
call mysub(c,d)
print *, d
end
$ fort bug_name.f90
bug_name.o: In function `main':
bug_name.f90:(.text+0x7b): undefined reference to `mysub_.1'
collect2: error: ld returned 1 exit status
If you use -S -emit-llvm you can see that callee is produced as mysub_ and caller is tying to invoke mysub_.1.
The text was updated successfully, but these errors were encountered:
A call to an procedure declared external triggers codegen to produce a function declaration matching the call (there might be some set up on AST level too, but nonetheless). That makes backend perfectly content with the generated code in simple cases, but is not correct in general. It also directly leads to this bug.
Before modules external was used to call procedures defined outside of current program unit scope. The only part of procedure signature such declarations can describe is the return type (or lack of it), parameters are taken from the call and don't have to match between different calls to the same external. The gotcha is that it is OK to define the target procedure in the same source file and calling mismatch between declaration and the call would only lead to a warning (at least in GNU Fortran).
What happens in this bug is that the second definition produced by the call site is treated as a local redefinition and that's why it gets a .1 name. To fix this the compiler need to check if a function with the same name is already defined in this file and ditch the definition in this case.
Migrated from llvm-flang/flang#2
To reproduce:
If you use
-S -emit-llvm
you can see that callee is produced asmysub_
and caller is tying to invokemysub_.1
.The text was updated successfully, but these errors were encountered: