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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So looking into tree-nested.cc I see this:
  /* The original user label may also be use for a normal goto, therefore
     we must create a new label that will actually receive the abnormal
     control transfer.  This new label will be marked LABEL_NONLOCAL; this
     mark will trigger proper behavior in the cfg, as well as cause the
     (hairy target-specific) non-local goto receiver code to be generated
     when we expand rtl.  Enter this association into var_map so that we
     can insert the new label into the IL during a second pass.  */

So maybe during gimplification we should clear LABEL_NONLOCAL.

Or better yet don't set DECL_NONLOCAL in the C front-end.

(In reply to Andrew Pinski from comment #4)
> (In reply to Andrew Pinski from comment #3)
> > I am suspecting r16-3747-gafa74d37e8170d exposed this.

So build_external_ref was not called on a label decl from a goto statement:
              tree name = c_parser_peek_token (parser)->value;
              if (parser->omp_metadirective_state)
                name = mangle_metadirective_region_label (parser, name);
              stmt = c_finish_goto_label (loc, name);
              c_parser_consume_token (parser);

Likewise for &&:
```
      /* Refer to the address of a label as a pointer.  */
      c_parser_consume_token (parser);
      if (c_parser_next_token_is (parser, CPP_NAME))
        {
          ret.value = finish_label_address_expr
            (c_parser_peek_token (parser)->value, op_loc);
          set_c_expr_source_range (&ret, op_loc,
                                   c_parser_peek_token (parser)->get_finish
());
          c_parser_consume_token (parser);
        }
      else
        {
          c_parser_error (parser, "expected identifier");
          ret.set_error ();
        }
```

So I think the fix is in mark_decl_used:
```
  if (nonloc_p)
    DECL_NONLOCAL (ref) = 1;
```
Should be:
```
  /* Label decls are handled by the un-nesting code in tree-nested.cc. */
  if (nonloc_p && TREE_CODE (ref) != LABEL_DECL)
    DECL_NONLOCAL (ref) = 1;
```

Reply via email to