@@ -1067,8 +1067,7 @@ class StructAccessBase
1067
1067
1068
1068
} // end anonymous namespace
1069
1069
1070
- using RecIndicesTy =
1071
- SmallVector<std::pair<const RecordDecl *, llvm::Value *>, 8 >;
1070
+ using RecIndicesTy = SmallVector<llvm::Value *, 8 >;
1072
1071
1073
1072
static bool getGEPIndicesToField (CodeGenFunction &CGF, const RecordDecl *RD,
1074
1073
const FieldDecl *Field,
@@ -1083,7 +1082,7 @@ static bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD,
1083
1082
1084
1083
FieldNo = Layout.getLLVMFieldNo (FD);
1085
1084
if (FD == Field) {
1086
- Indices.emplace_back (std::make_pair (RD, CGF.Builder .getInt32 (FieldNo) ));
1085
+ Indices.emplace_back (CGF.Builder .getInt32 (FieldNo));
1087
1086
return true ;
1088
1087
}
1089
1088
@@ -1092,7 +1091,7 @@ static bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD,
1092
1091
if (getGEPIndicesToField (CGF, Ty->getAsRecordDecl (), Field, Indices)) {
1093
1092
if (RD->isUnion ())
1094
1093
FieldNo = 0 ;
1095
- Indices.emplace_back (std::make_pair (RD, CGF.Builder .getInt32 (FieldNo) ));
1094
+ Indices.emplace_back (CGF.Builder .getInt32 (FieldNo));
1096
1095
return true ;
1097
1096
}
1098
1097
}
@@ -1109,7 +1108,7 @@ static bool getGEPIndicesToField(CodeGenFunction &CGF, const RecordDecl *RD,
1109
1108
// / - \p FAMDecl: the \p Decl for the flexible array member. It may not be
1110
1109
// / within the top-level struct.
1111
1110
// / - \p CountDecl: must be within the same non-anonymous struct as \p FAMDecl.
1112
- llvm::Value *CodeGenFunction::EmitCountedByFieldExpr (
1111
+ llvm::Value *CodeGenFunction::EmitLoadOfCountedByField (
1113
1112
const Expr *Base, const FieldDecl *FAMDecl, const FieldDecl *CountDecl) {
1114
1113
const RecordDecl *RD = CountDecl->getParent ()->getOuterLexicalRecordContext ();
1115
1114
@@ -1136,15 +1135,15 @@ llvm::Value *CodeGenFunction::EmitCountedByFieldExpr(
1136
1135
return nullptr ;
1137
1136
}
1138
1137
1139
- llvm::Value *Zero = Builder.getInt32 (0 );
1140
1138
RecIndicesTy Indices;
1141
-
1142
1139
getGEPIndicesToField (*this , RD, CountDecl, Indices);
1140
+ if (Indices.empty ())
1141
+ return nullptr ;
1143
1142
1144
- for ( auto I = Indices.rbegin (), E = Indices. rend (); I != E; ++I)
1145
- Res = Builder.CreateInBoundsGEP (
1146
- ConvertType (QualType (I-> first ->getTypeForDecl (), 0 )), Res,
1147
- {Zero, I-> second } , " ..counted_by.gep" );
1143
+ Indices.push_back (Builder. getInt32 ( 0 ));
1144
+ Res = Builder.CreateInBoundsGEP (
1145
+ ConvertType (QualType (RD ->getTypeForDecl (), 0 )), Res,
1146
+ RecIndicesTy ( llvm::reverse (Indices)) , " ..counted_by.gep" );
1148
1147
1149
1148
return Builder.CreateAlignedLoad (ConvertType (CountDecl->getType ()), Res,
1150
1149
getIntAlign (), " ..counted_by.load" );
@@ -4108,25 +4107,25 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
4108
4107
4109
4108
// / The offset of a field from the beginning of the record.
4110
4109
static bool getFieldOffsetInBits (CodeGenFunction &CGF, const RecordDecl *RD,
4111
- const FieldDecl *FD , int64_t &Offset) {
4110
+ const FieldDecl *Field , int64_t &Offset) {
4112
4111
ASTContext &Ctx = CGF.getContext ();
4113
4112
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout (RD);
4114
4113
unsigned FieldNo = 0 ;
4115
4114
4116
- for (const Decl *D : RD->decls ()) {
4117
- if (const auto *Record = dyn_cast<RecordDecl>(D))
4118
- if (getFieldOffsetInBits (CGF, Record, FD, Offset)) {
4119
- Offset += Layout.getFieldOffset (FieldNo);
4120
- return true ;
4121
- }
4115
+ for (const FieldDecl *FD : RD->fields ()) {
4116
+ if (FD == Field) {
4117
+ Offset += Layout.getFieldOffset (FieldNo);
4118
+ return true ;
4119
+ }
4122
4120
4123
- if (const auto *Field = dyn_cast<FieldDecl>(D))
4124
- if (FD == Field) {
4121
+ QualType Ty = FD->getType ();
4122
+ if (Ty->isRecordType ())
4123
+ if (getFieldOffsetInBits (CGF, Ty->getAsRecordDecl (), Field, Offset)) {
4125
4124
Offset += Layout.getFieldOffset (FieldNo);
4126
4125
return true ;
4127
4126
}
4128
4127
4129
- if (isa<FieldDecl>(D ))
4128
+ if (!RD-> isUnion ( ))
4130
4129
++FieldNo;
4131
4130
}
4132
4131
0 commit comments