Skip to content

Commit 5a1269a

Browse files
committed
[Clang][CodeGen] Reuse alignment computation
1 parent 68f6381 commit 5a1269a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,8 @@ CodeGenFunction::EmitLoadOfReference(LValue RefLVal,
29392939
Builder.CreateLoad(RefLVal.getAddress(), RefLVal.isVolatile());
29402940
CGM.DecorateInstructionWithTBAA(Load, RefLVal.getTBAAInfo());
29412941
QualType PTy = RefLVal.getType()->getPointeeType();
2942+
CharUnits Align = CGM.getNaturalTypeAlignment(
2943+
PTy, PointeeBaseInfo, PointeeTBAAInfo, /*ForPointeeType=*/true);
29422944
if (!PTy->isIncompleteType()) {
29432945
llvm::LLVMContext &Ctx = getLLVMContext();
29442946
llvm::MDBuilder MDB(Ctx);
@@ -2949,17 +2951,16 @@ CodeGenFunction::EmitLoadOfReference(LValue RefLVal,
29492951
llvm::MDNode::get(Ctx, {}));
29502952
// Emit !align metadata
29512953
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) {
29552956
Load->setMetadata(
29562957
llvm::LLVMContext::MD_align,
29572958
llvm::MDNode::get(Ctx, MDB.createConstant(llvm::ConstantInt::get(
2958-
Builder.getInt64Ty(), Align))));
2959+
Builder.getInt64Ty(), AlignVal))));
29592960
}
29602961
}
29612962
}
2962-
return makeNaturalAddressForPointer(Load, PTy, CharUnits(),
2963+
return makeNaturalAddressForPointer(Load, PTy, Align,
29632964
/*ForPointeeType=*/true, PointeeBaseInfo,
29642965
PointeeTBAAInfo);
29652966
}

0 commit comments

Comments
 (0)