[llvm] [llvm] fix nullptr dereference in BasicBlock::getIrrLoopHeaderWeight (PR #116192)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 06:42:01 PST 2024


nikic wrote:

> I think you are right that we should not guarantee that MachineBasicBlock can be constructed for an empty BasicBlock. It indeed has very little sense from compiler infrastructure point of view (will remove the test for it). Thank you. However I think it does make sense to return `std::nullopt` in the case terminator is not found. It seems legal to me to attempt to get Loop Header Weight of the BasicBlock with no terminators (and the result should be `std::nullopt` because block is indeed incomplete and we can not analyze any loop-related stuff on WIP basic block). In case you are still strongly against handling this case let me know and I'll simply add an assert instead.

I'd prefer the assert. I don't think querying this on an incomplete block is a legal operation. It's better to crash and burn than silently accept unexpected state.

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


More information about the llvm-commits mailing list