* [Patch] Fortran/OpenMP: Avoid ICE for invalid char array in omp atomic [PR104329]
@ 2022-02-04 11:39 Tobias Burnus
2022-02-09 19:27 ` Jakub Jelinek
0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2022-02-04 11:39 UTC (permalink / raw)
To: gcc-patches, fortran
[-- Attachment #1: Type: text/plain, Size: 790 bytes --]
Already during parsing, the allocatable character array assignment
x = (x)
is converted to two gfc_codes with EXEC_ASSIGN, namely:
ASSIGN z1:_F.DA0(FULL) (parens z1:x(FULL))
ASSIGN z1:x(FULL) z1:_F.DA0(FULL)
But the current code expects only one gfc_code - as parse.c does some
checks, that's unexpected for resolution and currently is checked with
an gcc_assert.
Solution: I now defer the gfc_assert until after diagnosing the arguments.
OK for mainline (only affected version)?
Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: omp-char-arr-fix.diff --]
[-- Type: text/x-patch, Size: 2811 bytes --]
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.
gcc/fortran/openmp.cc | 11 ++++++++---
gcc/testsuite/gfortran.dg/gomp/atomic-28.f90 | 28 ++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 38c67e1f640..b1c065d9e8b 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -7687,7 +7687,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;
@@ -7825,7 +7825,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
{
@@ -7833,7 +7834,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)
@@ -7886,6 +7888,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 00000000000..91e29c96d45
--- /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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch] Fortran/OpenMP: Avoid ICE for invalid char array in omp atomic [PR104329]
2022-02-04 11:39 [Patch] Fortran/OpenMP: Avoid ICE for invalid char array in omp atomic [PR104329] Tobias Burnus
@ 2022-02-09 19:27 ` Jakub Jelinek
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2022-02-09 19:27 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, fortran
On Fri, Feb 04, 2022 at 12:39:53PM +0100, Tobias Burnus wrote:
> Already during parsing, the allocatable character array assignment
> x = (x)
>
> is converted to two gfc_codes with EXEC_ASSIGN, namely:
>
> ASSIGN z1:_F.DA0(FULL) (parens z1:x(FULL))
> ASSIGN z1:x(FULL) z1:_F.DA0(FULL)
>
> But the current code expects only one gfc_code - as parse.c does some
> checks, that's unexpected for resolution and currently is checked with
> an gcc_assert.
>
> Solution: I now defer the gfc_assert until after diagnosing the arguments.
>
> OK for mainline (only affected version)?
>
> Tobias
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
> 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.
>
> gcc/fortran/openmp.cc | 11 ++++++++---
> gcc/testsuite/gfortran.dg/gomp/atomic-28.f90 | 28 ++++++++++++++++++++++++++++
> 2 files changed, 36 insertions(+), 3 deletions(-)
Ok, thanks.
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-02-09 19:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 11:39 [Patch] Fortran/OpenMP: Avoid ICE for invalid char array in omp atomic [PR104329] Tobias Burnus
2022-02-09 19:27 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).