[flang-commits] [flang] 8eebf46 - [flang] Fix crash on USE error
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Jun 13 16:20:38 PDT 2022
Author: Peter Klausler
Date: 2022-06-13T16:15:47-07:00
New Revision: 8eebf4696454378deb4b6dcbd5a17227eeb3677c
URL: https://github.com/llvm/llvm-project/commit/8eebf4696454378deb4b6dcbd5a17227eeb3677c
DIFF: https://github.com/llvm/llvm-project/commit/8eebf4696454378deb4b6dcbd5a17227eeb3677c.diff
LOG: [flang] Fix crash on USE error
Handle the case of a non-generic procedure that is USE associated
into a scope that has a generic interface of the same name with an
appropriate error rather than crashing.
Differential Revision: https://reviews.llvm.org/D127429
Added:
Modified:
flang/lib/Semantics/resolve-names.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index a1a3e53801b25..bdd8416427bca 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2698,15 +2698,23 @@ ModuleVisitor::SymbolRename ModuleVisitor::AddUse(
// symbol must be either a Use or a Generic formed by merging two uses.
// Convert it to a UseError with this additional location.
-static void ConvertToUseError(
+static bool ConvertToUseError(
Symbol &symbol, const SourceName &location, const Scope &module) {
const auto *useDetails{symbol.detailsIf<UseDetails>()};
if (!useDetails) {
- auto &genericDetails{symbol.get<GenericDetails>()};
- useDetails = &genericDetails.uses().at(0)->get<UseDetails>();
+ if (auto *genericDetails{symbol.detailsIf<GenericDetails>()}) {
+ if (!genericDetails->uses().empty()) {
+ useDetails = &genericDetails->uses().at(0)->get<UseDetails>();
+ }
+ }
+ }
+ if (useDetails) {
+ symbol.set_details(
+ UseErrorDetails{*useDetails}.add_occurrence(location, module));
+ return true;
+ } else {
+ return false;
}
- symbol.set_details(
- UseErrorDetails{*useDetails}.add_occurrence(location, module));
}
// If a symbol has previously been USE-associated and did not appear in a USE
@@ -2807,9 +2815,7 @@ void ModuleVisitor::DoAddUse(SourceName location, SourceName localName,
}
}
if (!combine) {
- if (localSymbol.has<UseDetails>() || localSymbol.has<GenericDetails>()) {
- ConvertToUseError(localSymbol, location, *useModuleScope_);
- } else {
+ if (!ConvertToUseError(localSymbol, location, *useModuleScope_)) {
Say(location,
"Cannot use-associate '%s'; it is already declared in this scope"_err_en_US,
localName)
More information about the flang-commits
mailing list