[flang] Fix forward ref to derived type when symbol exists

Fix some comments

Original-commit: flang-compiler/f18@3274ed9545
Reviewed-on: https://github.com/flang-compiler/f18/pull/852
This commit is contained in:
peter klausler 2019-12-03 10:21:37 -08:00
parent 31624ae53f
commit 9cf3c638ec
3 changed files with 41 additions and 10 deletions

View File

@ -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};
};

View File

@ -4429,15 +4429,16 @@ void DeclarationVisitor::SetType(
std::optional<DerivedTypeSpec> DeclarationVisitor::ResolveDerivedType(
const parser::Name &name) {
const Symbol *symbol{FindSymbol(name)};
if (!symbol) {
Symbol *symbol{FindSymbol(name)};
if (!symbol || symbol->has<UnknownDetails>()) {
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();
}
}

View File

@ -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