2 ms·
The most important thing about this: int x; if (x < 42) { assert (x != 12345); } isn't to have a checker is clever enough to know that the assert will no
by kazinator 3y ago
The most important thing about this:
int x;
if (x < 42) { assert (x != 12345); }
isn't to have a checker is clever enough to know that the assert will not go off, but to be informed that the automatic variable x is being accessed without being initialized!!!
- mort96 3y agoTo repurpose an old meme... Intelligence is knowing that the assert will never go off. Wisdom is knowing that it might.
- kazinator 3y agoWisdom is knowing that the entire block may be treated by your compiler as if it were __builtin_unreachable().
- lou1306 3y agoCome on, that kind of check is almost trivial to implement. Anyway, there you go: extern int nondet (void); int x = nondet(); if (x < 42) { assert (x != 12345); }
- kazinator 3y agoThere are trivial cases of the use of an uninitialized variable that elementary data flow analysis will uncover. When the variable definition and its use are together in the same basic block, it's immediately obvious that the variable has a next-use on entry into the block, and that its definition hasn't supplied it with a value. From there it gets complicated. GCC has a history of emitting overly zealous diagnostics in this area, warning about possibly uninitialized variables that can be proven not to be. The difficulty is equivalent to the halting problem: void f() { int x; if (invokes_undefined_behavior(f)) x = 'A'; putchar(x); }