From 9cf3c638ecdf3cb749977e44546bf98a686dc459 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Tue, 3 Dec 2019 10:21:37 -0800 Subject: [PATCH] [flang] Fix forward ref to derived type when symbol exists Fix some comments Original-commit: flang-compiler/f18@3274ed95459865057a2e77966863e6b01b5f6d35 Reviewed-on: https://github.com/flang-compiler/f18/pull/852 --- flang/lib/evaluate/intrinsics.cc | 6 +++--- flang/lib/semantics/resolve-names.cc | 14 ++++++------- flang/test/semantics/symbol17.f90 | 31 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/flang/lib/evaluate/intrinsics.cc b/flang/lib/evaluate/intrinsics.cc index 844fffa3a471..f513b2c014f6 100644 --- a/flang/lib/evaluate/intrinsics.cc +++ b/flang/lib/evaluate/intrinsics.cc @@ -708,8 +708,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ // TODO: Non-standard intrinsic functions // AND, OR, XOR, LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, // COSD, SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, -// DCMPLX, EQV, NEQV, INT8, JINT, JNINT, KNINT, -// QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, +// EQV, NEQV, INT8, JINT, JNINT, KNINT, +// QCMPLX, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, // INUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, SIZEOF, // MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR // IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, @@ -740,7 +740,7 @@ struct SpecificIntrinsicInterface : public IntrinsicInterface { // e.g. IABS(INT(i), INT(j)) not equiv to INT(ABS(i, j)). // This is allowed for restricted min/max specific functions because // the expected behavior is clear from their definitions. A warning is though - // always emitted because other compilers behavior is not ubiquitous here. + // always emitted because other compilers' behavior is not ubiquitous here. bool useGenericAndForceResultType{false}; }; diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 4e6bbe9d6ff6..b8eb6a8b6291 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -4429,15 +4429,16 @@ void DeclarationVisitor::SetType( std::optional DeclarationVisitor::ResolveDerivedType( const parser::Name &name) { - const Symbol *symbol{FindSymbol(name)}; - if (!symbol) { + Symbol *symbol{FindSymbol(name)}; + if (!symbol || symbol->has()) { if (allowForwardReferenceToDerivedType()) { - Symbol &forward{MakeSymbol(InclusiveScope(), name.source, Attrs{})}; + if (!symbol) { + symbol = &MakeSymbol(InclusiveScope(), name.source, Attrs{}); + Resolve(name, *symbol); + }; DerivedTypeDetails details; details.set_isForwardReferenced(); - forward.set_details(std::move(details)); - Resolve(name, forward); - symbol = &forward; + symbol->set_details(std::move(details)); } else { Say(name, "Derived type '%s' not found"_err_en_US); return std::nullopt; @@ -6221,5 +6222,4 @@ bool ResolveNames(SemanticsContext &context, const parser::Program &program) { ResolveNamesVisitor{context}.Walk(program); return !context.AnyFatalError(); } - } diff --git a/flang/test/semantics/symbol17.f90 b/flang/test/semantics/symbol17.f90 index 1ee8e4d49fc9..7b6ee08c4e8e 100644 --- a/flang/test/semantics/symbol17.f90 +++ b/flang/test/semantics/symbol17.f90 @@ -120,3 +120,34 @@ subroutine s2 (q1) !DEF: /s2/DerivedType2/n ObjectEntity INTEGER(4) q1%n = 1 end subroutine +!DEF: /m1 Module +module m1 + !DEF: /m1/forward PRIVATE DerivedType + private :: forward + !DEF: /m1/base PUBLIC DerivedType + type :: base + !REF: /m1/forward + !DEF: /m1/base/p POINTER ObjectEntity CLASS(forward) + class(forward), pointer :: p + end type + !REF: /m1/base + !REF: /m1/forward + type, extends(base) :: forward + !DEF: /m1/forward/n ObjectEntity INTEGER(4) + integer :: n + end type + contains + !DEF: /m1/test PUBLIC (Subroutine) Subprogram + subroutine test + !REF: /m1/forward + !DEF: /m1/test/object TARGET ObjectEntity TYPE(forward) + type(forward), target :: object + !REF: /m1/test/object + !REF: /m1/base/p + object%p => object + !REF: /m1/test/object + !REF: /m1/base/p + !REF: /m1/forward/n + object%p%n = 666 + end subroutine +end module