IRgen: Set the alignment correctly when creating LValue for a decls.
- Fixes PR5598.
- Review appreciated.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111726 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 8cc5480..cbe1982 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1118,7 +1118,8 @@
llvm::Value *V = CGF.CGM.GetAddrOfGlobalVar(VD);
if (VD->getType()->isReferenceType())
V = CGF.Builder.CreateLoad(V, "tmp");
- LValue LV = CGF.MakeAddrLValue(V, E->getType());
+ unsigned Alignment = CGF.getContext().getDeclAlign(VD).getQuantity();
+ LValue LV = CGF.MakeAddrLValue(V, E->getType(), Alignment);
setObjCGCLValueClass(CGF.getContext(), E, LV);
return LV;
}
@@ -1138,17 +1139,18 @@
V = CGF.Builder.CreateBitCast(V, CGF.ConvertType(NoProtoType), "tmp");
}
}
- return CGF.MakeAddrLValue(V, E->getType());
+ unsigned Alignment = CGF.getContext().getDeclAlign(FD).getQuantity();
+ return CGF.MakeAddrLValue(V, E->getType(), Alignment);
}
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
const NamedDecl *ND = E->getDecl();
+ unsigned Alignment = CGF.getContext().getDeclAlign(ND).getQuantity();
if (ND->hasAttr<WeakRefAttr>()) {
const ValueDecl* VD = cast<ValueDecl>(ND);
llvm::Constant *Aliasee = CGM.GetWeakRefReference(VD);
-
- return MakeAddrLValue(Aliasee, E->getType());
+ return MakeAddrLValue(Aliasee, E->getType(), Alignment);
}
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
@@ -1174,7 +1176,7 @@
if (VD->getType()->isReferenceType())
V = Builder.CreateLoad(V, "tmp");
- LValue LV = MakeAddrLValue(V, E->getType());
+ LValue LV = MakeAddrLValue(V, E->getType(), Alignment);
if (NonGCable) {
LV.getQuals().removeObjCGCAttr();
LV.setNonGC(true);
@@ -1190,7 +1192,7 @@
if (E->getQualifier()) {
const FieldDecl *FD = cast<FieldDecl>(ND);
llvm::Value *V = CGM.EmitPointerToDataMember(FD);
- return MakeAddrLValue(V, FD->getType());
+ return MakeAddrLValue(V, FD->getType(), Alignment);
}
assert(false && "Unhandled DeclRefExpr");
@@ -1201,7 +1203,9 @@
}
LValue CodeGenFunction::EmitBlockDeclRefLValue(const BlockDeclRefExpr *E) {
- return MakeAddrLValue(GetAddrOfBlockDecl(E), E->getType());
+ unsigned Alignment =
+ CGF.getContext().getDeclAlign(E->getDecl()).getQuantity();
+ return MakeAddrLValue(GetAddrOfBlockDecl(E), E->getType(), Alignment);
}
LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
@@ -1637,7 +1641,8 @@
if (Field->getType()->isReferenceType())
V = Builder.CreateLoad(V, "tmp");
- LValue LV = MakeAddrLValue(V, Field->getType());
+ unsigned Alignment = getContext().getDeclAlign(Field).getQuantity();
+ LValue LV = MakeAddrLValue(V, Field->getType(), Alignment);
LV.getQuals().addCVRQualifiers(CVRQualifiers);
// __weak attribute on a field is ignored.
@@ -1663,7 +1668,8 @@
assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
- return MakeAddrLValue(V, FieldType);
+ unsigned Alignment = getContext().getDeclAlign(Field).getQuantity();
+ return MakeAddrLValue(V, FieldType, Alignment);
}
LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E){