Skip to content

Commit b29d632

Browse files
authored
[flang] Accept BIND(C) derived type for Cray pointees (llvm#76538)
The compiler requires that a Cray pointee have a SEQUENCE type, but a recent bug report points out that a BIND(C) type should also be accepted. Fixes llvm#76529.
1 parent 3bbdbb2 commit b29d632

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,7 @@ bool IsFunctionResult(const Symbol &);
12271227
bool IsKindTypeParameter(const Symbol &);
12281228
bool IsLenTypeParameter(const Symbol &);
12291229
bool IsExtensibleType(const DerivedTypeSpec *);
1230+
bool IsSequenceOrBindCType(const DerivedTypeSpec *);
12301231
bool IsBuiltinDerivedType(const DerivedTypeSpec *derived, const char *name);
12311232
bool IsBuiltinCPtr(const Symbol &);
12321233
bool IsEventType(const DerivedTypeSpec *);

flang/lib/Evaluate/tools.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,9 +1724,13 @@ bool IsLenTypeParameter(const Symbol &symbol) {
17241724
}
17251725

17261726
bool IsExtensibleType(const DerivedTypeSpec *derived) {
1727-
return derived && !IsIsoCType(derived) &&
1728-
!derived->typeSymbol().attrs().test(Attr::BIND_C) &&
1729-
!derived->typeSymbol().get<DerivedTypeDetails>().sequence();
1727+
return !IsSequenceOrBindCType(derived) && !IsIsoCType(derived);
1728+
}
1729+
1730+
bool IsSequenceOrBindCType(const DerivedTypeSpec *derived) {
1731+
return derived &&
1732+
(derived->typeSymbol().attrs().test(Attr::BIND_C) ||
1733+
derived->typeSymbol().get<DerivedTypeDetails>().sequence());
17301734
}
17311735

17321736
bool IsBuiltinDerivedType(const DerivedTypeSpec *derived, const char *name) {

flang/lib/Semantics/resolve-names.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5940,9 +5940,9 @@ void DeclarationVisitor::Post(const parser::BasedPointer &bp) {
59405940
}
59415941
if (const auto *pointeeType{pointee->GetType()}) {
59425942
if (const auto *derived{pointeeType->AsDerived()}) {
5943-
if (!derived->typeSymbol().get<DerivedTypeDetails>().sequence()) {
5943+
if (!IsSequenceOrBindCType(derived)) {
59445944
Say(pointeeName,
5945-
"Type of Cray pointee '%s' is a non-sequence derived type"_err_en_US);
5945+
"Type of Cray pointee '%s' is a derived type that is neither SEQUENCE nor BIND(C)"_err_en_US);
59465946
}
59475947
}
59485948
}
@@ -6177,15 +6177,13 @@ void DeclarationVisitor::CheckCommonBlocks() {
61776177
Say(name,
61786178
"Unlimited polymorphic pointer '%s' may not appear in a COMMON block"_err_en_US);
61796179
} else if (const auto *derived{type->AsDerived()}) {
6180-
auto &typeSymbol{derived->typeSymbol()};
6181-
if (!typeSymbol.attrs().test(Attr::BIND_C) &&
6182-
!typeSymbol.get<DerivedTypeDetails>().sequence()) {
6180+
if (!IsSequenceOrBindCType(derived)) {
61836181
Say(name,
61846182
"Derived type '%s' in COMMON block must have the BIND or"
61856183
" SEQUENCE attribute"_err_en_US);
61866184
}
61876185
UnorderedSymbolSet typeSet;
6188-
CheckCommonBlockDerivedType(name, typeSymbol, typeSet);
6186+
CheckCommonBlockDerivedType(name, derived->typeSymbol(), typeSet);
61896187
}
61906188
}
61916189
}

flang/test/Semantics/resolve61.f90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@ subroutine p12
107107
type t2
108108
integer c2
109109
end type
110+
type, bind(c) :: t3
111+
integer c3
112+
end type
110113
type(t1) :: x1
111114
type(t2) :: x2
115+
type(t3) :: x3
112116
pointer(a, x1)
113-
!ERROR: Type of Cray pointee 'x2' is a non-sequence derived type
117+
!ERROR: Type of Cray pointee 'x2' is a derived type that is neither SEQUENCE nor BIND(C)
114118
pointer(b, x2)
119+
pointer(c, x3)
115120
end
116121

117122
subroutine p13

0 commit comments

Comments
 (0)