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

Names of subroutines do not match between caller, callee, and declaration in same compilation unit #2

Open
jleidel opened this issue Dec 11, 2015 · 5 comments

Comments

@jleidel
Copy link

jleidel commented Dec 11, 2015

Yep:

SUBROUTINE MYSUB(B,N)
CHARACTER_1 B(1)
CHARACTER_1 BLNK
SAVE BLNK
DATA BLNK /' '/

DO 10 I=1,N
B(I)=BLNK
10 CONTINUE
RETURN
END

program invokecharblank
character_1 STRING(10)
integer_4 N
external MYSUB

N = 10
call MYSUB(STRING,N)

do 20 I=1,10
print *, 'string = ', STRING(I), '.'
20 continue

end
Compile with -S -emit-llvm and then pass it to clang with the rt library linked.
It will fail saying that the called function does not exist.

@jleidel
Copy link
Author

jleidel commented Dec 11, 2015

In examining the IR, Flang appears to mangle the caller beyond appending the underscore. The IR shows:

subroutine definition:
define void @mysub_([1 x i8]* noalias %b, i32* noalias %n)

call location:
call void @mysub_.1([1 x i8]* %0, i32* %n)

The symbol is declared at the bottom of the IR as follows:
declare void @mysub_.1([1 x i8], i32)

@jleidel
Copy link
Author

jleidel commented Dec 11, 2015

The bug occurs when the subroutines are defined as "external"

@jleidel
Copy link
Author

jleidel commented Dec 11, 2015

Issue migrated from llvm-flang/flang-old#8

@ppenzin
Copy link
Collaborator

ppenzin commented Dec 14, 2017

How to compile this? I copy-pasted everything in a file and got a bunch or compile-time errors, regardless of file extension (fixed or free-form).

@ppenzin
Copy link
Collaborator

ppenzin commented Dec 14, 2017

Got it reproduced, never mind.

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

2 participants