[llvm-dev] [RFC] Should we add isa_or_null<>?

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 6 09:08:57 PDT 2019

On 6 Apr 2019, at 16:00, Don Hinton <hintonda at gmail.com> wrote:
> I like your logic, but not sure it's feasible to detect which one you should use in all cases, e.g., if the user already knows `p` can't be null, they just use `isa`.  However, if it could be null, they use `p && isa<X>(p)`, `cast_or_null` or `dyn_cast_or_null`.  So, we could switch all the current uses of `isa` to the null variety when we make the change, but wouldn't we have to trust the user from them on.  
> Also, wouldn't this be a pretty big change across llvm and all subprojects, and be an issue for downstream projects. 

It would involve a lot of code churn for LLVM (so may not be a good idea for that reason), but for downstream projects it wouldn’t be a breaking change - if they use the null-safe version then their code is still correct, just slightly suboptimal (though I’d expect the compiler to be able to elide the null check in a lot of places).


More information about the llvm-dev mailing list