https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97084

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Trying with:
  character(len=:), allocatable :: temp_string
  character(len=N) :: temp_string2
(using one or the other)

Both get set to 'shared' initially; in omp-low.c' scan_sharing_clauses:
        case OMP_CLAUSE_SHARED:
...
          by_ref = use_pointer_for_field (decl, NULL);

As "temp_string2" is a string/array, by_ref is true as:
  if (AGGREGATE_TYPE_P (TREE_TYPE (decl))
      || TYPE_ATOMIC (TREE_TYPE (decl)))
    return true;

By contrast, temp_string is a pointer to a string/array, has 'by_ref = false'
and, hence,
          /* We don't need to copy const scalar vars back.  */
          OMP_CLAUSE_SET_CODE (c, OMP_CLAUSE_FIRSTPRIVATE);

→ This statement is definitely wrong as it is not a scalar (in the OpenMP
sense) and it is also not 'const' and it should be addressable.

The question is why not any of the many items in the if condition following
line 1143's "by_ref =" is true.


Back to the ICE: Then, via lower_rec_input_clauses, gfc_omp_clause_copy_ctor is
called and we end up at:
  gfc_start_block (&block);
  gfc_init_block (&cond_block);
  gfc_add_modify (&cond_block, dest, src));

"lhs = rhs" is:
  temp_string = .omp_data_s.1.temp_string

where both lhs and rhs are pointers to an array; in the dump both types look
identical but are different pointer/array types. Thus, the following assert
fails in gfc_add_modify_loc:

  gcc_checking_assert (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2)
                       || AGGREGATE_TYPE_P (TREE_TYPE (lhs)));

Reply via email to