aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <tobias@codesourcery.com>2022-02-10 09:30:19 +0100
committerTobias Burnus <tobias@codesourcery.com>2022-02-10 09:30:19 +0100
commit9694f6121982668285a21020b55b44c3099f7042 (patch)
tree97f9d3897df34ad47d7dad328c2b1376c760f96a
parent6d98e83b2c919bd9fba2c61333d613bafc37357f (diff)
downloadgcc-9694f6121982668285a21020b55b44c3099f7042.zip
gcc-9694f6121982668285a21020b55b44c3099f7042.tar.gz
gcc-9694f6121982668285a21020b55b44c3099f7042.tar.bz2
Fortran/OpenMP: Avoid ICE for invalid char array in omp atomic [PR104329]
PR fortran/104329 gcc/fortran/ChangeLog: * openmp.cc (resolve_omp_atomic): Defer extra-code assert after other diagnostics. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/atomic-28.f90: New test.
-rw-r--r--gcc/fortran/openmp.cc11
-rw-r--r--gcc/testsuite/gfortran.dg/gomp/atomic-28.f9028
2 files changed, 36 insertions, 3 deletions
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 33b372f..19142c4 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7695,7 +7695,7 @@ resolve_omp_atomic (gfc_code *code)
gfc_omp_atomic_op aop
= (gfc_omp_atomic_op) (atomic_code->ext.omp_clauses->atomic_op
& GFC_OMP_ATOMIC_MASK);
- gfc_code *stmt = NULL, *capture_stmt = NULL;
+ gfc_code *stmt = NULL, *capture_stmt = NULL, *tailing_stmt = NULL;
gfc_expr *comp_cond = NULL;
locus *loc = NULL;
@@ -7833,7 +7833,8 @@ resolve_omp_atomic (gfc_code *code)
stmt = code;
capture_stmt = code->next;
}
- gcc_assert (!code->next->next);
+ /* Shall be NULL but can happen for invalid code. */
+ tailing_stmt = code->next->next;
}
else
{
@@ -7841,7 +7842,8 @@ resolve_omp_atomic (gfc_code *code)
stmt = code;
if (!atomic_code->ext.omp_clauses->compare && stmt->op != EXEC_ASSIGN)
goto unexpected;
- gcc_assert (!code->next);
+ /* Shall be NULL but can happen for invalid code. */
+ tailing_stmt = code->next;
}
if (comp_cond)
@@ -7894,6 +7896,9 @@ resolve_omp_atomic (gfc_code *code)
return;
}
+ /* Should be diagnosed above already. */
+ gcc_assert (tailing_stmt == NULL);
+
var = stmt->expr1->symtree->n.sym;
stmt_expr2 = is_conversion (stmt->expr2, true, true);
if (stmt_expr2 == NULL)
diff --git a/gcc/testsuite/gfortran.dg/gomp/atomic-28.f90 b/gcc/testsuite/gfortran.dg/gomp/atomic-28.f90
new file mode 100644
index 0000000..91e29c9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/atomic-28.f90
@@ -0,0 +1,28 @@
+! { dg-do compile }
+!
+! PR fortran/104329
+!
+! Contributed by G. Steinmetz
+!
+subroutine z1
+ character(:), allocatable :: x(:)
+ x = ['123']
+ !$omp atomic update
+ x = (x) ! { dg-error "OMP ATOMIC statement must set a scalar variable of intrinsic type" }
+end
+
+subroutine z2
+ character(:), allocatable :: x(:)
+ x = ['123']
+ !$omp atomic update
+ x = 'a' // x // 'e' ! { dg-error "OMP ATOMIC statement must set a scalar variable of intrinsic type" }
+end
+
+
+subroutine z3
+ character(:), allocatable :: x(:)
+ x = ['123']
+ !$omp atomic capture
+ x = 'a' // x // 'e' ! { dg-error "OMP ATOMIC statement must set a scalar variable of intrinsic type" }
+ x = x
+end