[PATCH] D87535: [flang] Fix bug for forward referenced type
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 11 11:08:29 PDT 2020
PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld requested review of this revision.
A type name in an IMPLICIT declaration that was later used in a PARAMETER
statement caused problems because the default symbol scope had not yet been
initialized. I avoided dereferencing in the situation where the default scope
was uninitialized and added a test that triggers the problem.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D87535
Files:
flang/lib/Semantics/symbol.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
@@ -70,3 +70,13 @@
type, extends(undef) :: t
end type
end subroutine
+
+subroutine s8
+ !ERROR: Derived type 't2' was used but never defined
+ !ERROR: The derived type 't2' was forward-referenced but not defined
+ implicit type(t2)(x)
+ parameter(y=t2(12.3))
+ type t2
+ real :: c
+ end type
+end subroutine
Index: flang/lib/Semantics/symbol.cpp
===================================================================
--- flang/lib/Semantics/symbol.cpp
+++ flang/lib/Semantics/symbol.cpp
@@ -541,13 +541,12 @@
const Symbol *Symbol::GetParentComponent(const Scope *scope) const {
if (const auto *dtDetails{detailsIf<DerivedTypeDetails>()}) {
- if (!scope) {
- scope = scope_;
+ const Scope *localScope = scope ? scope : scope_;
+ if (localScope) {
+ return dtDetails->GetParentComponent(DEREF(localScope));
}
- return dtDetails->GetParentComponent(DEREF(scope));
- } else {
- return nullptr;
}
+ return nullptr;
}
void DerivedTypeDetails::add_component(const Symbol &symbol) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87535.291278.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200911/f877554f/attachment.bin>
More information about the llvm-commits
mailing list