[cfe-dev] clang and clang-sa do not detect uninitialized variable
Ali Shuja Siddiqui (alissidd) via cfe-dev
cfe-dev at lists.llvm.org
Thu Apr 29 13:41:55 PDT 2021
Hello,
With the following code
//-------------------------
#include <stdio.h>
extern int t;
void use_b (int *b){
printf("%p\n",b);
}
void func(){
int b;
use_b(&b);
if (b)
b+=33;
}
//---------------------------
Running clang -Wuninitialized or running clang –analyze, I don’t see any warning for uninitialized variables. However, if I change the code to:
//----------------------
#include <stdio.h>
extern int t;
void use_b (int *b){
if (t==5)
return;
printf("%p\n",b);
}
void func(){
int b;
use_b(&b);
if (b)
b+=33;
}
//--------------------
I do see this warning with the static analyzer:
sa_try.c:13:9: warning: Branch condition evaluates to a garbage value [core.uninitialized.Branch]
if (b)
^
1 warning generated.
My question is why am I not getting any warning for the first case? Is it being considered that printf is updating the value of b in some way?
Thanks,
Ali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210429/05175245/attachment.html>
More information about the cfe-dev
mailing list