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

via flang-commits flang-commits at lists.llvm.org
Mon Nov 3 07:39:19 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/166181.diff


2 Files Affected:

- (modified) flang/lib/Evaluate/check-expression.cpp (+5-2) 
- (added) flang/test/Semantics/structconst12.f90 (+12) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list