C++ devirtualization in clang
summary
Clang implements devirtualization by adding LLVM-level checks and metadata: it inserts llvm.assume checks after constructors, uses available_externally vtable linkage when safe, and introduces invariant-group metadata plus barrier calls to let the optimizer treat repeated vptr loads as identical. Placement new, inline virtuals and key-function vtable placement force conservative behavior, so an LTO-aware compiler flag and runtime-UB diagnostics are required. Implementation is experimental, LTO compatibility is tricky, and performance numbers are not yet finalized.
AI-written summary · about
chapters (13)
- 0:00Intro
- 0:58How virtual calls works
- 1:53Old devirtualization
- 4:42Calling the same virtual function
- 5:09Placement new is evil
- 6:38assuming type after ctor call
- 7:50available_externally vtables
- 8:49propagating "constness" of vptr
- 9:29introducing linvariant.group
- 10:04Dealing with placement new
- 10:42introducing invariant.group.barrier
- 11:09introducing -fstrict-vtable-pointers
- 12:49Corner cases
related talks
24mGenerating BPF Verifier Friendly Code with Clang
16mReconciling Optimization With Secure Compilation
01h 23mElsewhere Memory (C++20 Abstract Machine) + Virtual Memory
01h 34mSecurity in C++ - Hardening Techniques From the Trenches
18mExciting new compiler flags for kernel security
52mNon-conforming C++: the Secrets the Committee Is Hiding From You
19mExploiting Undefined Behavior in C/C++ Programs for Optimization: A Study on the(…)
01h 01mDeprecating volatile
