The cast of a pointer to a different address space makes clang implement an implicit cast during SEMA that was not getting the right CastKind information. This caused the code emission to fail later on. This patch adds an extra check before the creation of the cast and fixes the kind if the types are pointers and the address spaces differ.
This is a fix for http://llvm.org/bugs/show_bug.cgi?id=20135.
Why is Kind == CK_NoOp being passed in here for an address space cast? That seems like it might be a bug in the caller. Do you know which calls to ImpCastExprToType result in this happening?