@@ -193,18 +193,19 @@ TypeTranslator::addUnionDefinition(clang::RecordDecl *record,
193
193
std::string name) {
194
194
std::vector<std::shared_ptr<Field>> fields;
195
195
196
+ int anonIdField = 0 ;
196
197
for (const clang::FieldDecl *field : record->fields ()) {
197
- std::string fname = field->getNameAsString ();
198
198
std::shared_ptr<Type> ftype = translate (field->getType ());
199
199
200
+ std::string fname = field->getNameAsString ();
201
+ if (fname.empty ()) fname = " anonymous_" + std::to_string (anonIdField++);
200
202
fields.push_back (std::make_shared<Field>(fname, ftype));
201
203
}
202
204
203
205
uint64_t sizeInBits = ctx->getTypeSize (record->getTypeForDecl ());
204
206
assert (sizeInBits % 8 == 0 );
205
207
206
- return ir.addUnion (name, std::move (fields), sizeInBits / 8 ,
207
- getLocation (record));
208
+ return ir.addUnion (std::move (name), std::move (fields), sizeInBits / 8 , getLocation (record));
208
209
}
209
210
210
211
std::shared_ptr<TypeDef>
@@ -222,15 +223,17 @@ TypeTranslator::addStructDefinition(clang::RecordDecl *record,
222
223
ctx->getASTRecordLayout (record);
223
224
224
225
bool isBitFieldStruct = false ;
226
+ int anonIdField = 0 ;
225
227
for (const clang::FieldDecl *field : record->fields ()) {
226
228
if (field->isBitField ()) {
227
229
isBitFieldStruct = true ;
228
230
}
229
231
std::shared_ptr<Type> ftype = translate (field->getType ());
230
232
uint64_t recordOffsetInBits =
231
233
recordLayout.getFieldOffset (field->getFieldIndex ());
232
- fields.push_back (std::make_shared<Field>(field->getNameAsString (),
233
- ftype, recordOffsetInBits));
234
+ std::string fname = field->getNameAsString ();
235
+ if (fname.empty ()) fname = " anonymous_" + std::to_string (anonIdField++);
236
+ fields.push_back (std::make_shared<Field>(fname, ftype, recordOffsetInBits));
234
237
}
235
238
236
239
uint64_t sizeInBits = ctx->getTypeSize (record->getTypeForDecl ());
0 commit comments