timshen added a comment. - Do you have a reduced testcase that produces the crash? - Would it be better to call M.getGlobalVariable(), assert on the returned value, and then create an IR cast on the returned GlobalValue? https://reviews.llvm.org/D23674