[flang-commits] [flang] [Flang] External subprograms should be allowed as proc_target in procedure pointers. (PR #183268)
via flang-commits
flang-commits at lists.llvm.org
Wed Feb 25 02:06:22 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: None (ShashwathiNavada)
<details>
<summary>Changes</summary>
Fixes https://github.com/llvm/llvm-project/issues/177505.
This patch updates an existing external procedure symbol with the correct function signature and argument attributes, so it can be safely used as a proc_target without signature conflicts.
---
Full diff: https://github.com/llvm/llvm-project/pull/183268.diff
2 Files Affected:
- (modified) flang/lib/Lower/CallInterface.cpp (+15)
- (added) flang/test/Semantics/extrn_subp.f90 (+20)
``````````diff
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index f5ae2de5cad8b..65cac0466d5ea 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -695,6 +695,21 @@ void Fortran::lower::CallInterface<T>::declare() {
mlir::ModuleOp module = converter.getModuleOp();
mlir::SymbolTable *symbolTable = converter.getMLIRSymbolTable();
func = fir::FirOpBuilder::getNamedFunction(module, symbolTable, name);
+ if (func) {
+ if constexpr (std::is_same_v<T, Fortran::lower::CalleeInterface>) {
+ mlir::FunctionType ty = genFunctionType();
+ if (!func.getBlocks().empty())
+ fir::emitFatalError(
+ func.getLoc(),
+ "conflicting procedure definition with mismatched signature");
+ if (func.getFunctionType() != ty) {
+ func.setType(ty);
+ for (const auto &placeHolder : llvm::enumerate(inputs))
+ func.setArgAttrs(placeHolder.index(),
+ placeHolder.value().attributes);
+ }
+ }
+ }
if (!func) {
mlir::Location loc = side().getCalleeLocation();
mlir::MLIRContext &mlirContext = converter.getMLIRContext();
diff --git a/flang/test/Semantics/extrn_subp.f90 b/flang/test/Semantics/extrn_subp.f90
new file mode 100644
index 0000000000000..67b3b02a85363
--- /dev/null
+++ b/flang/test/Semantics/extrn_subp.f90
@@ -0,0 +1,20 @@
+! RUN: flang %s
+
+Module m1
+ external::sub
+ type ty
+ procedure(),pointer,nopass :: ptr5=>sub
+ end type
+ procedure(),pointer:: ptr6=>sub
+end module
+
+use m1
+ integer::jj =4
+ call ptr6(10)
+ print*,"Pass"
+end
+
+subroutine sub(a)
+ integer::a
+ print*,"sub"
+end subroutine
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/183268
More information about the flang-commits
mailing list