Hi Jakub!

Stumbled over this while reviewing Julian's "Factor out duplicate code in
gimplify_scan_omp_clauses":

On 2015-07-31T18:16:10+0200, Jakub Jelinek <ja...@redhat.com> wrote:
> This patch is the start of implementation of struct element mapping.

Not quite the same, but similar code is still present in GCC trunk.

> --- gcc/gimplify.c.jj 2015-07-31 16:55:01.482411392 +0200
> +++ gcc/gimplify.c    2015-07-31 16:57:22.307320290 +0200

> +               tree offset;

Here we define 'offset'...

> +               HOST_WIDE_INT bitsize, bitpos;
> +               machine_mode mode;
> +               int unsignedp, volatilep = 0;
> +               tree base
> +                 = get_inner_reference (OMP_CLAUSE_DECL (c), &bitsize,
> +                                        &bitpos, &offset, &mode, &unsignedp,
> +                                        &volatilep, false);

..., which here gets writte to...

> +               gcc_assert (base == decl
> +                           && (offset == NULL_TREE
> +                               || TREE_CODE (offset) == INTEGER_CST));

..., and here gets checked...

> +
> +               splay_tree_node n
> +                 = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
> +               if (n == NULL || (n->value & GOVD_MAP) == 0)
> +                 {
> +                   [...]
> +                 }
> +               else
> +                 {
> +                   tree *osc = struct_map_to_clause->get (decl), *sc;
> +                   if (OMP_CLAUSE_MAP_KIND (c) & GOMP_MAP_FLAG_ALWAYS)
> +                     n->value |= GOVD_SEEN;
> +                   offset_int o1, o2;
> +                   if (offset)
> +                     o1 = wi::to_offset (offset);

..., and here used.

> +                   else
> +                     o1 = 0;
> +                   if (bitpos)
> +                     o1 = o1 + bitpos / BITS_PER_UNIT;
> +                   for (sc = &OMP_CLAUSE_CHAIN (*osc); *sc != c;
> +                        sc = &OMP_CLAUSE_CHAIN (*sc))
> +                     if (TREE_CODE (OMP_CLAUSE_DECL (*sc)) != COMPONENT_REF)
> +                       break;
> +                     else
> +                       {
> +                         tree offset2;

Here we define 'offset2'...

> +                         HOST_WIDE_INT bitsize2, bitpos2;
> +                         base = get_inner_reference (OMP_CLAUSE_DECL (*sc),
> +                                                     &bitsize2, &bitpos2,
> +                                                     &offset2, &mode,
> +                                                     &unsignedp, &volatilep,
> +                                                     false);

..., which here gets writte to...

> +                         if (base != decl)
> +                           break;
> +                         gcc_assert (offset == NULL_TREE
> +                                     || TREE_CODE (offset) == INTEGER_CST);

..., but here we again check 'offset', not 'offset2'...

> +                         tree d1 = OMP_CLAUSE_DECL (*sc);
> +                         tree d2 = OMP_CLAUSE_DECL (c);
> +                         while (TREE_CODE (d1) == COMPONENT_REF)
> +                           if (TREE_CODE (d2) == COMPONENT_REF
> +                               && TREE_OPERAND (d1, 1)
> +                                  == TREE_OPERAND (d2, 1))
> +                             {
> +                               d1 = TREE_OPERAND (d1, 0);
> +                               d2 = TREE_OPERAND (d2, 0);
> +                             }
> +                           else
> +                             break;
> +                         if (d1 == d2)
> +                           {
> +                             error_at (OMP_CLAUSE_LOCATION (c),
> +                                       "%qE appears more than once in map "
> +                                       "clauses", OMP_CLAUSE_DECL (c));
> +                             remove = true;
> +                             break;
> +                           }
> +                         if (offset2)
> +                           o2 = wi::to_offset (offset2);

.., but here again we use 'offset2'.

> +                         else
> +                           o2 = 0;
> +                         if (bitpos2)
> +                           o2 = o2 + bitpos2 / BITS_PER_UNIT;
> +                         if (wi::ltu_p (o1, o2)
> +                             || (wi::eq_p (o1, o2) && bitpos < bitpos2))
> +                           break;
> +                       }
> +                   if (!remove)
> +                     OMP_CLAUSE_SIZE (*osc)
> +                       = size_binop (PLUS_EXPR, OMP_CLAUSE_SIZE (*osc),
> +                                     size_one_node);
> +                   if (!remove && *sc != c)
> +                     {
> +                       *list_p = OMP_CLAUSE_CHAIN (c);
> +                       OMP_CLAUSE_CHAIN (c) = *sc;
> +                       *sc = c;
> +                       continue;
> +                     }
> +                 }
> +             }
>             break;
>           }
>         flags = GOVD_MAP | GOVD_EXPLICIT;

Should the second highlighted 'gcc_assert' be changed as follows,
suitably adapted for current GCC trunk, of course?  (Not yet tested.)  If
approving such a patch, please respond with "Reviewed-by: NAME <EMAIL>"
so that your effort will be recorded in the commit log, see
<https://gcc.gnu.org/wiki/Reviewed-by>.

    -                       gcc_assert (offset == NULL_TREE
    -                                   || TREE_CODE (offset) == INTEGER_CST);
    +                       gcc_assert (offset2 == NULL_TREE
    +                                   || TREE_CODE (offset2) == INTEGER_CST);


Grüße
 Thomas

Attachment: signature.asc
Description: PGP signature

Reply via email to