[PATCH] D103714: [flang] Check for undefined derived types
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 4 14:34:13 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2b795ec682ff: [flang] Check for undefined derived types (authored by PeteSteinfeld).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103714/new/
https://reviews.llvm.org/D103714
Files:
flang/include/flang/Semantics/symbol.h
flang/lib/Semantics/check-declarations.cpp
flang/lib/Semantics/resolve-names.cpp
flang/lib/Semantics/type.cpp
flang/test/Semantics/bad-forward-type.f90
Index: flang/test/Semantics/bad-forward-type.f90
===================================================================
--- flang/test/Semantics/bad-forward-type.f90
+++ flang/test/Semantics/bad-forward-type.f90
@@ -90,3 +90,10 @@
integer, kind :: n = 3
end type
end subroutine s9
+
+subroutine s10
+ type t
+ !ERROR: The derived type 'undef' has not been defined
+ type(undef), pointer :: y
+ end type
+end subroutine s10
Index: flang/lib/Semantics/type.cpp
===================================================================
--- flang/lib/Semantics/type.cpp
+++ flang/lib/Semantics/type.cpp
@@ -244,6 +244,7 @@
foldingContext.messages().Say(typeSymbol_.name(),
"The derived type '%s' was forward-referenced but not defined"_err_en_US,
typeSymbol_.name());
+ context.SetError(typeSymbol_);
return;
}
EvaluateParameters(context);
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -3957,6 +3957,7 @@
CHECK(scope.symbol());
CHECK(scope.symbol()->scope() == &scope);
auto &details{scope.symbol()->get<DerivedTypeDetails>()};
+ details.set_isForwardReferenced(false);
std::set<SourceName> paramNames;
for (auto ¶mName : std::get<std::list<parser::Name>>(stmt.statement.t)) {
details.add_paramName(paramName.source);
@@ -5027,7 +5028,7 @@
Resolve(name, *symbol);
};
DerivedTypeDetails details;
- details.set_isForwardReferenced();
+ details.set_isForwardReferenced(true);
symbol->set_details(std::move(details));
} else { // C732
Say(name, "Derived type '%s' not found"_err_en_US);
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -845,6 +845,10 @@
void CheckHelper::CheckDerivedType(
const Symbol &derivedType, const DerivedTypeDetails &details) {
+ if (details.isForwardReferenced() && !context_.HasError(derivedType)) {
+ messages_.Say("The derived type '%s' has not been defined"_err_en_US,
+ derivedType.name());
+ }
const Scope *scope{derivedType.scope()};
if (!scope) {
CHECK(details.isForwardReferenced());
Index: flang/include/flang/Semantics/symbol.h
===================================================================
--- flang/include/flang/Semantics/symbol.h
+++ flang/include/flang/Semantics/symbol.h
@@ -259,7 +259,7 @@
void add_paramDecl(const Symbol &symbol) { paramDecls_.push_back(symbol); }
void add_component(const Symbol &);
void set_sequence(bool x = true) { sequence_ = x; }
- void set_isForwardReferenced() { isForwardReferenced_ = true; }
+ void set_isForwardReferenced(bool value) { isForwardReferenced_ = value; }
const std::list<SourceName> &componentNames() const {
return componentNames_;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103714.349973.patch
Type: text/x-patch
Size: 3014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210604/32b1afe9/attachment-0001.bin>
More information about the llvm-commits
mailing list