[CodeGen] Avoid pointer element type access when creating LValue

This required fixing two places that were passing the pointer type
rather than the expected pointee type to the method.
This commit is contained in:
Nikita Popov 2021-12-21 15:28:45 +01:00
parent 33319dde2a
commit 09669e6c5f
3 changed files with 5 additions and 4 deletions

View File

@ -1309,7 +1309,8 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) {
const ConstantExpr *CE = cast<ConstantExpr>(E);
if (llvm::Value *Result = ConstantEmitter(*this).tryEmitConstantExpr(CE)) {
QualType RetType = cast<CallExpr>(CE->getSubExpr()->IgnoreImplicit())
->getCallReturnType(getContext());
->getCallReturnType(getContext())
->getPointeeType();
return MakeNaturalAlignAddrLValue(Result, RetType);
}
return EmitLValue(cast<ConstantExpr>(E)->getSubExpr());

View File

@ -5945,7 +5945,7 @@ static llvm::Value *emitReduceInitFunction(CodeGenModule &CGM,
} else {
OrigLVal = CGF.MakeNaturalAlignAddrLValue(
llvm::ConstantPointerNull::get(CGM.VoidPtrTy),
CGM.getContext().VoidPtrTy);
CGM.getContext().VoidTy);
}
// Emit the initializer:
// %0 = bitcast void* %arg to <type>*

View File

@ -188,8 +188,8 @@ LValue CodeGenFunction::MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T) {
LValueBaseInfo BaseInfo;
TBAAAccessInfo TBAAInfo;
CharUnits Alignment = CGM.getNaturalTypeAlignment(T, &BaseInfo, &TBAAInfo);
return LValue::MakeAddr(Address(V, Alignment), T, getContext(), BaseInfo,
TBAAInfo);
Address Addr(V, ConvertTypeForMem(T), Alignment);
return LValue::MakeAddr(Addr, T, getContext(), BaseInfo, TBAAInfo);
}
/// Given a value of type T* that may not be to a complete object,