aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-02-03 09:01:07 +0100
committerJakub Jelinek <jakub@redhat.com>2022-02-03 09:01:07 +0100
commit54d21dd5b5c5c5539505b3e037cdecb3b0ab3918 (patch)
treee08ec2f11ac4a43808929b103d773837c5c70d60 /gcc/fortran
parent501c4ee9fad68716497db4d96b63b801cc57b4a1 (diff)
downloadgcc-54d21dd5b5c5c5539505b3e037cdecb3b0ab3918.zip
gcc-54d21dd5b5c5c5539505b3e037cdecb3b0ab3918.tar.gz
gcc-54d21dd5b5c5c5539505b3e037cdecb3b0ab3918.tar.bz2
openmp, fortran: Improve !$omp atomic checks [PR104328]
The testcase shows some cases that weren't verified and we ICE on invalid because of that. One problem is that unlike before, we weren't checking if some expression is EXPR_VARIABLE with non-NULL symtree in the case where there was a conversion around it. The other two issues is that we check that in an IF ->block is non-NULL and then immediately dereference ->block->next->op, but on invalid code with no statements in the then clause ->block->next might be NULL. 2022-02-02 Jakub Jelinek <jakub@redhat.com> PR fortran/104328 * openmp.cc (is_scalar_intrinsic_expr): If must_be_var && conv_ok and expr is conversion, verify it is a conversion from EXPR_VARIABLE with non-NULL symtree. Check ->block->next before dereferencing it. * gfortran.dg/gomp/atomic-27.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/openmp.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 073e5a1..38c67e1 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7660,9 +7660,16 @@ static bool
is_scalar_intrinsic_expr (gfc_expr *expr, bool must_be_var, bool conv_ok)
{
if (must_be_var
- && (expr->expr_type != EXPR_VARIABLE || !expr->symtree)
- && (!conv_ok || !is_conversion (expr, true, true)))
- return false;
+ && (expr->expr_type != EXPR_VARIABLE || !expr->symtree))
+ {
+ if (!conv_ok)
+ return false;
+ gfc_expr *conv = is_conversion (expr, true, true);
+ if (!conv)
+ return false;
+ if (conv->expr_type != EXPR_VARIABLE || !conv->symtree)
+ return false;
+ }
return (expr->rank == 0
&& !gfc_is_coindexed (expr)
&& (expr->ts.type == BT_INTEGER
@@ -7705,6 +7712,7 @@ resolve_omp_atomic (gfc_code *code)
if (next->op == EXEC_IF
&& next->block
&& next->block->op == EXEC_IF
+ && next->block->next
&& next->block->next->op == EXEC_ASSIGN)
{
comp_cond = next->block->expr1;
@@ -7757,6 +7765,7 @@ resolve_omp_atomic (gfc_code *code)
if (code->op == EXEC_IF
&& code->block
&& code->block->op == EXEC_IF
+ && code->block->next
&& code->block->next->op == EXEC_ASSIGN)
{
comp_cond = code->block->expr1;