Skip to content

Commit

Permalink
[CodeGen] Avoid some pointer element type accesses
Browse files Browse the repository at this point in the history
Possibly this is sufficient to fix PR53089.
  • Loading branch information
nikic committed Jan 10, 2022
1 parent 7893bb7 commit 7725331
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 7725331

Please sign in to comment.