Skip to content

Commit

Permalink
[flang] Fix characterization of result of function returning procedur… (
Browse files Browse the repository at this point in the history
#66248)

…e pointer

The procedure characterization package correctly characterizes the
result of a reference to a function that returns a procedure pointer. In
the event of a result that is a pointer to a function that itself is a
procedure pointer, the code in pointer assignment semantics checking was
mistakenly using that result's procedure characteristics as the
characteristics of the original function reference. This is just wrong;
delete it.
  • Loading branch information
klausler committed Sep 18, 2023
1 parent 1609a87 commit 15c9376
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion flang/include/flang/Common/enum-class.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// enum class className { enum1, enum2, ... , enumN };
// as well as the introspective utilities
// static constexpr std::size_t className_enumSize{N};
// static inline const std::string_view EnumToString(className);
// static inline std::string_view EnumToString(className);

#ifndef FORTRAN_COMMON_ENUM_CLASS_H_
#define FORTRAN_COMMON_ENUM_CLASS_H_
Expand Down
13 changes: 3 additions & 10 deletions flang/lib/Semantics/pointer-assignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "definable.h"
#include "flang/Common/idioms.h"
#include "flang/Common/restorer.h"
#include "flang/Common/template.h"
#include "flang/Evaluate/characteristics.h"
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/fold.h"
Expand Down Expand Up @@ -397,16 +398,8 @@ bool PointerAssignmentChecker::Check(const evaluate::ProcedureDesignator &d) {
}

bool PointerAssignmentChecker::Check(const evaluate::ProcedureRef &ref) {
if (auto chars{Procedure::Characterize(ref, foldingContext_)}) {
if (chars->functionResult) {
if (const auto *proc{chars->functionResult->IsProcedurePointer()}) {
return Check(ref.proc().GetName(), true, proc);
}
}
return Check(ref.proc().GetName(), true, &*chars);
} else {
return Check(ref.proc().GetName(), true, nullptr);
}
auto chars{Procedure::Characterize(ref, foldingContext_)};
return Check(ref.proc().GetName(), true, common::GetPtrFromOptional(chars));
}

// The target can be unlimited polymorphic if the pointer is, or if it is
Expand Down

0 comments on commit 15c9376

Please sign in to comment.