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

--- Comment #6 from Kewen Lin <linkw at gcc dot gnu.org> ---
It's an arguable topic, I can't find the thread that previously some reviewers
told me it's not always good to initialize the local variable. IIRC, the case
is that I initialized one variable at the top, but the one got assigned in
below all switch cases, I was told not to initialize it, once a new case arm
use that variable unexpectedly, some bug would show up (static analyzer or
runtime bug), a default (but not reasonable) value is easy to cover some issue,
though at that time I hold an argument that initializing local variable seems
best practice.

For this case, since vect_analyze_loop_2 isn't able to be inlined, the
initialization can't be optimized, the worse thing I meant is to have more
instructions than before, for example, a test case like:

__attribute__((noipa)) int foo(int *a) { *a = 1; return 1;}

int test(){
#ifdef AINIT
  int a = 0;
#else
  int a;
#endif
  int b = foo(&a);
  return b;
}

on Power, I got one more li and stw for -DAINIT.

But I just posted my naive thoughts, if you still think it's better to
initialize it, you can just go ahead to post a patch. :)

----

btw, the test case

int foo() {
  bool a = true;
  bool b;
  if (a || b)
    return 1;
  b = true;
  return 0;
}

still has the warning, it looks something can be improved (guess we prefer not
to emit warning).

Reply via email to