[Bug middle-end/89230] Bogus uninited usage warning
lavr at ncbi dot nlm.nih.gov
gcc-bugzilla@gcc.gnu.org
Tue Feb 12 17:17:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89230
--- Comment #5 from lavr at ncbi dot nlm.nih.gov ---
Thank you Martin, for giving me the idea of where the problem might be stemming
from! It does look like *printf() is not recognized by GCC as not modifying
the local memory. But in your example GCC _might_ think that "p" and "q" can
be aliased (being the result of the same function).
Below is a mockup of the code that I was dealing with, clearly showing that "s"
and "h" cannot be aliased! "s" is being on the local frame all alone. I get
the same "uninitialized" warning if BUG is defined:
$ cat bogus2.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct S {
int a;
int b;
};
struct H {
int c;
int d;
};
void getblk(void* blk)
{
struct S* s = (struct S*) blk;
memset(blk, 0, 512);
s->a = rand() & 1;
}
struct H* gethdr(void* blk)
{
memset(blk, 0, 512);
return rand() & 1 ? (struct H*) blk : 0;
}
int main(void)
{
char blk[512], tmp[512];
struct S *s = (struct S*) blk;
struct H *h;
getblk(blk);
if (s->a || !(h = gethdr(tmp)) || s->a != h->d) {
#ifdef BUG
printf("%d\n", s->b);
#endif
if (s->a)
printf("s->a = %d\n", s->a);
else if (!h)
printf("!h\n");
else
printf("h->d = %d\n", h->d);
}
}
$ gcc -O6 -Wall -c bogus2.c
$ gcc -DBUG -O6 -Wall -c bogus2.c
bogus2.c: In function ‘main’:
bogus2.c:42:17: warning: ‘h’ may be used uninitialized in this function
[-Wmaybe-uninitialized]
else if (!h)
^
More information about the Gcc-bugs
mailing list