Exploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the Performance Impact
Lucian Popescu, Nuno P. Lopes
Abstract
The C and C++ languages define hundreds of cases as having undefined behavior (UB). These include, for example, corner cases where different CPU architectures disagree on the semantics of an instruction and the language does not want to force a specific implementation (e.g., shift by a value larger than the bitwidth). Another class of UB involves errors that the language chooses not to detect because it would be too expensive or impractical, such as dereferencing out-of-bounds pointers.
Although there is a common belief within the compiler community that UB enables certain optimizations that would not be possible otherwise, no rigorous large-scale studies have been conducted on this subject. At the same time, there is growing interest in eliminating UB from programming languages to improve security.
In this paper, we present the first comprehensive study that examines the performance impact of exploiting UB in C and C++ applications across multiple CPU architectures. Using LLVM, a compiler known for its extensive use of UB for optimizations, we demonstrate that, for the benchmarks and UB categories that we evaluated, the end-to-end performance gains are minimal. Moreover, when performance regresses, it can often be recovered through small improvements to optimization algorithms or by using link-time optimizations.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext eb7df5bf-7f1a-4e94-baad-c4867a896153Cited by top-tier papers2
- A Family of Sims with Diverging InterestsNicolas ChappePOPL 2026
- Towards Removing Undef Values from LLVM IRPedro Lobo, John McIver, George Mitenkov, Juneyoung Lee et al.PLDI 2026
Builds on10
- SoK: Sanitizing for SecurityDokyung Song, Julian Lettner, Prabhu Rajasekaran, Yeoul Na et al.S&P 2019 · 196 citations
- Alive2: bounded translation validation for LLVMNuno P. Lopes, Juneyoung Lee, Chung-Kil Hur, Zhengyang Liu et al.PLDI 2021 · 109 citations
- UniSan: Proactive Kernel Memory Initialization to Eliminate Data LeakagesKangjie Lu, Chengyu Song, Taesoo Kim, Wenke LeeCCS 2016 · 81 citations
- Finding Unstable Code via Compiler-Driven Differential TestingShaohua Li, Zhendong SuASPLOS 2023 · 19 citations
- Refined Input, Degraded Output: The Counterintuitive World of Compiler BehaviorTheodoros Theodoridis, Zhendong SuPLDI 2024 · 14 citations
Related papers
- Don't Look UB: Exposing Sanitizer-Eliding Compiler OptimizationsRaphael Isemann, Cristiano Giuffrida, Herbert Bos, Erik van der Kouwe et al.PLDI 2023 · 5 citations
- Silent Bugs Matter: A Study of Compiler-Introduced Security BugsJianhao Xu, Kangjie Lu, Zhengjie Du, Zhu Ding et al.USENIX Security 2023
- Not so fast: understanding and mitigating negative impacts of compiler optimizations on code reuse gadget setsMichael D. Brown, Matthew Pruett, Robert Bigelow, Girish Mururu et al.OOPSLA 2021 · 11 citations
- KUBO: Precise and Scalable Detection of User-triggerable Undefined Behavior Bugs in OS KernelChangming Liu, Yaohui Chen, Long LuNDSS 2021
- An Integer Overflow Endgame: Compiler and Architecture Support for Default-On Integer Overflow MitigationZheng Zhang, Qi Ling, Kian Kasad, Brendan Ryan Sweeney et al.USENIX Security 2026
