[flang-commits] [flang] [flang] Add conflicting checks for EXTERNAL attribute (PR #149973)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 23 05:38:41 PDT 2025
https://github.com/foxtran updated https://github.com/llvm/llvm-project/pull/149973
>From 2dd5e5c20774aa824a828c163dc61bf65b963226 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 22 Jul 2025 10:11:03 +0200
Subject: [PATCH 1/6] Add checks of EXTERNAL attribute
---
flang/lib/Semantics/check-declarations.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index a2f2906af10b8..a99a65b0dc0b4 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -66,6 +66,7 @@ class CheckHelper {
void CheckVolatile(const Symbol &, const DerivedTypeSpec *);
void CheckContiguous(const Symbol &);
void CheckPointer(const Symbol &);
+ void CheckExternal(const Symbol &);
void CheckPassArg(
const Symbol &proc, const Symbol *interface, const WithPassArg &);
void CheckProcBinding(const Symbol &, const ProcBindingDetails &);
@@ -983,6 +984,7 @@ void CheckHelper::CheckObjectEntity(
}
}
if (symbol.attrs().test(Attr::EXTERNAL)) {
+ CheckExternal(symbol);
SayWithDeclaration(symbol,
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
@@ -2460,6 +2462,11 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
}
}
+void CheckHelper::CheckExternal(const Symbol &symbol) {
+ CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842
+ CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
+}
+
// C760 constraints on the passed-object dummy argument
// C757 constraints on procedure pointer components
void CheckHelper::CheckPassArg(
>From 50bf419ed31a9a467bc1353a8a531e5dca03a889 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 22 Jul 2025 10:14:55 +0200
Subject: [PATCH 2/6] Add tests for EXTERNAL attribute
---
flang/test/Semantics/declarations09.f90 | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 flang/test/Semantics/declarations09.f90
diff --git a/flang/test/Semantics/declarations09.f90 b/flang/test/Semantics/declarations09.f90
new file mode 100644
index 0000000000000..4bd08a1749721
--- /dev/null
+++ b/flang/test/Semantics/declarations09.f90
@@ -0,0 +1,11 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
+
+subroutine bug149771
+
+ !ERROR: 'x1' may not have both the EXTERNAL and INTRINSIC attributes
+ integer, external, intrinsic :: x1
+
+ !ERROR: 'x2' may not have both the EXTERNAL and PARAMETER attributes
+ integer, external, parameter :: x2
+
+end subroutine bug149771
>From abf1dbf8004084b8974dc8ef35d3892e2a8611da Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Tue, 22 Jul 2025 13:56:47 +0200
Subject: [PATCH 3/6] Rename CheckExternal -> CheckExternalAttrConflicts
---
flang/lib/Semantics/check-declarations.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index a99a65b0dc0b4..113543825558e 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -66,7 +66,7 @@ class CheckHelper {
void CheckVolatile(const Symbol &, const DerivedTypeSpec *);
void CheckContiguous(const Symbol &);
void CheckPointer(const Symbol &);
- void CheckExternal(const Symbol &);
+ void CheckExternalAttrConflicts(const Symbol &);
void CheckPassArg(
const Symbol &proc, const Symbol *interface, const WithPassArg &);
void CheckProcBinding(const Symbol &, const ProcBindingDetails &);
@@ -984,7 +984,7 @@ void CheckHelper::CheckObjectEntity(
}
}
if (symbol.attrs().test(Attr::EXTERNAL)) {
- CheckExternal(symbol);
+ CheckExternalAttrConflicts(symbol);
SayWithDeclaration(symbol,
"'%s' is a data object and may not be EXTERNAL"_err_en_US,
symbol.name());
@@ -2462,7 +2462,7 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
}
}
-void CheckHelper::CheckExternal(const Symbol &symbol) {
+void CheckHelper::CheckExternalAttrConflicts(const Symbol &symbol) {
CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842
CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
}
>From b22cf10bba7c5c425bda7b093256d284d0391c0a Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Wed, 23 Jul 2025 14:33:58 +0200
Subject: [PATCH 4/6] Conflicting attributes: PARAMETER & EXTERNAL, PARAMETER &
INTRINSIC
---
flang/lib/Semantics/check-declarations.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 113543825558e..c726be82eb313 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -697,6 +697,8 @@ void CheckHelper::CheckObjectEntity(
CheckConflicting(symbol, Attr::SAVE, Attr::PARAMETER);
CheckConflicting(symbol, Attr::TARGET, Attr::PARAMETER);
CheckConflicting(symbol, Attr::VOLATILE, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::INTRINSIC, Attr::PARAMETER);
Check(details.shape());
Check(details.coshape());
if (details.shape().Rank() > common::maxRank) {
@@ -2464,7 +2466,6 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852
void CheckHelper::CheckExternalAttrConflicts(const Symbol &symbol) {
CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842
- CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER);
}
// C760 constraints on the passed-object dummy argument
>From 92885b2dbef7eec4ee0e342db296bd06e0c71295 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Wed, 23 Jul 2025 14:37:07 +0200
Subject: [PATCH 5/6] Add check for INTRINSIC & PARAMETER
---
flang/test/Semantics/declarations02.f90 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/flang/test/Semantics/declarations02.f90 b/flang/test/Semantics/declarations02.f90
index 32c3517d13cd1..90f29f90d9d0e 100644
--- a/flang/test/Semantics/declarations02.f90
+++ b/flang/test/Semantics/declarations02.f90
@@ -24,6 +24,9 @@ module m
target x4
volatile x4
+ !ERROR: 'sin' may not have both the INTRINSIC and PARAMETER attributes
+ real, parameter, intrinsic :: sin
+
type :: my_type1
integer :: x4
end type
>From fbca1e64d2756b2040294bbbae5170a3e274b1c3 Mon Sep 17 00:00:00 2001
From: "Igor S. Gerasimov" <foxtranigor at gmail.com>
Date: Wed, 23 Jul 2025 14:38:24 +0200
Subject: [PATCH 6/6] Use proper intrinsic name
---
flang/test/Semantics/declarations09.f90 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/flang/test/Semantics/declarations09.f90 b/flang/test/Semantics/declarations09.f90
index 4bd08a1749721..8abe320f5d2f3 100644
--- a/flang/test/Semantics/declarations09.f90
+++ b/flang/test/Semantics/declarations09.f90
@@ -2,8 +2,8 @@
subroutine bug149771
- !ERROR: 'x1' may not have both the EXTERNAL and INTRINSIC attributes
- integer, external, intrinsic :: x1
+ !ERROR: 'exp' may not have both the EXTERNAL and INTRINSIC attributes
+ real, external, intrinsic :: exp
!ERROR: 'x2' may not have both the EXTERNAL and PARAMETER attributes
integer, external, parameter :: x2
More information about the flang-commits
mailing list