@@ -2939,6 +2939,8 @@ CodeGenFunction::EmitLoadOfReference(LValue RefLVal,
2939
2939
Builder.CreateLoad (RefLVal.getAddress (), RefLVal.isVolatile ());
2940
2940
CGM.DecorateInstructionWithTBAA (Load, RefLVal.getTBAAInfo ());
2941
2941
QualType PTy = RefLVal.getType ()->getPointeeType ();
2942
+ CharUnits Align = CGM.getNaturalTypeAlignment (
2943
+ PTy, PointeeBaseInfo, PointeeTBAAInfo, /* ForPointeeType=*/ true );
2942
2944
if (!PTy->isIncompleteType ()) {
2943
2945
llvm::LLVMContext &Ctx = getLLVMContext ();
2944
2946
llvm::MDBuilder MDB (Ctx);
@@ -2949,17 +2951,16 @@ CodeGenFunction::EmitLoadOfReference(LValue RefLVal,
2949
2951
llvm::MDNode::get (Ctx, {}));
2950
2952
// Emit !align metadata
2951
2953
if (PTy->isObjectType ()) {
2952
- auto Align =
2953
- CGM.getNaturalPointeeTypeAlignment (RefLVal.getType ()).getQuantity ();
2954
- if (Align > 1 ) {
2954
+ auto AlignVal = Align.getQuantity ();
2955
+ if (AlignVal > 1 ) {
2955
2956
Load->setMetadata (
2956
2957
llvm::LLVMContext::MD_align,
2957
2958
llvm::MDNode::get (Ctx, MDB.createConstant (llvm::ConstantInt::get (
2958
- Builder.getInt64Ty (), Align ))));
2959
+ Builder.getInt64Ty (), AlignVal ))));
2959
2960
}
2960
2961
}
2961
2962
}
2962
- return makeNaturalAddressForPointer (Load, PTy, CharUnits () ,
2963
+ return makeNaturalAddressForPointer (Load, PTy, Align ,
2963
2964
/* ForPointeeType=*/ true , PointeeBaseInfo,
2964
2965
PointeeTBAAInfo);
2965
2966
}
0 commit comments