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

            Bug ID: 96300
           Summary: missing -Wuninitialized reading a struct member by a
                    conditionally assigned pointer
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Of the two functions below with uninitialized reads only the first bug is
detected.  The second one is not.  Both instances should trigger
-Wuninitialized.

$ cat z.c && gcc -O2 -S -Wall -fdump-tree-uninit=/dev/stdout z.c
int f (int i)
{
  int x, y, *p = i ? &x : &y;

  return *p;   // -Wuninitialized
}

struct S { int i; };

int g (int i)
{
  struct S x, y, *p = i ? &x : &y;

  return p->i;   // missing -Wuninitialized
}

;; Function f (f, funcdef_no=0, decl_uid=1931, cgraph_uid=1, symbol_order=0)

z.c: In function ‘f’:
z.c:5:10: warning: ‘x’ is used uninitialized [-Wuninitialized]
    5 |   return *p;   // -Wuninitialized
      |          ^~
f (int i)
{
  int y;
  int x;

  <bb 2> [local count: 1073741824]:
  return x_9(D);

}



;; Function g (g, funcdef_no=1, decl_uid=1939, cgraph_uid=2, symbol_order=1)

g (int i)
{
  struct S y;
  struct S x;
  struct S * iftmp.1_1;
  int _4;

  <bb 2> [local count: 1073741824]:
  if (i_2(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 5> [local count: 536870912]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 536870912]:

  <bb 4> [local count: 1073741824]:
  # iftmp.1_1 = PHI <&x(3), &y(5)>
  _4 = iftmp.1_1->i;
  x ={v} {CLOBBER};
  y ={v} {CLOBBER};
  return _4;

}

Reply via email to