Skip to content

Commit

Permalink
[Clang] Loop over FieldDecls instead of all Decls (#89453)
Browse files Browse the repository at this point in the history
Only FieldDecls are of importance here. A struct defined within another
struct has the same semantics as if it were defined outside of the
struct. So there's no need to look into RecordDecls that aren't a field.
  • Loading branch information
bwendling committed Apr 19, 2024
1 parent 45432ee commit 5bcf31e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,13 @@ const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField(
static unsigned CountCountedByAttrs(const RecordDecl *RD) {
unsigned Num = 0;

for (const Decl *D : RD->decls()) {
if (const auto *FD = dyn_cast<FieldDecl>(D);
FD && FD->getType()->isCountAttributedType()) {
for (const FieldDecl *FD : RD->fields()) {
if (FD->getType()->isCountAttributedType())
return ++Num;
}

if (const auto *Rec = dyn_cast<RecordDecl>(D))
Num += CountCountedByAttrs(Rec);
QualType Ty = FD->getType();
if (Ty->isRecordType())
Num += CountCountedByAttrs(Ty->getAsRecordDecl());
}

return Num;
Expand Down

0 comments on commit 5bcf31e

Please sign in to comment.