aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/pointer-assignment.cpp
diff options
context:
space:
mode:
authorpeter klausler <pklausler@nvidia.com>2020-12-07 12:08:58 -0800
committerpeter klausler <pklausler@nvidia.com>2020-12-07 14:40:41 -0800
commit641ede93efd664cc2e1d1788b195a80b50b36f66 (patch)
tree87bb71dce6c700451a875e5e9c92b4fe8b9f639f /flang/lib/Semantics/pointer-assignment.cpp
parent155fca3cae275562e626d3e4fbfac70b4b75d2e7 (diff)
downloadllvm-641ede93efd664cc2e1d1788b195a80b50b36f66.zip
llvm-641ede93efd664cc2e1d1788b195a80b50b36f66.tar.gz
llvm-641ede93efd664cc2e1d1788b195a80b50b36f66.tar.bz2
[flang] Improve initializer semantics, esp. for component default values
This patch plugs many holes in static initializer semantics, improves error messages for default initial values and other component properties in parameterized derived type instantiations, and cleans up several small issues noticed during development. We now do proper scalar expansion, folding, and type, rank, and shape conformance checking for component default initializers in derived types and PDT instantiations. The initial values of named constants are now guaranteed to have been folded when installed in the symbol table, and are no longer folded or scalar-expanded at each use in expression folding. Semantics documentation was extended with information about the various kinds of initializations in Fortran and when each of them are processed in the compiler. Some necessary concomitant changes have bulked this patch out a bit: * contextual messages attachments, which are now produced for parameterized derived type instantiations so that the user can figure out which instance caused a problem with a component, have been added as part of ContextualMessages, and their implementation was debugged * several APIs in evaluate::characteristics was changed so that a FoldingContext is passed as an argument rather than just its intrinsic procedure table; this affected client call sites in many files * new tools in Evaluate/check-expression.cpp to determine when an Expr actually is a single constant value and to validate a non-pointer variable initializer or object component default value * shape conformance checking has additional arguments that control whether scalar expansion is allowed * several now-unused functions and data members noticed and removed * several crashes and bogus errors exposed by testing this new code were fixed * a -fdebug-stack-trace option to enable LLVM's stack tracing on a crash, which might be useful in the future TL;DR: Initialization processing does more and takes place at the right times for all of the various kinds of things that can be initialized. Differential Review: https://reviews.llvm.org/D92783
Diffstat (limited to 'flang/lib/Semantics/pointer-assignment.cpp')
-rw-r--r--flang/lib/Semantics/pointer-assignment.cpp21
1 files changed, 12 insertions, 9 deletions
diff --git a/flang/lib/Semantics/pointer-assignment.cpp b/flang/lib/Semantics/pointer-assignment.cpp
index 761d664..dc5611c 100644
--- a/flang/lib/Semantics/pointer-assignment.cpp
+++ b/flang/lib/Semantics/pointer-assignment.cpp
@@ -45,7 +45,7 @@ public:
PointerAssignmentChecker(evaluate::FoldingContext &context, const Symbol &lhs)
: context_{context}, source_{lhs.name()},
description_{"pointer '"s + lhs.name().ToString() + '\''}, lhs_{&lhs},
- procedure_{Procedure::Characterize(lhs, context.intrinsics())} {
+ procedure_{Procedure::Characterize(lhs, context)} {
set_lhsType(TypeAndShape::Characterize(lhs, context));
set_isContiguous(lhs.attrs().test(Attr::CONTIGUOUS));
set_isVolatile(lhs.attrs().test(Attr::VOLATILE));
@@ -143,7 +143,7 @@ bool PointerAssignmentChecker::Check(const evaluate::FunctionRef<T> &f) {
} else if (const auto *intrinsic{f.proc().GetSpecificIntrinsic()}) {
funcName = intrinsic->name;
}
- auto proc{Procedure::Characterize(f.proc(), context_.intrinsics())};
+ auto proc{Procedure::Characterize(f.proc(), context_)};
if (!proc) {
return false;
}
@@ -262,7 +262,7 @@ bool PointerAssignmentChecker::Check(
}
bool PointerAssignmentChecker::Check(const evaluate::ProcedureDesignator &d) {
- if (auto chars{Procedure::Characterize(d, context_.intrinsics())}) {
+ if (auto chars{Procedure::Characterize(d, context_)}) {
return Check(d.GetName(), false, &*chars);
} else {
return Check(d.GetName(), false);
@@ -271,7 +271,7 @@ bool PointerAssignmentChecker::Check(const evaluate::ProcedureDesignator &d) {
bool PointerAssignmentChecker::Check(const evaluate::ProcedureRef &ref) {
const Procedure *procedure{nullptr};
- auto chars{Procedure::Characterize(ref, context_.intrinsics())};
+ auto chars{Procedure::Characterize(ref, context_)};
if (chars) {
procedure = &*chars;
if (chars->functionResult) {
@@ -299,10 +299,13 @@ bool PointerAssignmentChecker::LhsOkForUnlimitedPoly() const {
template <typename... A>
parser::Message *PointerAssignmentChecker::Say(A &&...x) {
auto *msg{context_.messages().Say(std::forward<A>(x)...)};
- if (lhs_) {
- return evaluate::AttachDeclaration(msg, *lhs_);
- } else if (!source_.empty()) {
- msg->Attach(source_, "Declaration of %s"_en_US, description_);
+ if (msg) {
+ if (lhs_) {
+ return evaluate::AttachDeclaration(msg, *lhs_);
+ }
+ if (!source_.empty()) {
+ msg->Attach(source_, "Declaration of %s"_en_US, description_);
+ }
}
return msg;
}
@@ -358,7 +361,7 @@ static bool CheckPointerBounds(
}
}
if (isBoundsRemapping && rhs.Rank() != 1 &&
- !evaluate::IsSimplyContiguous(rhs, context.intrinsics())) {
+ !evaluate::IsSimplyContiguous(rhs, context)) {
messages.Say("Pointer bounds remapping target must have rank 1 or be"
" simply contiguous"_err_en_US); // 10.2.2.3(9)
}