[llvm] [IR] Fix User use-after-destroy by zapping in ~User (PR #170575)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 10:58:55 PST 2025


rnk wrote:

Thanks for gathering the perf data! I did a bit more digging, and I discovered this inheritance relationship:
Value -> User -> Constant -> ConstantData -> ConstantInt

This gives me some pause. I think it's worth investigating this a bit more. In a pre-C++20 world (I need to look up the timeline for us on that...), we could avoid bloating `ConstantData` instances by specializing `ConstantData::operator delete` to have it directly use `::operator delete` with no adjustment, since we know that all subclasses of `ConstantData` have no operands. The allocation side would need a similar adjustment, which adds complexity. =/

Truly, the C++20 solution is the cleanest. My recollection is that MLIR uses factory methods so they can customize allocation more deeply. It's somewhat nice that LLVM IR uses conventional C++ heap allocation facilities, but perhaps it's not worth it.

I think that zero-operand `Instruction` instances are probably marginal and uncommon and not worth optimizing (`return void`, `freeze`, can't think of another).

https://github.com/llvm/llvm-project/pull/170575


More information about the llvm-commits mailing list