[flang] Avoid infinite recursion in common block check
authorLeandro Lupori <leandro.lupori@linaro.org>
Thu, 2 Feb 2023 20:28:32 +0000 (20:28 +0000)
committerLeandro Lupori <leandro.lupori@linaro.org>
Mon, 13 Feb 2023 13:48:32 +0000 (10:48 -0300)
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

index 76dfb52..3772c6b 100644 (file)
@@ -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);
+            }
           }
         }
       }