The use of uninitialized local variables is undefined in C. The purpose of this issue is to discuss the advantages and disadvantages of implementation deterministic vs. non-deterministic behaviour for uninitialized variables.
Deterministic behaviour
For sake of discussion, lets assume that the deterministic behaviour would be defined such that uninitialized local variables are always zero-initialized.
Non-deterministic behaviour
Furthermore, for the sake of discussion, lets assume that one (of potentially many) non-deterministic behaviours would be defined such that uninitialized local variables have the value of the previous contents stored at the same memory location of the stack frame as the local variable.
Examples
Example input C source file:
void f() {
int x; // Uninitialized variable
if (x) { // Use of uninitialized variable.
;
}
}
Marked as a future ambition. For now, lets do what Clang does. In the future, we may continue the discussion and decide which approach feels closest to heart.
The use of uninitialized local variables is undefined in C. The purpose of this issue is to discuss the advantages and disadvantages of implementation deterministic vs. non-deterministic behaviour for uninitialized variables.
Deterministic behaviour
For sake of discussion, lets assume that the deterministic behaviour would be defined such that uninitialized local variables are always zero-initialized.
Non-deterministic behaviour
Furthermore, for the sake of discussion, lets assume that one (of potentially many) non-deterministic behaviours would be defined such that uninitialized local variables have the value of the previous contents stored at the same memory location of the stack frame as the local variable.
Examples
Example input C source file:
LLVM IR output from Clang: