[LLVMbugs] [Bug 18046] New: uninitialized warning refers to practically irrelevant code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Nov 24 11:41:42 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=18046

            Bug ID: 18046
           Summary: uninitialized warning refers to practically irrelevant
                    code
           Product: clang
           Version: trunk
          Hardware: PC
                OS: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: M8R-9yw8a5 at mailinator.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

1. Source code (x.c):

int main(void)
{
    for(const char *p = ""; p; ) { }
    for(const char *q; (q = q + 1); ) { }
}

2. Command line:

clang -Wall x.c

3. Output:

x.c:3:26: warning: variable 'q' is used uninitialized whenever 'for' loop exits
because its condition is false [-Wsometimes-uninitialized]
        for(const char *p = ""; p; ) { }
                                ^
x.c:4:26: note: uninitialized use occurs here
        for(const char *q; (q = q + 1); ) { }
                                ^
x.c:3:26: note: remove the condition if it is always true
        for(const char *p = ""; p; ) { }
                                ^
x.c:4:19: note: initialize the variable 'q' to silence this warning
        for(const char *q; (q = q + 1); ) { }
                         ^
                          = 0
1 warning generated.

4. Notes:

   a) Using ``++q'' instead of ``(q = q + 1)'' causes the reference to the
other loop to go away (the uninitialized warning for ``q'' is still given).

   b) If ``q'' is instead created and used (without initialization) in a
non-loop block (eg., ``{ const char *q; (q = q + 1); }''), then the reference
also goes away.

   c) Changing the condition of the 1st loop to ``1'' (always true) causes the
said warnings to go away.

-- 
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/20131124/361b6974/attachment.html>


More information about the llvm-bugs mailing list