forked from OSchip/llvm-project
[flang] Fix pointer target check
Original-commit: flang-compiler/f18@8249bc8cd4 Reviewed-on: https://github.com/flang-compiler/f18/pull/601 Tree-same-pre-rewrite: false
This commit is contained in:
parent
00861127ac
commit
3f753af937
|
@ -113,21 +113,19 @@ template<typename T>
|
||||||
void CheckPointerAssignment(parser::ContextualMessages &messages,
|
void CheckPointerAssignment(parser::ContextualMessages &messages,
|
||||||
const IntrinsicProcTable &intrinsics, const Symbol &lhs,
|
const IntrinsicProcTable &intrinsics, const Symbol &lhs,
|
||||||
const Designator<T> &d) {
|
const Designator<T> &d) {
|
||||||
if (const auto *symbol{d.GetBaseObject().symbol()}) {
|
const Symbol *last{d.GetLastSymbol()}, *base{d.GetBaseObject().symbol()};
|
||||||
const Symbol &ultimate{symbol->GetUltimate()};
|
if (last != nullptr && base != nullptr) {
|
||||||
std::optional<parser::MessageFixedText> error;
|
std::optional<parser::MessageFixedText> error;
|
||||||
if (IsProcedurePointer(lhs)) {
|
if (IsProcedurePointer(lhs)) {
|
||||||
// Shouldn't be here in this function unless lhs is an
|
// Shouldn't be here in this function unless lhs is an
|
||||||
// object pointer.
|
// object pointer.
|
||||||
error = "In assignment to procedure pointer '%s', the "
|
error = "In assignment to procedure pointer '%s', the "
|
||||||
"target is not a procedure or procedure pointer"_err_en_US;
|
"target is not a procedure or procedure pointer"_err_en_US;
|
||||||
} else if (!ultimate.template has<semantics::ObjectEntityDetails>() ||
|
} else if (GetLastTarget(d) == nullptr) {
|
||||||
!ultimate.attrs().HasAny(semantics::Attrs(
|
|
||||||
{semantics::Attr::POINTER, semantics::Attr::TARGET}))) {
|
|
||||||
error = "In assignment to object pointer '%s', the target '%s' "
|
error = "In assignment to object pointer '%s', the target '%s' "
|
||||||
"is not an object with POINTER or TARGET attributes"_err_en_US;
|
"is not an object with POINTER or TARGET attributes"_err_en_US;
|
||||||
} else if (auto rhsTypeAndShape{characteristics::TypeAndShape::Characterize(
|
} else if (auto rhsTypeAndShape{
|
||||||
d.GetLastSymbol())}) {
|
characteristics::TypeAndShape::Characterize(last)}) {
|
||||||
if (auto lhsTypeAndShape{
|
if (auto lhsTypeAndShape{
|
||||||
characteristics::TypeAndShape::Characterize(lhs)}) {
|
characteristics::TypeAndShape::Characterize(lhs)}) {
|
||||||
if (!lhsTypeAndShape->IsCompatibleWith(messages, *rhsTypeAndShape)) {
|
if (!lhsTypeAndShape->IsCompatibleWith(messages, *rhsTypeAndShape)) {
|
||||||
|
@ -137,9 +135,9 @@ void CheckPointerAssignment(parser::ContextualMessages &messages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error.has_value()) {
|
if (error.has_value()) {
|
||||||
if (auto *msg{messages.Say(*error, lhs.name(), ultimate.name())}) {
|
if (auto *msg{messages.Say(*error, lhs.name(), last->name())}) {
|
||||||
msg->Attach(lhs.name(), "Declaration of pointer being assigned"_en_US)
|
msg->Attach(lhs.name(), "Declaration of pointer being assigned"_en_US)
|
||||||
.Attach(ultimate.name(), "Declaration of pointer target"_en_US);
|
.Attach(last->name(), "Declaration of pointer target"_en_US);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue