[flang-commits] [flang] [flang] Explicit interface externals are constant expressions (PR #166181)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Nov 3 07:38:44 PST 2025


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/166181

... but the constant expression test didn't allow for them, so they weren't working in initializers.

>From e6e7e5e4756bfbae69c03a68e1991a36870afc8f Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 3 Nov 2025 07:36:47 -0800
Subject: [PATCH] [flang] Explicit interface externals are constant expressions

... but the constant expression test didn't allow for them, so
they weren't working in initializers.
---
 flang/lib/Evaluate/check-expression.cpp |  7 +++++--
 flang/test/Semantics/structconst12.f90  | 12 ++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Semantics/structconst12.f90

diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 839717d0833f1..656fc50044877 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -379,8 +379,11 @@ bool IsInitialProcedureTarget(const semantics::Symbol &symbol) {
       common::visitors{
           [&](const semantics::SubprogramDetails &subp) {
             return !subp.isDummy() && !subp.stmtFunction() &&
-                symbol.owner().kind() != semantics::Scope::Kind::MainProgram &&
-                symbol.owner().kind() != semantics::Scope::Kind::Subprogram;
+                ((symbol.owner().kind() !=
+                         semantics::Scope::Kind::MainProgram &&
+                     symbol.owner().kind() !=
+                         semantics::Scope::Kind::Subprogram) ||
+                    ultimate.attrs().test(semantics::Attr::EXTERNAL));
           },
           [](const semantics::SubprogramNameDetails &x) {
             return x.kind() != semantics::SubprogramKind::Internal;
diff --git a/flang/test/Semantics/structconst12.f90 b/flang/test/Semantics/structconst12.f90
new file mode 100644
index 0000000000000..345016b236c8a
--- /dev/null
+++ b/flang/test/Semantics/structconst12.f90
@@ -0,0 +1,12 @@
+!RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+!CHECK: TYPE(t) :: x = t(pp=f)
+!CHECK-NOT: error:
+interface
+  function f()
+  end
+end interface
+type t
+  procedure(f), nopass, pointer :: pp
+end type
+type(t) :: x = t(pp=f)
+end



More information about the flang-commits mailing list