Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1587,12 +1587,14 @@ // All parameters are already in place except VTT, which goes after 'this'. // These are Clang types, so we don't need to worry about sret yet. - // Check if we need to add a VTT parameter (which has type void **). + // Check if we need to add a VTT parameter (which has type global void **). if ((isa(GD.getDecl()) ? GD.getCtorType() == Ctor_Base : GD.getDtorType() == Dtor_Base) && cast(GD.getDecl())->getParent()->getNumVBases() != 0) { + LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr); + QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS); ArgTys.insert(ArgTys.begin() + 1, - Context.getPointerType(Context.VoidPtrTy)); + Context.getPointerType(CanQualType::CreateUnsafe(Q))); return AddedStructorArgCounts::prefix(1); } return AddedStructorArgCounts{}; @@ -1625,7 +1627,9 @@ ASTContext &Context = getContext(); // FIXME: avoid the fake decl - QualType T = Context.getPointerType(Context.VoidPtrTy); + LangAS AS = CGM.GetGlobalVarAddressSpace(nullptr); + QualType Q = Context.getAddrSpaceQualType(Context.VoidPtrTy, AS); + QualType T = Context.getPointerType(Q); auto *VTTDecl = ImplicitParamDecl::Create( Context, /*DC=*/nullptr, MD->getLocation(), &Context.Idents.get("vtt"), T, ImplicitParamDecl::CXXVTT); @@ -1667,10 +1671,14 @@ if (!NeedsVTTParameter(GlobalDecl(D, Type))) return AddedStructorArgs{}; - // Insert the implicit 'vtt' argument as the second argument. + // Insert the implicit 'vtt' argument as the second argument. Make sure to + // correctly reflect its address space, which can differ from generic on + // some targets. llvm::Value *VTT = CGF.GetVTTParameter(GlobalDecl(D, Type), ForVirtualBase, Delegating); - QualType VTTTy = getContext().getPointerType(getContext().VoidPtrTy); + LangAS AS = getLangASFromTargetAS(VTT->getType()->getPointerAddressSpace()); + QualType Q = getContext().getAddrSpaceQualType(getContext().VoidPtrTy, AS); + QualType VTTTy = getContext().getPointerType(Q); return AddedStructorArgs::prefix({{VTT, VTTTy}}); }