[flang] Catch (and fix) attempts to create an invalid source range for a Scope
authorPeter Klausler <pklausler@nvidia.com>
Thu, 11 May 2023 21:28:58 +0000 (14:28 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Wed, 17 May 2023 13:20:57 +0000 (06:20 -0700)
commitaf3c7241df9e274d9944f41e8c174b7580c656dd
tree775a16822e54553fe4d486e7c54d287d43f25625
parent6170bb895917e69793fe2125bb79d2991183492b
[flang] Catch (and fix) attempts to create an invalid source range for a Scope

When Scope::AddSourceRange() is called to extend the scope's source range to
include another snippet from a cooked character stream, add a check to ensure
that the new range is part of the same cooked character stream as the rest
of the scope.

And fix the bug that was causing such invalid source ranges to be created:
a submodule's Scope is a children of its parent's in the Scope tree, but
it may or may not be part of the same source file, and it is certainly
not enclosed in the parent's source range.  So don't propagate Scope
source range expansion from a submodule to its parent.

Differential Revision: https://reviews.llvm.org/D150714
flang/include/flang/Semantics/scope.h
flang/lib/Semantics/scope.cpp