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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Sometimes it might be beneficial to use array in .rodata section rather than
automatic compound literal, i.e. try
        const int j = ({ const int myarr[] = {0, 1, 2, 3, 4, 5}; myarr[i]; });
The question is if the gcc should do this as an optimization and when.
Don't remember right now the C requirements, but I bet
int
foo (const int *q)
{
  const int *p = (const int []){0, 1, 2, 3};
  if (q == 0)
    return foo (p);
  else
    return p == q;
}
should return 0, so we probably can't turn into TREE_STATIC all compound
literals, only if we can analyze all their uses.  So either do it only for
limited cases during gimplification, or do it in some later pass, determine if
const variables are initialized and then used in a way where promotion to
TREE_STATIC would be possible and beneficial.

Reply via email to