A common type of bug in C programs is that the program uses some uninitialized data, most often assuming something is zero when it has in fact never been initialized to zero. Such a program can seem to work because those memory locations just happen to be zero, but then one day there is some garbage there and your program crashes.
I know that valgrind is a great tool to find such problems. But sometimes valgrind cannot be used, for example if the program does memory allocation in a nonstandard way.
My question: is there some compiler option to gcc (or clang) that could be used to ask the compiler to initialize local variables to some nonzero "poison" values, in order to expose that kind of bugs?
I think it should be technically possible for the compiler to do that, to insert some instructions at each function call to put that data into the memory space of stack variables that would normally be uninitialized. There would be some performance cost, but cheap compared to using valgrind, and also valgrind may not be possible to use in some cases.
Edit: let me clarify that this question is not about compiler warnings. Of course compiler warnings are very helpful, they should be turned on and taken care of, but that does not solve all problems with uninitialized data. For example, the program may take the address of a local variable and pass that to a function, then the compiler will not know if the address is passed to allow the function to copy data there (which would be fine) or if the function will use the data pointed to (which would mean using uninitialized data).