diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -407,7 +407,7 @@ GV->getValueType()->getPointerTo( CGF.getContext().getTargetAddressSpace(LangAS::Default))); // FIXME: Should we put the new global into a COMDAT? - return Address(C, alignment); + return Address(C, GV->getValueType(), alignment); } return CGF.CreateMemTemp(Ty, "ref.tmp", Alloca); } @@ -441,10 +441,10 @@ ownership != Qualifiers::OCL_ExplicitNone) { Address Object = createReferenceTemporary(*this, M, E); if (auto *Var = dyn_cast(Object.getPointer())) { - Object = Address(llvm::ConstantExpr::getBitCast(Var, - ConvertTypeForMem(E->getType()) - ->getPointerTo(Object.getAddressSpace())), - Object.getAlignment()); + llvm::Type *Ty = ConvertTypeForMem(E->getType()); + Object = Address(llvm::ConstantExpr::getBitCast( + Var, Ty->getPointerTo(Object.getAddressSpace())), + Ty, Object.getAlignment()); // createReferenceTemporary will promote the temporary to a global with a // constant initializer if it can. It can only do this to a value of @@ -499,9 +499,11 @@ Address Object = createReferenceTemporary(*this, M, E, &Alloca); if (auto *Var = dyn_cast( Object.getPointer()->stripPointerCasts())) { + llvm::Type *TemporaryType = ConvertTypeForMem(E->getType()); Object = Address(llvm::ConstantExpr::getBitCast( cast(Object.getPointer()), - ConvertTypeForMem(E->getType())->getPointerTo()), + TemporaryType->getPointerTo()), + TemporaryType, Object.getAlignment()); // If the temporary is a global and has a constant initializer or is a // constant temporary that we promoted to a global, we may have already @@ -1208,9 +1210,10 @@ LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E, const char *Name) { ErrorUnsupported(E, Name); - llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); - return MakeAddrLValue(Address(llvm::UndefValue::get(Ty), CharUnits::One()), - E->getType()); + llvm::Type *ElTy = ConvertType(E->getType()); + llvm::Type *Ty = llvm::PointerType::getUnqual(ElTy); + return MakeAddrLValue( + Address(llvm::UndefValue::get(Ty), ElTy, CharUnits::One()), E->getType()); } bool CodeGenFunction::IsWrappedCXXThis(const Expr *Obj) { @@ -2741,8 +2744,10 @@ LValue CapLVal = EmitCapturedFieldLValue(*this, CapturedStmtInfo->lookup(VD), CapturedStmtInfo->getContextValue()); + Address LValueAddress = CapLVal.getAddress(*this); CapLVal = MakeAddrLValue( - Address(CapLVal.getPointer(*this), getContext().getDeclAlign(VD)), + Address(LValueAddress.getPointer(), LValueAddress.getElementType(), + getContext().getDeclAlign(VD)), CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl), CapLVal.getTBAAInfo()); // Mark lvalue as nontemporal if the variable is marked as nontemporal @@ -3431,7 +3436,8 @@ CfiCheckFailDataTy, Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0, 0); - Address CheckKindAddr(V, getIntAlign()); + + Address CheckKindAddr(V, Int8Ty, getIntAlign()); llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr); llvm::Value *AllVtables = llvm::MetadataAsValue::get( @@ -3817,7 +3823,7 @@ llvm::Value *EltPtr = emitArraySubscriptGEP(*this, Addr.getElementType(), Addr.getPointer(), ScaledIdx, false, SignedIndices, E->getExprLoc()); - Addr = Address(EltPtr, EltAlign); + Addr = Address(EltPtr, Addr.getElementType(), EltAlign); // Cast back. Addr = Builder.CreateBitCast(Addr, OrigBaseTy); @@ -3917,7 +3923,8 @@ CGF.CGM.getNaturalTypeAlignment(ElTy, &TypeBaseInfo, &TypeTBAAInfo); BaseInfo.mergeForCast(TypeBaseInfo); TBAAInfo = CGF.CGM.mergeTBAAInfoForCast(TBAAInfo, TypeTBAAInfo); - return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)), Align); + return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)), + CGF.ConvertTypeForMem(ElTy), Align); } return CGF.EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo); } @@ -4374,7 +4381,7 @@ // fields may leak the real address of dynamic object, which could result // in miscompilation when leaked pointer would be compared. auto *stripped = Builder.CreateStripInvariantGroup(addr.getPointer()); - addr = Address(stripped, addr.getAlignment()); + addr = Address(stripped, addr.getElementType(), addr.getAlignment()); } } @@ -4395,7 +4402,7 @@ addr = Address( Builder.CreatePreserveUnionAccessIndex( addr.getPointer(), getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo), - addr.getAlignment()); + addr.getElementType(), addr.getAlignment()); } if (FieldType->isReferenceType()) @@ -4779,7 +4786,8 @@ *this, LV.getPointer(*this), E->getSubExpr()->getType().getAddressSpace(), E->getType().getAddressSpace(), ConvertType(DestTy)); - return MakeAddrLValue(Address(V, LV.getAddress(*this).getAlignment()), + return MakeAddrLValue(Address(V, ConvertTypeForMem(E->getType()), + LV.getAddress(*this).getAlignment()), E->getType(), LV.getBaseInfo(), LV.getTBAAInfo()); } case CK_ObjCObjectLValueCast: { @@ -5333,7 +5341,8 @@ llvm::Value *Handle = Callee.getFunctionPointer(); auto *Cast = Builder.CreateBitCast(Handle, Handle->getType()->getPointerTo()); - auto *Stub = Builder.CreateLoad(Address(Cast, CGM.getPointerAlign())); + auto *Stub = Builder.CreateLoad( + Address(Cast, Handle->getType(), CGM.getPointerAlign())); Callee.setFunctionPointer(Stub); } llvm::CallBase *CallOrInvoke = nullptr;