|
|
|
|
|
by bertit
3511 days ago
|
|
That would not work. Since the test may not cause any problems. While the compiler might find more optimzation opportuinities in the real program. (Just as the begining of the function did not have problem, but the for loop had.) Just don't use undefined behavior. |
|
2. Users report that it started crashing sometimes in version V.
3. After lots of debugging, you discover an input that reliably crashes your program after 30 minutes.
4. A bit later, you discover that your compiler started compiling function f so that it no longer works with unaligned data/buffers of exactly 8 bytes/whatever.
5. At the start of main, you add a dummy call to f with data that reliably crashes if your compiler decides to do that optimization again.
6. The program has become worse: it now always crashes, independent of its input, but you don't have to wait 30 minutes before finding out. That makes it way less likely that you ship a binary again that has the problem. It also makes it easier to tweak source code/compiler flags/whatever until the problem disappears.
Is that perfect? Absolutely not, it is more something of last resort, but depending on the costs of crashing versus those of sometimes crashing half-way through a run, it can be an improvement.
(this technique also can be used when your code hits compiler bugs)