[Bug middle-end/89501] Odd lack of warning about missing initialization

torvalds@linux-foundation.org gcc-bugzilla@gcc.gnu.org
Mon Feb 25 23:32:00 GMT 2019


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

--- Comment #2 from Linus Torvalds <torvalds@linux-foundation.org> ---
(In reply to Andrew Pinski from comment #1)
> I think it comes down to the same issue as PR 18501.

Very possibly the same issue in just a different guise.

NOTE! I have in the meantime verified that yes, it does seem to be about the
pattern

   int x;

   if (somecondition) {
      x = something();
      if (x != XYZ)
         return x;
   }

   return x;

where gcc seems to turn the "if (x != XYZ) return x" to mean that "x" clearly
_has_ to be XYZ elsewhere.

If I change my kernel-based test-case to do

    if (ret != 1)
        return ret;

instead of the original

    if (ret)
        return ret;

then gcc will actually generate code that ends with

        movl    $1, %eax
        popq    %rbp
        popq    %r12
        ret

ie it will basically consider "ret" to be initialized to that value "1", even
if the basic block that assigned it was never actually executed.

Knowing how SSA works, I'm not entirely surprised, but obviously if you'd like
to see the warning about buggy source code, it's less than optimal.

Anyway, this shouldn't be a high priority, but it does strike me as a
potentially fairly common pattern that people might be missing warnings for.

              Linus


More information about the Gcc-bugs mailing list