[Bug c++/102281] -ftrivial-auto-var-init=zero causes ice

qinzhao at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 12 14:50:54 GMT 2021


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

--- Comment #11 from qinzhao at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #8)
> Sure, you can, but just note that it is conservative and fast, it will
> return true even for types that don't have any padding.
> But for double, _Complex double, int etc. it will quickly return false.
> I guess I should use it in c-omp.c too.

I saw you changed c-omp.c today, I am wondering whether it's better to also add
the following as a common utility routine to dimple-fold.[ch], then I can use
it when adding padding initializations for auto var:

/* Return true if TYPE contains any padding bits.  */
bool
clear_padding_type_has_padding_p (tree type)
{
  bool clear_padding = false;
  if (BITS_PER_UNIT == 8
      && CHAR_BIT == 8
      && clear_padding_type_may_have_padding_p (type))
    {
      HOST_WIDE_INT sz = int_size_in_bytes (cmptype), i;
      gcc_assert (sz > 0);
      unsigned char *buf = XALLOCAVEC (unsigned char, sz);
      memset (buf, ~0, sz);
      clear_type_padding_in_mask (cmptype, buf);
      for (i = 0; i < sz; i++)
      if (buf[i] != (unsigned char) ~0)
        {
          clear_padding = true;
          break;
        }
    }
  return clear_padding;
}


More information about the Gcc-bugs mailing list