llvm-project
9e428b7e - [LLVM][Support] add nonNull function helper (#188718)

Commit
11 days ago
[LLVM][Support] add nonNull function helper (#188718) We often see a pattern like: ``` T *ptr = doSomething() assert(ptr && "doSomething() shouldn't return nullptr"); ``` We also have functions like `cantFail`, but those are working with Expected types. This commits adds a `nonNull` function, which can be used inline. In practice, one could use: ``` T *ptr = cast<T>(functionReturningT()); ``` But it conveys the meaning that `functionReturningT` might return a subtype/supertype that we actually cast. Function behaves like the other error kinds: calls llvm_unreachable, which may or may not trap depending on the build options. Calling this function with `nullptr` won't build, but it makes no sense to do so. --------- Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
Author
Parents
Loading