[flang] Fix crashes in ResolveOmpObject and RewriteOpenMPLoopConstruct
authorTim Keith <tkeith@nvidia.com>
Thu, 14 Nov 2019 23:01:20 +0000 (15:01 -0800)
committerTim Keith <tkeith@nvidia.com>
Thu, 14 Nov 2019 23:01:20 +0000 (15:01 -0800)
commitb5c7193769cc2eaef6f0084e95624583806513d2
treee0ff295ecaa8fc32ad00163b88d9c9b1172ab0cd
parent3efb332af2a6b0ded9ff8c318cf9f845c5ffaefc
[flang] Fix crashes in ResolveOmpObject and RewriteOpenMPLoopConstruct

Using debug build of f18, `omp-resolve01.f90` sometimes crashed in
`OmpVisitor::ResolveOmpObject`. This was because when the designator was
analyzed it could be rewritten from an `ArrayElement` to a `Substring`.
That made the reference to the `Name` inside the designator no longer
valid so the crash happened when it was referenced later. The fix is to
return when the substring is detected so the name is not referenced.

Also, the name returned from `ResolveDesignator` can but null so it must
be checked.

The crash in `RewriteOpenMPLoopConstruct` happened intermittently on
`omp-loop-association.f90`. It happened when the DO construct was the
last element of the block. In that case `block.erase()` returns an
iterator pointing to `block.end()` which must not be dereferenced.

Original-commit: flang-compiler/f18@3299972d047696aca28212131ab4644a3966fc8b
Reviewed-on: https://github.com/flang-compiler/f18/pull/824
flang/lib/semantics/canonicalize-omp.cc
flang/lib/semantics/resolve-names.cc