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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
GCC cannot determine every arbitrarily complex invariant in a complex program. 
If a precondition must be true true that a flow-dependent warning doesn't know
about then asserting it usually both avoids the warning and improves codegen. 
In the test case adding either of the two assertions below has that effect:

            res = func(str, src, size);
            if (size <= 0)
              __builtin_unreachable ();
            str->data()[size - 1] = '\0';

        ...

        // If we get here, dest was completely filled (dest == end)
        if (dest == destBuf->data ())
          __builtin_unreachable ();
        *(dest-1) = 0;
        return (dest-begin);

In future releases, as optimizations improve GCC may be able to determine more
preconditions and the warning might disappear on its own as well.

Reply via email to