[CodeGen] Avoid some pointer element type accesses

Possibly this is sufficient to fix PR53089.
This commit is contained in:
Nikita Popov 2022-01-10 14:58:38 +01:00
parent 7893bb7408
commit 7725331ccd
1 changed files with 6 additions and 8 deletions

View File

@ -4699,12 +4699,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
if (LV.isSimple()) {
Address V = LV.getAddress(*this);
if (V.isValid()) {
llvm::Type *T =
ConvertTypeForMem(E->getType())
->getPointerTo(
cast<llvm::PointerType>(V.getType())->getAddressSpace());
if (V.getType() != T)
LV.setAddress(Builder.CreateBitCast(V, T));
llvm::Type *T = ConvertTypeForMem(E->getType());
if (V.getElementType() != T)
LV.setAddress(Builder.CreateElementBitCast(V, T));
}
}
return LV;
@ -4763,8 +4760,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
CGM.EmitExplicitCastExprType(CE, this);
LValue LV = EmitLValue(E->getSubExpr());
Address V = Builder.CreateBitCast(LV.getAddress(*this),
ConvertType(CE->getTypeAsWritten()));
Address V = Builder.CreateElementBitCast(
LV.getAddress(*this),
ConvertTypeForMem(CE->getTypeAsWritten()->getPointeeType()));
if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
EmitVTablePtrCheckForCast(E->getType(), V.getPointer(),