[flang] Don't add a source range to a type instantiation's scope
authorPeter Klausler <pklausler@nvidia.com>
Wed, 15 Feb 2023 19:11:54 +0000 (11:11 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Wed, 15 Feb 2023 20:05:12 +0000 (12:05 -0800)
A type instantiation's scope doesn't require a source range, as we don't
need/want it to be the result of SemanticsContext::FindScope(), and
adding the original type's source range to the scope of one of its
instantiations has the side effect of expanding the source range of
all of its parents to include the original type definition, which
breaks FindScope() for any scope including a type instantiation.

Differential Revision: https://reviews.llvm.org/D144129

flang/lib/Semantics/type.cpp

index bc8667e..afc2baa 100644 (file)
@@ -368,7 +368,6 @@ void DerivedTypeSpec::Instantiate(Scope &containingScope) {
   }
   // Instantiate every non-parameter symbol from the original derived
   // type's scope into the new instance.
-  newScope.AddSourceRange(typeScope.sourceRange());
   auto restorer2{foldingContext.messages().SetContext(contextMessage)};
   if (PlumbPDTInstantiationDepth(&containingScope) > 100) {
     foldingContext.messages().Say(