@@ -177,11 +177,6 @@ llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) {
177
177
Loc);
178
178
}
179
179
180
- // Helper method to check if the underlying ABI is AAPCS
181
- static bool isAAPCS (const TargetInfo &TargetInfo) {
182
- return TargetInfo.getABI ().startswith (" aapcs" );
183
- }
184
-
185
180
// / EmitIgnoredExpr - Emit code to compute the specified expression,
186
181
// / ignoring the result.
187
182
void CodeGenFunction::EmitIgnoredExpr (const Expr *E) {
@@ -4057,120 +4052,15 @@ static bool hasAnyVptr(const QualType Type, const ASTContext &Context) {
4057
4052
return false ;
4058
4053
}
4059
4054
4060
- // AAPCS requires volatile bitfield accesses to be performed using the
4061
- // natural alignment / width of the bitfield declarative type, if that
4062
- // won't cause overlap over a non-bitfield member nor access outside the
4063
- // the data structure.
4064
- bool CodeGenFunction::AdjustAAPCSBitfieldLValue (Address &Base,
4065
- CGBitFieldInfo &Info,
4066
- const FieldDecl *Field,
4067
- const QualType FieldType,
4068
- const CGRecordLayout &RL) {
4069
- llvm::Type *ResLTy = ConvertTypeForMem (FieldType);
4070
- // CGRecordLowering::setBitFieldInfo() pre-adjusts the bitfield offsets for
4071
- // big-endian targets, but it assumes a container of width Info.StorageSize.
4072
- // Since AAPCS uses a different container size (width of the type), we first
4073
- // undo that calculation here and redo it once the bitfield offset within the
4074
- // new container is calculated
4075
- const bool BE = CGM.getTypes ().getDataLayout ().isBigEndian ();
4076
- const unsigned OldOffset =
4077
- BE ? Info.StorageSize - (Info.Offset + Info.Size ) : Info.Offset ;
4078
- // Offset to the bitfield from the beginning of the struct
4079
- const unsigned AbsoluteOffset =
4080
- getContext ().toBits (Info.StorageOffset ) + OldOffset;
4081
-
4082
- // Container size is the width of the bitfield type
4083
- const unsigned ContainerSize = ResLTy->getPrimitiveSizeInBits ();
4084
- // Nothing to do if the access uses the desired
4085
- // container width and is naturally aligned
4086
- if (Info.StorageSize == ContainerSize && (OldOffset % ContainerSize == 0 ))
4087
- return false ;
4088
-
4089
- // Offset within the container
4090
- unsigned MemberOffset = AbsoluteOffset & (ContainerSize - 1 );
4091
-
4092
- // Bail out if an aligned load of the container cannot cover the entire
4093
- // bitfield. This can happen for example, if the bitfield is part of a packed
4094
- // struct. AAPCS does not define access rules for such cases, we let clang to
4095
- // follow its own rules.
4096
- if (MemberOffset + Info.Size > ContainerSize) {
4097
- return false ;
4098
- }
4099
- // Re-adjust offsets for big-endian targets
4100
- if (BE)
4101
- MemberOffset = ContainerSize - (MemberOffset + Info.Size );
4102
-
4103
- const CharUnits NewOffset =
4104
- getContext ().toCharUnitsFromBits (AbsoluteOffset & ~(ContainerSize - 1 ));
4105
- const CharUnits End = NewOffset +
4106
- getContext ().toCharUnitsFromBits (ContainerSize) -
4107
- CharUnits::One ();
4108
-
4109
- const ASTRecordLayout &Layout =
4110
- getContext ().getASTRecordLayout (Field->getParent ());
4111
- // If we access outside memory outside the record, than bail out
4112
- const CharUnits RecordSize = Layout.getSize ();
4113
- if (End >= RecordSize) {
4114
- return false ;
4115
- }
4116
-
4117
- // Bail out if performing this load would access non-bitfields members
4118
-
4119
- for (auto it : Field->getParent ()->fields ()) {
4120
- const FieldDecl &F = *it;
4121
- // We distinct allow bitfields overlaps
4122
- if (F.isBitField ())
4123
- continue ;
4124
- const CharUnits FOffset = getContext ().toCharUnitsFromBits (
4125
- Layout.getFieldOffset (F.getFieldIndex ()));
4126
- const CharUnits FEnd =
4127
- FOffset +
4128
- getContext ().toCharUnitsFromBits (
4129
- ConvertTypeForMem (F.getType ())->getPrimitiveSizeInBits ()) -
4130
- CharUnits::One ();
4131
- if (End < FOffset) {
4132
- // The other field starts after the desired load end.
4133
- break ;
4134
- }
4135
- if (FEnd < NewOffset) {
4136
- // The other field ends before the desired load offset.
4137
- continue ;
4138
- }
4139
- // The desired load overlaps a non-bitfiel member, bail out.
4140
- return false ;
4141
- }
4142
-
4143
- // Write the new bitfield access parameters
4144
- Info.StorageOffset = NewOffset;
4145
- Info.StorageSize = ContainerSize;
4146
- Info.Offset = MemberOffset;
4147
- // GEP into the bitfield container. Here we essentially treat the Base as a
4148
- // pointer to a block of containers and index into it appropriately
4149
- Base =
4150
- Builder.CreateConstInBoundsGEP (Builder.CreateElementBitCast (Base, ResLTy),
4151
- AbsoluteOffset / ContainerSize);
4152
- return true ;
4153
- }
4154
-
4155
4055
LValue CodeGenFunction::EmitLValueForField (LValue base,
4156
4056
const FieldDecl *field) {
4157
4057
LValueBaseInfo BaseInfo = base.getBaseInfo ();
4158
4058
4159
4059
if (field->isBitField ()) {
4160
4060
const CGRecordLayout &RL =
4161
- CGM.getTypes ().getCGRecordLayout (field->getParent ());
4162
- CGBitFieldInfo Info = RL.getBitFieldInfo (field);
4061
+ CGM.getTypes ().getCGRecordLayout (field->getParent ());
4062
+ const CGBitFieldInfo & Info = RL.getBitFieldInfo (field);
4163
4063
Address Addr = base.getAddress (*this );
4164
- const QualType FieldType =
4165
- field->getType ().withCVRQualifiers (base.getVRQualifiers ());
4166
-
4167
- if (isAAPCS (CGM.getTarget ()) && FieldType.isVolatileQualified ()) {
4168
- if (AdjustAAPCSBitfieldLValue (Addr, Info, field, FieldType, RL)) {
4169
- return LValue::MakeBitfield (Addr, Info, FieldType, BaseInfo,
4170
- TBAAAccessInfo ());
4171
- }
4172
- }
4173
-
4174
4064
unsigned Idx = RL.getLLVMFieldNo (field);
4175
4065
const RecordDecl *rec = field->getParent ();
4176
4066
if (!IsInPreservedAIRegion &&
@@ -4192,9 +4082,11 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
4192
4082
if (Addr.getElementType () != FieldIntTy)
4193
4083
Addr = Builder.CreateElementBitCast (Addr, FieldIntTy);
4194
4084
4085
+ QualType fieldType =
4086
+ field->getType ().withCVRQualifiers (base.getVRQualifiers ());
4195
4087
// TODO: Support TBAA for bit fields.
4196
4088
LValueBaseInfo FieldBaseInfo (BaseInfo.getAlignmentSource ());
4197
- return LValue::MakeBitfield (Addr, Info, FieldType , FieldBaseInfo,
4089
+ return LValue::MakeBitfield (Addr, Info, fieldType , FieldBaseInfo,
4198
4090
TBAAAccessInfo ());
4199
4091
}
4200
4092
0 commit comments