[clang] 7725331 - [CodeGen] Avoid some pointer element type accesses
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 10 06:03:02 PST 2022
Author: Nikita Popov
Date: 2022-01-10T15:02:55+01:00
New Revision: 7725331ccdd82312e1ae82d4d634ee5d7dec2406
URL: https://github.com/llvm/llvm-project/commit/7725331ccdd82312e1ae82d4d634ee5d7dec2406
DIFF: https://github.com/llvm/llvm-project/commit/7725331ccdd82312e1ae82d4d634ee5d7dec2406.diff
LOG: [CodeGen] Avoid some pointer element type accesses
Possibly this is sufficient to fix PR53089.
Added:
Modified:
clang/lib/CodeGen/CGExpr.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 053c9f6e06d7..0fb7ec26a85e 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -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(),
More information about the cfe-commits
mailing list