[flang-commits] [flang] [flang] Lower special bind(c) cases without binding labels (PR #65758)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 11 02:36:54 PDT 2023
================
@@ -99,11 +99,14 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol,
// TODO: A procedure that inherits BIND(C) through another interface
// (procedure(iface)) should be dealt with in GetBindName() or some wrapper.
- if (!Fortran::semantics::IsPointer(ultimateSymbol) &&
- Fortran::semantics::IsBindCProcedure(ultimateSymbol) &&
- Fortran::semantics::ClassifyProcedure(symbol) !=
- Fortran::semantics::ProcedureDefinitionClass::Internal)
- return ultimateSymbol.name().ToString();
+ if (const auto *procDetails{
----------------
jeanPerier wrote:
> What would it mean? Does it make 'foo' an alias for 'iface', using the same binding label? Does it mean that foo has the BIND(C) attribute with no explicit binding label? The standard doesn't say.
I agree the standard is not very specific about these cases.... Now, the "normal" symbol name is part of the interface, yet a procedure statement does not create an alias of the interface name, so I would follow the same logic and say that the NAME="" in an interface does not become the binding label of all the procedure using that interface in a procedure statement. I would say that BIND(C), BIND(C, name="some_name") and BIND(C, name="") on an interface all have the same effect on procedures in procedure statement: they are as if the procedure was BIND(C).
This matches what nag, gfortran and ifort do (I cannot completely tell for XLF since it does not append underscore), nvfortran does not implicitly give a binding label to procedures in procedure statement with a BIND(C) iface. So all compilers accept NAME= on an interface and do not propagate the _explicit_ biding label on the procedures using that interface in procedure statements.
Here is a test case:
```
subroutine test()
interface
subroutine notbindcatall()
end subroutine
subroutine iface_bindc() bind(c)
end subroutine
subroutine iface_explicit_name() bind(c, name="explicit_name")
end subroutine
subroutine iface_nobinding() bind(c, name="")
end subroutine
end interface
procedure(iface_bindc) :: foo_iface_bindc
procedure(iface_explicit_name) :: foo_iface_explicit_name
procedure(iface_nobinding) :: foo_iface_nobinding
procedure(iface_bindc), bind(c, name="bar_iface_bindc_2") :: bar_iface_bindc
procedure(iface_explicit_name), bind(c,name="bar_iface_explicit_name_2") :: bar_iface_explicit_name
procedure(iface_nobinding), bind(c, name="bar_iface_nobinding_2") :: bar_iface_nobinding
procedure(iface_bindc), bind(c, name="") :: nobinding_iface_bindc
procedure(iface_explicit_name), bind(c, name="") :: nobinding_iface_explicit_name
procedure(iface_nobinding), bind(c, name="") :: nobinding_iface_nobinding
call notbindcatall()
call iface_bindc()
call iface_explicit_name()
call iface_nobinding()
call foo_iface_bindc()
call foo_iface_explicit_name()
call foo_iface_nobinding()
call bar_iface_bindc()
call bar_iface_explicit_name()
call bar_iface_nobinding()
call nobinding_iface_bindc()
call nobinding_iface_explicit_name()
call nobinding_iface_nobinding()
end subroutine
```
gfortran and nag names looks like this:
```
call notbindcatall_
call iface_bindc
call explicit_name
call iface_nobinding_
call foo_iface_bindc
call foo_iface_explicit_name
call foo_iface_nobinding
call bar_iface_bindc_2
call bar_iface_explicit_name_2
call bar_iface_nobinding_2
call nobinding_iface_bindc_
call nobinding_iface_explicit_name_
call nobinding_iface_nobinding_
```
ifort does not enforce the fact that NAME="" drops the binding label of iface_nobinding_ and nobinding_xxx but is otherwise similar.
https://github.com/llvm/llvm-project/pull/65758
More information about the flang-commits
mailing list