[LLVMbugs] [Bug 17526] New: -Wconditional-uninitialized false positive when usage is correctly constrained by other variable
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Oct 9 14:49:26 PDT 2013
http://llvm.org/bugs/show_bug.cgi?id=17526
Bug ID: 17526
Summary: -Wconditional-uninitialized false positive when usage
is correctly constrained by other variable
Product: new-bugs
Version: trunk
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: sean at rogue-research.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Consider this C99:
-------------------------
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
typedef enum
{
kDog,
kCat,
} MyEnum;
int main (void)
{
bool isValid = false;
MyEnum animal; // NB: UNINITIALIZED!
int random = rand();
if (random == 420)
{
animal = kDog;
isValid = true;
}
if (isValid)
{
printf("animal is %u", animal);
}
return 0;
}
-------------------------
$ clang --version
clang version 3.4 (192323)
$ clang -Weverything -fsyntax-only ~/Desktop/test.c
/Users/sean/Desktop/test.c:25:26: warning: variable 'animal' may be
uninitialized when used here [-Wconditional-uninitialized]
printf("animal is %u", animal);
^~~~~~
/Users/sean/Desktop/test.c:14:2: note: variable 'animal' is declared here
MyEnum animal; // NB: UNINITIALIZED!
^
1 warning generated.
It's easy for a human to see that "animal" is only used if "isValid" is true
and that everywhere "isValid" is set to true, "animal" is also set to
something. The bug is that clang can't also see this. :)
This is a reduced test case of something similar but with many more if-else
branches.
--
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/20131009/645eadff/attachment.html>
More information about the llvm-bugs
mailing list