[llvm] [NFC]Add assert to avoid possibly deref nullptr (PR #65564)

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 11:28:55 PDT 2023


JDevlieghere wrote:

First off, I appreciate you trying to fix this issue. 

> I think add an assert would be a light weight fix to it.

As Adrian and I pointed out earlier, the current patch doesn't fix anything. I would go even further and say it makes things worse, because the assert states that `MMI` cannot be null, while there's a code patch that shows that it can be. 

> I have no evidence MMI would be nullptr from author's intention

You pointed out that it can be null if `MMIWP` is null, which is the case if the analysis pass is not found. If you look at the implementation of `findAnalysisPass`, it has a comment saying:

```
/// Find the pass that implements Analysis AID. Search immutable
/// passes and all pass managers. If desired pass is not found
/// then return NULL.
```

Clearly, it's possible for a pass to not exist. If someone were to build LLVM without `MachineModuleInfoWrapperPass`, `MMIWP` would be NULL and consequently `MMI` would be NULL. 

> If you guys strongly object this patch, I would revert it and use if-condition instead.

Yes, we should use an if-condition instead.

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


More information about the llvm-commits mailing list