Skip to content

Commit abebac5

Browse files
authored
[flang] Dig deeper to find more EVENT_TYPE/LOCK_TYPE misuse (#130687)
Only objects may have these types, or have potential subobject components with these types.
1 parent 587f997 commit abebac5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,20 @@ void CheckHelper::CheckSymbolType(const Symbol &symbol) {
37173717
"'%s' has a type %s with a deferred type parameter but is neither an allocatable nor an object pointer"_err_en_US,
37183718
symbol.name(), dyType->AsFortran());
37193719
}
3720+
if (!symbol.has<ObjectEntityDetails>()) {
3721+
if (const DerivedTypeSpec *
3722+
derived{evaluate::GetDerivedTypeSpec(*dyType)}) {
3723+
if (IsEventTypeOrLockType(derived)) {
3724+
messages_.Say(
3725+
"Entity '%s' with EVENT_TYPE or LOCK_TYPE must be an object"_err_en_US,
3726+
symbol.name());
3727+
} else if (auto iter{FindEventOrLockPotentialComponent(*derived)}) {
3728+
messages_.Say(
3729+
"Entity '%s' with EVENT_TYPE or LOCK_TYPE potential subobject component '%s' must be an object"_err_en_US,
3730+
symbol.name(), iter.BuildResultDesignatorName());
3731+
}
3732+
}
3733+
}
37203734
}
37213735
}
37223736

flang/test/Semantics/event02b.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ program test_event_wait
1818
character(len=128) error_message, non_scalar_char(1), co_indexed_character[*], superfluous_errmsg
1919
logical invalid_type
2020

21+
type t
22+
type(event_type) event
23+
end type
24+
!ERROR: Entity 'badfunc0' with EVENT_TYPE or LOCK_TYPE must be an object
25+
procedure(type(event_type)) :: badfunc0
26+
!ERROR: Entity 'badfunc1' with EVENT_TYPE or LOCK_TYPE must be an object
27+
procedure(type(event_type)), pointer :: badfunc1
28+
!ERROR: Entity 'badfunc2' with EVENT_TYPE or LOCK_TYPE potential subobject component '%event' must be an object
29+
procedure(type(t)) badfunc2
30+
!ERROR: Entity 'badfunc3' with EVENT_TYPE or LOCK_TYPE must be an object
31+
type(event_type), external :: badfunc3
32+
!ERROR: Entity 'badfunc4' with EVENT_TYPE or LOCK_TYPE potential subobject component '%event' must be an object
33+
type(t), external :: badfunc4
34+
2135
!____________________ non-standard-conforming statements __________________________
2236

2337
!_________________________ invalid event-variable ________________________________

0 commit comments

Comments
 (0)