@@ -1106,48 +1106,35 @@ struct SubobjectFinder
11061106
11071107} // end anonymous namespace
11081108
1109- /// getFieldInfo - Gather the size and offset of the field \p VD in \p RD.
1110- static std::pair<uint64_t, uint64_t> getFieldInfo(CodeGenFunction &CGF,
1111- const RecordDecl *RD,
1112- const ValueDecl *VD,
1113- uint64_t Offset = 0) {
1109+ /// getFieldInfo - Gather the size of the field \p VD in \p RD.
1110+ static uint64_t getFieldInfo(CodeGenFunction &CGF, const RecordDecl *RD,
1111+ const ValueDecl *VD) {
11141112 if (!RD)
1115- return std::make_pair(0, 0) ;
1113+ return 0 ;
11161114
11171115 ASTContext &Ctx = CGF.getContext();
1118- const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(RD);
1119- unsigned FieldNo = 0;
11201116
11211117 for (const Decl *D : RD->decls()) {
11221118 if (const auto *Record = dyn_cast<RecordDecl>(D)) {
1123- std::pair<uint64_t, uint64_t> Res =
1124- getFieldInfo(CGF, Record->getDefinition(), VD,
1125- Offset + Layout.getFieldOffset(FieldNo));
1126- if (Res.first != 0)
1119+ uint64_t Res = getFieldInfo(CGF, Record->getDefinition(), VD);
1120+ if (Res != 0)
11271121 return Res;
11281122 continue;
11291123 }
11301124
1131- if (const auto *FD = dyn_cast<FieldDecl>(D); FD == VD) {
1132- Offset += Layout.getFieldOffset(FieldNo);
1133- return std::make_pair(Ctx.getTypeSizeInChars(FD->getType()).getQuantity(),
1134- Ctx.toCharUnitsFromBits(Offset).getQuantity());
1135- }
1136-
1137- if (isa<FieldDecl>(D))
1138- ++FieldNo;
1125+ if (const auto *FD = dyn_cast<FieldDecl>(D); FD == VD)
1126+ return Ctx.getTypeSizeInChars(FD->getType()).getQuantity();
11391127 }
11401128
1141- return std::make_pair(0, 0) ;
1129+ return 0 ;
11421130}
11431131
11441132/// getSubobjectInfo - Find the sub-object that \p E points to. If it lives
11451133/// inside a struct, return the "size" and "offset" of that sub-object.
1146- static std::pair<uint64_t, uint64_t> getSubobjectInfo(CodeGenFunction &CGF,
1147- const Expr *E) {
1134+ static uint64_t getSubobjectInfo(CodeGenFunction &CGF, const Expr *E) {
11481135 const Expr *Subobject = SubobjectFinder().Visit(E);
11491136 if (!Subobject)
1150- return std::make_pair(0, 0) ;
1137+ return 0 ;
11511138
11521139 const RecordDecl *OuterRD = nullptr;
11531140 const ValueDecl *VD = nullptr;
@@ -1172,12 +1159,12 @@ static std::pair<uint64_t, uint64_t> getSubobjectInfo(CodeGenFunction &CGF,
11721159 //
11731160 // In that case, we want the size of the whole struct. So we don't have to
11741161 // worry about finding a suboject.
1175- return std::make_pair(0, 0) ;
1162+ return 0 ;
11761163 }
11771164
11781165 if (!VD || !OuterRD)
11791166 // The expression is referencing an object that's not in a struct.
1180- return std::make_pair(0, 0) ;
1167+ return 0 ;
11811168
11821169 return getFieldInfo(CGF, OuterRD->getDefinition(), VD);
11831170}
@@ -1223,8 +1210,7 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type,
12231210 if (Type == 3 || (!EmittedE && E->HasSideEffects(getContext())))
12241211 return getDefaultBuiltinObjectSizeResult(Type, ResType);
12251212
1226- std::pair<Value *, Value *> SubobjectInfo =
1227- std::make_pair(Builder.getInt64(0), Builder.getInt64(0));
1213+ Value *SubobjectSize = Builder.getInt64(0);
12281214
12291215 if (IsDynamic) {
12301216 // Emit special code for a flexible array member with the "counted_by"
@@ -1236,10 +1222,9 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type,
12361222 // The object size is constrained to the sub-object containing the
12371223 // element. If it's in a structure, get the size and offset information
12381224 // for back-end processing.
1239- std::pair<uint64_t, uint64_t> Info = getSubobjectInfo(*this, E);
1240- if (Info.first != 0)
1241- SubobjectInfo = std::make_pair(Builder.getInt64(Info.first),
1242- Builder.getInt64(Info.second));
1225+ uint64_t Info = getSubobjectInfo(*this, E);
1226+ if (Info != 0)
1227+ SubobjectSize = Builder.getInt64(Info);
12431228 }
12441229 }
12451230
@@ -1260,7 +1245,7 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, unsigned Type,
12601245 // pointer points to.
12611246 Value *WholeObj = Builder.getInt1((Type & 1) == 0);
12621247 return Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic, WholeObj,
1263- SubobjectInfo.first, SubobjectInfo.second });
1248+ SubobjectSize });
12641249}
12651250
12661251namespace {
0 commit comments