[Bug fortran/108693] Update shared character array inside OpenMP critical section causes internal compiler error

2023-02-15 Thread burnus at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108693

Tobias Burnus  changed:

   What|Removed |Added

 Depends on||97977
 CC||burnus at gcc dot gnu.org

--- Comment #2 from Tobias Burnus  ---
Pre-remark: Allocatable scalar character variables consists of a pointer to the
actual data ('mask') and a hidden variable ('.mask') which contains the string
length.

 * * *

lower_omp_taskreg calls lower_rec_input_clauses which has:


6199  x = build_outer_var_ref (var, ctx);

(gdb) p debug(x)
.omp_data_i->mask


So far so good, but when calling

6329   x = lang_hooks.decls.omp_clause_copy_ctor
6330   (c, unshare_expr (new_var), x);

But that causes too much code to be generated and that code
also has an error_mark_node:


(gdb) p debug(x)
{
  void * D.4350;

  if ((void *) .omp_data_i->mask != 0B)
{
  mask = (character(kind=1)[1:D.4340] *) .omp_data_i->mask;
  D.4350 = __builtin_malloc (MAX_EXPR <(unsigned long) SAVE_EXPR
<(sizetype) NON_LVALUE_EXPR  error >, 1>);

* * *

I think one issue is that there is no 'shared(.mask)' to make the string
available. — We had a similar discussion elsewhere. -> PR97977.

I vaguely recall some IRC discussion about this that the solution is
non-trivial in general (for implicit mapping). However, here we have an
explicit 'share(mask)', where adding an implicit 'share(.mask)' could be
easier.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97977
[Bug 97977] Fortran deferred length strings incompatible with OMP

[Bug fortran/108693] Update shared character array inside OpenMP critical section causes internal compiler error

2023-02-07 Thread anlauf at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108693

anlauf at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Keywords||ice-on-valid-code
 Ever confirmed|0   |1
   Last reconfirmed||2023-02-07

--- Comment #1 from anlauf at gcc dot gnu.org ---
The code has a simple bug, as it violates array bounds as threads are
counted starting from 0, not 1.  This is fixed by replacing

  thread_id = OMP_GET_THREAD_NUM()

by

  thread_id = OMP_GET_THREAD_NUM() + 1

The ICE seems to occur only for deferred character length variables.
A small modification to use an array of character(len=1) seems to work.