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

--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Zdenek Sojka from comment #2)
> Similar happens with _BitInt(<8):
> 
> $ cat testcase.c
> char
> foo ()
> {
>   _BitInt(7) b;
>   if (__builtin_add_overflow (1, 2, &b))
>     b = 0;
>   return b;
> }
> $ x86_64-pc-linux-gnu-gcc -Og -ftrivial-auto-var-init=pattern
> -Werror=uninitialized testcase.c 
> testcase.c: In function 'foo':
> testcase.c:4:14: error: 'b' is used uninitialized [-Werror=uninitialized]
>     4 |   _BitInt(7) b;
>       |              ^
> cc1: some warnings being treated as errors

This one shows

  <bb 2> [local count: 1073741824]:
  _1 = .DEFERRED_INIT (1, 1, &"b"[0]);
  b = _1;
  _8 = VIEW_CONVERT_EXPR<char>(_1);
  _2 = _8 & 127;
  MEM[(_BitInt(7) *)&b] = _2;
  b = 3;
  b ={v} {CLOBBER(eos)};
  return 3;

which is not pattern matched.  A better testcase that also diagnoses at -O2 is

void bar(_BitInt(7) *);
void
foo ()
{
  _BitInt(7) b;
  bar (&b);
}

showing

  <bb 2> [local count: 1073741824]:
  _1 = .DEFERRED_INIT (1, 1, &"b"[0]);
  _7 = VIEW_CONVERT_EXPR<char>(_1);
  _2 = _7 & 127;
  MEM[(_BitInt(7) *)&b] = _2;
  bar (&b);
  b ={v} {CLOBBER(eos)};
  return;

it's tempting to match a .DEFERRED_INIT def as "load" of 'b', but we
cannot really distinguish this from

void bar(_BitInt(7));
void baz(_BitInt(7) *);
void
foo ()
{
  _BitInt(7) b;
  bar (b);
  baz (&b);
}

we fail to optimize this btw:

  <bb 2> [local count: 1073741824]:
  _1 = .DEFERRED_INIT (1, 1, &"b"[0]);
  _9 = VIEW_CONVERT_EXPR<char>(_1);
  _3 = _9 & 127;
  MEM[(_BitInt(7) *)&b] = _3;
  b.0_2 = b;
  bar (b.0_2);
  baz (&b);
  b ={v} {CLOBBER(eos)};
  return;

the load to b.0_2 is not elided somehow.

So I'm not adding a match to any .DEFERRED_INIT def.

Reply via email to