From 7eec2f2f218cd23a055dc81295c930a0674f5797 Mon Sep 17 00:00:00 2001 From: Leandro Lupori Date: Thu, 2 Feb 2023 20:28:32 +0000 Subject: [PATCH] [flang] Avoid infinite recursion in common block check Don't call CheckCommonBlockDerivedType() recursively if the derived type symbol is the same symbol that is already being processed. This can happen when a component is a pointer of the same type as its parent component, for instance. Fixes #60230 Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D143211 --- flang/lib/Semantics/resolve-names.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 76dfb52..3772c6b 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -5768,7 +5768,14 @@ void DeclarationVisitor::CheckCommonBlockDerivedType( if (details) { if (const auto *type{details->type()}) { if (const auto *derived{type->AsDerived()}) { - CheckCommonBlockDerivedType(name, derived->typeSymbol()); + const Symbol &derivedTypeSymbol{derived->typeSymbol()}; + // Don't call this member function recursively if the derived type + // symbol is the same symbol that is already being processed. + // This can happen when a component is a pointer of the same type + // as its parent component, for instance. + if (derivedTypeSymbol != typeSymbol) { + CheckCommonBlockDerivedType(name, derivedTypeSymbol); + } } } } -- 2.7.4