“My Little Optimizer: Undefined Behavior is Magic"
summary
Modern C++ compilers treat undefined behavior as permission to change code: LLVM turns a load-from-null into unreachable and removes the preceding store, collapses uninitialized values via undef folding, and uses the NSW flag for signed overflow to simplify arithmetic and loop bounds. Strict-aliasing and lifetime markers let stores be eliminated, malloc’s noalias on malloc enables load-forwarding, and atomics can be optimized under the standard’s ordering rules. Use UBSan, sanitizers and fuzzing to find these bugs before optimizations hide them.
AI-written summary · about
chapters (9)
- 0:00Introduction to UB
- 3:21Representing UB in LLVM
- 10:00Control flow and lifetimes
- 14:25Null pointers and aliasing
- 16:43Signed vs unsigned arithmetic
- 25:57Memory models and realloc
- 29:44Atomic and thread consistency
- 33:47Mitigation and standards
- 39:10Q&A session
related talks
54mUndefined Behaviour is awesome!
49mUndefined Behavior in 2017 (part 1 of 2)
19mExploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the(…)
20mTowards Removing Undef Values from LLVM IR
18mDon't Look UB: Exposing Sanitizer-Eliding Compiler Optimizations
49m“Which Machine Am I Coding To?”
01h 00mType punning in modern C++
01h 04m“Understanding Optimizers: Helping the Compiler Help You”
