[flang-commits] [flang] [flang] intrinsic and external are mutually exclusive (PR #149830)

Connector Switch via flang-commits flang-commits at lists.llvm.org
Mon Jul 21 07:58:32 PDT 2025


https://github.com/c8ef created https://github.com/llvm/llvm-project/pull/149830

None

>From 7ce2a13b4d9246f9733e55ab849d0ccd4fd67470 Mon Sep 17 00:00:00 2001
From: c8ef <c8ef at outlook.com>
Date: Mon, 21 Jul 2025 14:57:47 +0000
Subject: [PATCH] [flang] intrinsic and external are mutually exclusive

---
 flang/lib/Semantics/resolve-names.cpp              | 14 +-------------
 flang/test/Semantics/null-init.f90                 |  1 -
 .../test/Semantics/resolve-intrinsic-external.f90  |  9 +++++++++
 3 files changed, 10 insertions(+), 14 deletions(-)
 create mode 100644 flang/test/Semantics/resolve-intrinsic-external.f90

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b3268605e7c0c..cb59b3f881272 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2351,6 +2351,7 @@ bool AttrsVisitor::IsConflictingAttr(Attr attrName) {
       HaveAttrConflict(attrName, Attr::PASS, Attr::NOPASS) || // C781
       HaveAttrConflict(attrName, Attr::PURE, Attr::IMPURE) ||
       HaveAttrConflict(attrName, Attr::PUBLIC, Attr::PRIVATE) ||
+      HaveAttrConflict(attrName, Attr::EXTERNAL, Attr::INTRINSIC) || // C840
       HaveAttrConflict(attrName, Attr::RECURSIVE, Attr::NON_RECURSIVE);
 }
 bool AttrsVisitor::CheckAndSet(Attr attrName) {
@@ -3311,11 +3312,6 @@ bool ScopeHandler::CheckPossibleBadForwardRef(const Symbol &symbol) {
 void ScopeHandler::MakeExternal(Symbol &symbol) {
   if (!symbol.attrs().test(Attr::EXTERNAL)) {
     SetImplicitAttr(symbol, Attr::EXTERNAL);
-    if (symbol.attrs().test(Attr::INTRINSIC)) { // C840
-      Say(symbol.name(),
-          "Symbol '%s' cannot have both EXTERNAL and INTRINSIC attributes"_err_en_US,
-          symbol.name());
-    }
   }
 }
 
@@ -5606,10 +5602,6 @@ bool DeclarationVisitor::Pre(const parser::ExternalStmt &x) {
         SayWithDecl(
             name, *symbol, "EXTERNAL attribute not allowed on '%s'"_err_en_US);
       }
-    } else if (symbol->attrs().test(Attr::INTRINSIC)) { // C840
-      Say(symbol->name(),
-          "Symbol '%s' cannot have both INTRINSIC and EXTERNAL attributes"_err_en_US,
-          symbol->name());
     }
   }
   return false;
@@ -5637,10 +5629,6 @@ void DeclarationVisitor::DeclareIntrinsic(const parser::Name &name) {
   } else if (!ConvertToProcEntity(symbol, name.source)) {
     SayWithDecl(
         name, symbol, "INTRINSIC attribute not allowed on '%s'"_err_en_US);
-  } else if (symbol.attrs().test(Attr::EXTERNAL)) { // C840
-    Say(symbol.name(),
-        "Symbol '%s' cannot have both EXTERNAL and INTRINSIC attributes"_err_en_US,
-        symbol.name());
   } else {
     if (symbol.GetType()) {
       // These warnings are worded so that they should make sense in either
diff --git a/flang/test/Semantics/null-init.f90 b/flang/test/Semantics/null-init.f90
index d01ad75a75a11..3f81bd907eabc 100644
--- a/flang/test/Semantics/null-init.f90
+++ b/flang/test/Semantics/null-init.f90
@@ -30,7 +30,6 @@ module m5
 end module
 
 module m6
-  !ERROR: Symbol 'null' cannot have both INTRINSIC and EXTERNAL attributes
   integer, pointer :: p => null()
   external :: null
 end module
diff --git a/flang/test/Semantics/resolve-intrinsic-external.f90 b/flang/test/Semantics/resolve-intrinsic-external.f90
new file mode 100644
index 0000000000000..269ef37207c1f
--- /dev/null
+++ b/flang/test/Semantics/resolve-intrinsic-external.f90
@@ -0,0 +1,9 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+real function eval(x, n)
+  real :: x
+  integer :: n
+  !ERROR: Attributes 'EXTERNAL' and 'INTRINSIC' conflict with each other
+  real, external, intrinsic :: exp
+  eval = 1.0
+end function eval



More information about the flang-commits mailing list