[llvm-bugs] [Bug 43717] Missing -Wuninitialized warning with some gotos

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 18 18:50:25 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43717

Richard Smith <richard-llvm at metafoo.co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
This is working as intended.

-Wuninitialized warns on cases where a particular use of a variable is only
reachable in cases where the variable is uninitialized. (So either that use of
the variable is unreachable, or you have a use-uninitialized bug.)

-Wsometimes-uninitialized warns on cases where a particular branch always
results in an uninitialized use whenever it's taken. (So either that branch can
never be taken in that direction, or you have a use-uninitialized bug.)

Under the assumption that you have no dead code, both warnings have zero false
positives.


If instead you want a warning with fewer false negatives (but that instead has
false positives), you can use -Wconditional-uninitialized. That will warn
whenever we see a use of a variable and we can find any path to that variable
that didn't initialize it. (This has false positives if the path that we find
is actually impossible -- for instance, if it contains two branches on the same
value and requires them to go in different directions.)

-Wconditional-uninitialized does warn on this code:

<stdin>:20:16: warning: variable 'status' may be uninitialized when used here
[-Wconditional-uninitialized]
        return status;
               ^~~~~~
<stdin>:4:19: note: initialize the variable 'status' to silence this warning
        int status;
                  ^
                   = 0

(You can also use -Weverything to find out whether clang has a warning for a
particular construct.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191019/9946b56c/attachment.html>


More information about the llvm-bugs mailing list