Skip to content

[flang] Allow interoperable object to have interoperable derived type… #94768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CheckHelper {
void CheckProcedureAssemblyName(const Symbol &symbol);
void CheckExplicitSave(const Symbol &);
parser::Messages WhyNotInteroperableDerivedType(const Symbol &);
parser::Messages WhyNotInteroperableObject(const Symbol &, bool isError);
parser::Messages WhyNotInteroperableObject(const Symbol &);
parser::Messages WhyNotInteroperableFunctionResult(const Symbol &);
parser::Messages WhyNotInteroperableProcedure(const Symbol &, bool isError);
void CheckBindC(const Symbol &);
Expand Down Expand Up @@ -3012,15 +3012,13 @@ parser::Messages CheckHelper::WhyNotInteroperableDerivedType(
return msgs;
}

parser::Messages CheckHelper::WhyNotInteroperableObject(
const Symbol &symbol, bool isError) {
parser::Messages CheckHelper::WhyNotInteroperableObject(const Symbol &symbol) {
parser::Messages msgs;
if (examinedByWhyNotInteroperable_.find(symbol) !=
examinedByWhyNotInteroperable_.end()) {
return msgs;
}
bool isExplicitBindC{symbol.attrs().test(Attr::BIND_C)};
isError |= isExplicitBindC;
examinedByWhyNotInteroperable_.insert(symbol);
CHECK(symbol.has<ObjectEntityDetails>());
if (isExplicitBindC && !symbol.owner().IsModule()) {
Expand Down Expand Up @@ -3049,11 +3047,11 @@ parser::Messages CheckHelper::WhyNotInteroperableObject(
}
if (const auto *type{symbol.GetType()}) {
const auto *derived{type->AsDerived()};
if (derived) {
if (derived->typeSymbol().attrs().test(Attr::BIND_C)) {
} else if (isError) {
if (derived && !derived->typeSymbol().attrs().test(Attr::BIND_C)) {
if (!context_.IsEnabled(
common::LanguageFeature::NonBindCInteroperability)) {
msgs.Say(symbol.name(),
"The derived type of a BIND(C) object must also be BIND(C)"_err_en_US)
"The derived type of an interoperable object must be BIND(C)"_err_en_US)
.Attach(derived->typeSymbol().name(), "Non-BIND(C) type"_en_US);
} else if (auto bad{
WhyNotInteroperableDerivedType(derived->typeSymbol())};
Expand Down Expand Up @@ -3186,7 +3184,7 @@ parser::Messages CheckHelper::WhyNotInteroperableProcedure(
"A dummy procedure of an interoperable procedure should be BIND(C)"_warn_en_US);
}
} else if (dummy->has<ObjectEntityDetails>()) {
dummyMsgs = WhyNotInteroperableObject(*dummy, /*isError=*/false);
dummyMsgs = WhyNotInteroperableObject(*dummy);
} else {
CheckBindC(*dummy);
}
Expand Down Expand Up @@ -3256,7 +3254,7 @@ void CheckHelper::CheckBindC(const Symbol &symbol) {
}
}
if (symbol.has<ObjectEntityDetails>()) {
whyNot = WhyNotInteroperableObject(symbol, /*isError=*/isExplicitBindC);
whyNot = WhyNotInteroperableObject(symbol);
} else if (symbol.has<ProcEntityDetails>() ||
symbol.has<SubprogramDetails>()) {
whyNot = WhyNotInteroperableProcedure(symbol, /*isError=*/isExplicitBindC);
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Semantics/declarations02.f90
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic

module m
!ERROR: 'x1' may not have both the BIND(C) and PARAMETER attributes
Expand Down Expand Up @@ -32,14 +32,14 @@ module m
end type

!ERROR: 't1' may not have both the BIND(C) and PARAMETER attributes
!ERROR: The derived type of a BIND(C) object must also be BIND(C)
!WARNING: The derived type of an interoperable object should be BIND(C)
type(my_type1), bind(c), parameter :: t1 = my_type1(1)
!ERROR: 't2' may not have both the BIND(C) and PARAMETER attributes
type(my_type2), bind(c), parameter :: t2 = my_type2(1)

type(my_type2), parameter :: t3 = my_type2(1) ! no error
!ERROR: 't4' may not have both the BIND(C) and PARAMETER attributes
!ERROR: The derived type of a BIND(C) object must also be BIND(C)
!WARNING: The derived type of an interoperable object should be BIND(C)
type(my_type1), parameter :: t4 = my_type1(1)
!ERROR: 't5' may not have both the BIND(C) and PARAMETER attributes
type(my_type2), parameter :: t5 = my_type2(1)
Expand Down
Loading