[PATCH] D81101: [flang] Fix crash on erroneous expressions
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 08:12:23 PDT 2020
PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
PeteSteinfeld added a project: Flang.
Herald added a reviewer: jdoerfert.
If you create an expression with parse errors, the `parser::Expr.typedExpr`
will be empty, which causes a compiler crash. The crash is caused by the
check in check-do-forall.cpp that scans all expresssions to see if `DO`
variables are being modified. I fixed it by testing to see if `typedExpr`
actually exists before checking to see if it modifies a `DO` variable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D81101
Files:
flang/lib/Semantics/check-do-forall.cpp
flang/test/Semantics/resolve91.f90
Index: flang/test/Semantics/resolve91.f90
===================================================================
--- flang/test/Semantics/resolve91.f90
+++ flang/test/Semantics/resolve91.f90
@@ -44,3 +44,15 @@
real, dimension(:), pointer :: realArray => localArray
end type
end module m4
+
+module m6
+ integer, dimension(3) :: iarray
+ !ERROR: Derived type 'ubound' not found
+ character(len=ubound(iarray)(1)) :: first
+end module m6
+
+module m7
+ integer, dimension(2) :: iarray
+ !ERROR: Derived type 'ubound' not found
+ integer :: ivar = ubound(iarray)(1)
+end module m7
Index: flang/lib/Semantics/check-do-forall.cpp
===================================================================
--- flang/lib/Semantics/check-do-forall.cpp
+++ flang/lib/Semantics/check-do-forall.cpp
@@ -1045,10 +1045,12 @@
template ActualArgumentSet CollectActualArguments(const SomeExpr &);
void DoForallChecker::Leave(const parser::Expr &parsedExpr) {
- if (const SomeExpr * expr{GetExpr(parsedExpr)}) {
- ActualArgumentSet argSet{CollectActualArguments(*expr)};
- for (const evaluate::ActualArgumentRef &argRef : argSet) {
- CheckIfArgIsDoVar(*argRef, parsedExpr.source, context_);
+ if (parsedExpr.typedExpr) { // typedExpr is empty on expressions with errors
+ if (const SomeExpr * expr{GetExpr(parsedExpr)}) {
+ ActualArgumentSet argSet{CollectActualArguments(*expr)};
+ for (const evaluate::ActualArgumentRef &argRef : argSet) {
+ CheckIfArgIsDoVar(*argRef, parsedExpr.source, context_);
+ }
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81101.268206.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200603/f57ff4f8/attachment.bin>
More information about the llvm-commits
mailing list