[flang-commits] [flang] [flang] Retain internal and BIND(C) host procedure link in FIR (PR #87796)

via flang-commits flang-commits at lists.llvm.org
Fri Apr 12 11:37:17 PDT 2024


================
@@ -589,6 +589,21 @@ void Fortran::lower::CalleeInterface::setFuncAttrs(
 static void addSymbolAttribute(mlir::func::FuncOp func,
                                const Fortran::semantics::Symbol &sym,
                                mlir::MLIRContext &mlirContext) {
+  // The link between an internal procedure and its host procedure is lost
+  // in FIR if the host is BIND(C) since the internal mangling will not
+  // allow retrieving the host bind(C) name, and therefore func.func symbol.
+  // Preserve it as an attribute so that this can be later retrieved.
+  if (sym.owner().kind() == Fortran::semantics::Scope::Kind::Subprogram)
+    if (const Fortran::semantics::Symbol *hostProcedure = sym.owner().symbol())
+      if (Fortran::semantics::IsBindCProcedure(*hostProcedure)) {
----------------
jeanPerier wrote:

Thanks for the feedback. Makes sense to me. It is also then possible to get rid of fir.internal_proc and just use the new attribute. I updated the patch to do it for all internal procedures, including the ones from the main programs, and removed fir.internal_proc.

https://github.com/llvm/llvm-project/pull/87796


More information about the flang-commits mailing list