[llvm] [IR] Don't store switch case values as operands (PR #166842)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 00:16:07 PST 2025


vporpo wrote:

That's a very interesting case @aengelke , thanks for sharing! Let's start with the obvious: the tests are crashing because of the nullptr in the line you added: `ConstantInt *const *case_values() const { return nullptr; } // XXX`, which you obviously had to add because otherwise it wouldn't build. 
Well, having to do in the first place is against the design principles of Sandbox IR: LLVM's `SwitchInst::case_values()` function is private, not public, so Sandbox IR shouldn't interfere with it at all.
So why is this happening? Well it's because for the CaseHandle of the Sandbox IR SwitchInst we used the innocent-looking `CaseHandleImpl` template of LLVM IR's SwitchInst instead of creating a separate class, as is common practice in most other Sandbox IR Instructions. But this template is making assumptions about the private interface of `SwitchInst` (at least it does so with your changes), which creates a tight-coupling, a dependency cycle back to Sandbox IR which shouldn't be there in the first place. 

The fix is quite simple. Similarly to most other components, Sandbox IR's CaseHandle (and most probably the case iterator too) should become its own separate class that depends on LLVM IR' public API and remove the dependency back to Sandbox IR. I will follow-up with a patch that fixes this.

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


More information about the llvm-commits mailing list