aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Klausler <35819229+klausler@users.noreply.github.com>2024-03-18 14:13:50 -0700
committerGitHub <noreply@github.com>2024-03-18 14:13:50 -0700
commit53e8d501e2653f416bea9ddf2687bb0aff0c9e46 (patch)
treea1da038f4018d015cd5d52b99da67bb6357e340b
parent7eb5d4fc129a9b99b4dfe8f84507a08a72b55ecf (diff)
downloadllvm-53e8d501e2653f416bea9ddf2687bb0aff0c9e46.zip
llvm-53e8d501e2653f416bea9ddf2687bb0aff0c9e46.tar.gz
llvm-53e8d501e2653f416bea9ddf2687bb0aff0c9e46.tar.bz2
[flang] Catch inappropriate attributes for PARAMETERs (#85588)
There's several symbol attributes that cannot be applied to named constants, but that weren't being checked.
-rw-r--r--flang/lib/Semantics/check-declarations.cpp5
-rw-r--r--flang/test/Semantics/declarations02.f9014
2 files changed, 19 insertions, 0 deletions
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 431cef2..581371ff 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -632,6 +632,11 @@ void CheckHelper::CheckObjectEntity(
const Symbol &symbol, const ObjectEntityDetails &details) {
CheckSymbolType(symbol);
CheckArraySpec(symbol, details.shape());
+ CheckConflicting(symbol, Attr::ALLOCATABLE, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::ASYNCHRONOUS, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::SAVE, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::TARGET, Attr::PARAMETER);
+ CheckConflicting(symbol, Attr::VOLATILE, Attr::PARAMETER);
Check(details.shape());
Check(details.coshape());
if (details.shape().Rank() > common::maxRank) {
diff --git a/flang/test/Semantics/declarations02.f90 b/flang/test/Semantics/declarations02.f90
index 439527a..f39c233 100644
--- a/flang/test/Semantics/declarations02.f90
+++ b/flang/test/Semantics/declarations02.f90
@@ -10,6 +10,20 @@ module m
integer, parameter :: x3 = 1
bind(c) :: x3
+ !ERROR: 'x4' may not have both the ALLOCATABLE and PARAMETER attributes
+ !ERROR: 'x4' may not have both the ASYNCHRONOUS and PARAMETER attributes
+ !ERROR: 'x4' may not have both the SAVE and PARAMETER attributes
+ !ERROR: 'x4' may not have both the TARGET and PARAMETER attributes
+ !ERROR: 'x4' may not have both the VOLATILE and PARAMETER attributes
+ !ERROR: The entity 'x4' with an explicit SAVE attribute must be a variable, procedure pointer, or COMMON block
+ !ERROR: An entity may not have the ASYNCHRONOUS attribute unless it is a variable
+ integer, parameter :: x4 = 1
+ allocatable x4
+ asynchronous x4
+ save x4
+ target x4
+ volatile x4
+
type :: my_type1
integer :: x4
end type