Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -5183,11 +5183,17 @@ V->getType()->isIntegerTy()) V = Builder.CreateZExt(V, ArgInfo.getCoerceToType()); - // If the argument doesn't match, perform a bitcast to coerce it. This - // can happen due to trivial type mismatches. + // If the argument doesn't match, perform a either a bitcast or an + // address space cast to coerce it. This can happen either due to + // trivial type mismatches or valid address space mismatches + // (e.g. global -> generic; GEPs into VTTs are an example). if (FirstIRArg < IRFuncTy->getNumParams() && V->getType() != IRFuncTy->getParamType(FirstIRArg)) - V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg)); + if (V->getType()->isPointerTy()) + V = Builder.CreateAddrSpaceCast(V, + IRFuncTy->getParamType(FirstIrArg)); + else + V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg)); if (ArgHasMaybeUndefAttr) V = Builder.CreateFreeze(V);