4 ms·
Yep! Dumb example. main() x = get_from_some_external_data_source() if x: print("Hello World") trigger_ub() You might expect th
by Spivak 6y ago
Yep! Dumb example.
main()
x = get_from_some_external_data_source()
if x:
print("Hello World")
trigger_ub()
You might expect this code to always print if x is true but the optimizer can look at this and say "welp, if x is true then it would trigger ub, therefore it must be false, and since x must always be false we can just remove that entire branch."
- kbenson 6y agoMy favorite example along these lines (in C) is "Cap'n'Proto remote vuln: pointer overflow check optimized away by compiler"[1] which was covered here a few years back and shows all of these "theoretical" compiler behaviors coming to a head in a real bug which is thoroughly explained. 1: https://news.ycombinator.com/item?id=14163111 https://news.ycombinator.com/item?id=14163111