openmp: Avoid ICEs due to orphaned labels in OpenMP regions [PR99322]
authorJakub Jelinek <jakub@redhat.com>
Fri, 5 Mar 2021 20:52:35 +0000 (21:52 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 5 Mar 2021 20:59:25 +0000 (21:59 +0100)
commita3ad6489d38982434faef3bc5f33e3c28c5f7c74
treed2f291a88c785acbe74821873330542172c3001c
parent9e64dd6b3f6706de571c6ed3c4b7a8c8b67f22b7
openmp: Avoid ICEs due to orphaned labels in OpenMP regions [PR99322]

When performing cfg cleanup at the end of cfg pass, if there are any OpenMP
regions and some basic blocks are unreachable and contain forced labels,
remove_bb moves the labels to previous bb, but if the two bb belong to different
OpenMP regions, that means it will end up in a different function from where
it was assumed to be and checked e.g. during gimplification or OpenMP region
SESE checking.

The following patch will place the labels to some bb from the right OpenMP
region if the previous bb is not that.  I think it should happen very rarely,
normally the bbs from each OpenMP region should be from the before-cfg pass
adjacent and the problems will usually be only if the OpenMP regions are
no-return, so I hope it isn't fatal that it searches through all bbs on the miss.
If it turns out to be a problem, it can always lazily create some better data
structure and maintain it through bb removals when it reaches that case the
first time.

2021-03-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/99322
* tree-cfg.c (bb_to_omp_idx): New variable.
(execute_build_cfg): Release the bb_to_omp_idx vector after
cleanup_tree_cfg returns.
(handle_abnormal_edges): Remove bb_to_omp_idx argument, adjust
for bb_to_omp_idx being a vec<int> instead of pointer to array
of ints.
(make_edges): Remove bb_to_omp_idx local variable, don't pass
it to handle_abnormal_edges, adjust for bb_to_omp_idx being a
vec<int> instead of pointer to array of ints and don't free/release
it at the end.
(remove_bb): When removing a bb and placing forced label somewhere
else, ensure it is put into the same OpenMP region during cfg
pass if possible or to entry successor as fallback.  Unregister
bb from bb_to_omp_idx.

* c-c++-common/gomp/pr99322.c: New test.
gcc/testsuite/c-c++-common/gomp/pr99322.c [new file with mode: 0644]
gcc/tree-cfg.c