Skip to content

Commit 7725331

Browse files
committed
[CodeGen] Avoid some pointer element type accesses
Possibly this is sufficient to fix PR53089.
1 parent 7893bb7 commit 7725331

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

clang/lib/CodeGen/CGExpr.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -4699,12 +4699,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
46994699
if (LV.isSimple()) {
47004700
Address V = LV.getAddress(*this);
47014701
if (V.isValid()) {
4702-
llvm::Type *T =
4703-
ConvertTypeForMem(E->getType())
4704-
->getPointerTo(
4705-
cast<llvm::PointerType>(V.getType())->getAddressSpace());
4706-
if (V.getType() != T)
4707-
LV.setAddress(Builder.CreateBitCast(V, T));
4702+
llvm::Type *T = ConvertTypeForMem(E->getType());
4703+
if (V.getElementType() != T)
4704+
LV.setAddress(Builder.CreateElementBitCast(V, T));
47084705
}
47094706
}
47104707
return LV;
@@ -4763,8 +4760,9 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
47634760

47644761
CGM.EmitExplicitCastExprType(CE, this);
47654762
LValue LV = EmitLValue(E->getSubExpr());
4766-
Address V = Builder.CreateBitCast(LV.getAddress(*this),
4767-
ConvertType(CE->getTypeAsWritten()));
4763+
Address V = Builder.CreateElementBitCast(
4764+
LV.getAddress(*this),
4765+
ConvertTypeForMem(CE->getTypeAsWritten()->getPointeeType()));
47684766

47694767
if (SanOpts.has(SanitizerKind::CFIUnrelatedCast))
47704768
EmitVTablePtrCheckForCast(E->getType(), V.getPointer(),

0 commit comments

Comments
 (0)