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

            Bug ID: 116483
           Summary: RFE: a notion for asm goto to indicate all labels in
                    the function may be jumped to
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xry111 at gcc dot gnu.org
  Target Milestone: ---

Hi,

We currently have some code using computed goto:

goto *table[index];

But for satisfying some tools analyzing the generated machine code, we need to
encode the address of the jump instruction and the address of the table in a
special section, something like.

asm volatile (
  "1:"
  "jr %0\n\t"
  ".pushsection .metainfo\n\t"
  "  .8byte 1b\n\t"
  "  .8byte %1\n\t"
  ".popsection"
  : "r"(table[index]), "r"(table)
);

But this won't work: the compiler does not know this asm block ever jumps.  To
make it aware of the jump, we have to do:

asm goto (
  "1:"
  "jr %0\n\t"
  ".pushsection .metainfo\n\t"
  "  .8byte 1b\n\t"
  "  .8byte %1\n\t"
  ".popsection"
  : "r"(table[index]), "r"(table)
  :
  :
  : label1, label2, label3, label4, label5 /* ... */ 
);

Unfortunately this is nasty with a hundred of labels.  So IMO it may be useful
to add a notion to indicate this asm goto block may jump into any label in the
same function, maybe like...

asm goto (
  "1:"
  "jr %0\n\t"
  ".pushsection .metainfo\n\t"
  "  .8byte 1b\n\t"
  "  .8byte %1\n\t"
  ".popsection"
  : "r"(table[index]), "r"(table)
  :
  :
  : "anywhere"
);

?

Reply via email to