Skip to content

Commit 53e8d50

Browse files
authored
[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.
1 parent 7eb5d4f commit 53e8d50

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ void CheckHelper::CheckObjectEntity(
632632
const Symbol &symbol, const ObjectEntityDetails &details) {
633633
CheckSymbolType(symbol);
634634
CheckArraySpec(symbol, details.shape());
635+
CheckConflicting(symbol, Attr::ALLOCATABLE, Attr::PARAMETER);
636+
CheckConflicting(symbol, Attr::ASYNCHRONOUS, Attr::PARAMETER);
637+
CheckConflicting(symbol, Attr::SAVE, Attr::PARAMETER);
638+
CheckConflicting(symbol, Attr::TARGET, Attr::PARAMETER);
639+
CheckConflicting(symbol, Attr::VOLATILE, Attr::PARAMETER);
635640
Check(details.shape());
636641
Check(details.coshape());
637642
if (details.shape().Rank() > common::maxRank) {

flang/test/Semantics/declarations02.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ module m
1010
integer, parameter :: x3 = 1
1111
bind(c) :: x3
1212

13+
!ERROR: 'x4' may not have both the ALLOCATABLE and PARAMETER attributes
14+
!ERROR: 'x4' may not have both the ASYNCHRONOUS and PARAMETER attributes
15+
!ERROR: 'x4' may not have both the SAVE and PARAMETER attributes
16+
!ERROR: 'x4' may not have both the TARGET and PARAMETER attributes
17+
!ERROR: 'x4' may not have both the VOLATILE and PARAMETER attributes
18+
!ERROR: The entity 'x4' with an explicit SAVE attribute must be a variable, procedure pointer, or COMMON block
19+
!ERROR: An entity may not have the ASYNCHRONOUS attribute unless it is a variable
20+
integer, parameter :: x4 = 1
21+
allocatable x4
22+
asynchronous x4
23+
save x4
24+
target x4
25+
volatile x4
26+
1327
type :: my_type1
1428
integer :: x4
1529
end type

0 commit comments

Comments
 (0)