[flang-commits] [PATCH] D153792: [flang] Avoid crash in error recovery
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Jun 26 11:01:51 PDT 2023
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
When a PASS() clause names a nonexistent dummy argument, don't crash
later in expression semantics.
Fixes https://github.com/llvm/llvm-project/issues/63487.
https://reviews.llvm.org/D153792
Files:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/resolve52.f90
Index: flang/test/Semantics/resolve52.f90
===================================================================
--- flang/test/Semantics/resolve52.f90
+++ flang/test/Semantics/resolve52.f90
@@ -50,6 +50,10 @@
subroutine s(x)
class(t) :: x
end
+ subroutine test
+ type(t) x
+ call x%s ! ensure no crash in expr semantics
+ end
end
module m4
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -2116,7 +2116,7 @@
proc.details());
}
-static int GetPassIndex(const Symbol &proc) {
+static std::optional<int> GetPassIndex(const Symbol &proc) {
CHECK(!proc.attrs().test(semantics::Attr::NOPASS));
std::optional<parser::CharBlock> passName{GetPassName(proc)};
const auto *interface {
@@ -2133,7 +2133,7 @@
}
++index;
}
- DIE("PASS argument name not in dummy argument list");
+ return std::nullopt;
}
// Injects an expression into an actual argument list as the "passed object"
@@ -2146,10 +2146,13 @@
if (component.attrs().test(semantics::Attr::NOPASS)) {
return;
}
- int passIndex{GetPassIndex(component)};
+ std::optional<int> passIndex{GetPassIndex(component)};
+ if (!passIndex) {
+ return; // error recovery
+ }
auto iter{actuals.begin()};
int at{0};
- while (iter < actuals.end() && at < passIndex) {
+ while (iter < actuals.end() && at < *passIndex) {
if (*iter && (*iter)->keyword()) {
iter = actuals.end();
break;
@@ -4296,7 +4299,7 @@
if (generic) {
ExpressionAnalyzer::AdjustActuals adjustment{
[&](const Symbol &proc, ActualArguments &) {
- return passIndex == GetPassIndex(proc);
+ return passIndex == GetPassIndex(proc).value_or(-1);
}};
auto pair{
context_.ResolveGeneric(*generic, actuals_, adjustment, isSubroutine)};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153792.534655.patch
Type: text/x-patch
Size: 1929 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230626/2561e2d8/attachment.bin>
More information about the flang-commits
mailing list