[Bug middle-end/119537] assume with statement expression and ("non-local") label

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Mar 31 13:13:00 GMT 2025


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems the C FE doesn't diagnose this kind of stuff at all and C++ FE just
warns:
volatile int v;

void
foo (void)
{
  __label__ x;
  goto *&&x;
  int b = (__extension__ ({ x: ++v; 0; }));
  (void) b;
}

void
bar (void)
{
  __label__ x;
  goto *&&x;
  #pragma omp parallel
  {
    x:;
    ++v;
  }
}

void
baz (void)
{
  __label__ x;
  #pragma omp parallel
  goto *&&x;
  x:;
}

All those are invalid cases, jumping into a statement expression is invalid,
jumping into OpenMP structured block or out of it as well.
But with computed goto it isn't necessarily proven that it is invalid, we can
just take address of the label somewhere (including inside of the statement
expression or OpenMP region), pass the address back and then goto to that with
whether it is a violation hidden e.g. through some non-visible function.

E.g.
volatile int v;

__attribute__((noipa)) void *
qux (void *x, void *y)
{
  return v ? x : y;
}

void
foo (void)
{
  void *p = (__extension__ ({ x: &&x; }));
  void *q = qux (p, &&y);
  y:;
  goto *q;
}


More information about the Gcc-bugs mailing list