[flang-commits] [PATCH] D127429: [flang] Fix crash on USE error
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Jun 9 12:14:41 PDT 2022
klausler created this revision.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D127429
Files:
flang/lib/Semantics/resolve-names.cpp
Index: flang/lib/Semantics/resolve-names.cpp
===================================================================
--- flang/lib/Semantics/resolve-names.cpp
+++ flang/lib/Semantics/resolve-names.cpp
@@ -2698,15 +2698,23 @@
// 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 @@
}
}
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127429.435638.patch
Type: text/x-patch
Size: 1672 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220609/ac71c234/attachment.bin>
More information about the flang-commits
mailing list