aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <5993918+bwendling@users.noreply.github.com>2024-04-19 14:38:17 -0700
committerGitHub <noreply@github.com>2024-04-19 21:38:17 +0000
commit5bcf31ebfad8b32aed20dd47be6238cc19710e63 (patch)
treed00f2eca422a6fccd43c09735909a024199b2987
parent45432eec0ae6a7f7452196eb099814d1a7dc2c0f (diff)
downloadllvm-5bcf31ebfad8b32aed20dd47be6238cc19710e63.zip
llvm-5bcf31ebfad8b32aed20dd47be6238cc19710e63.tar.gz
llvm-5bcf31ebfad8b32aed20dd47be6238cc19710e63.tar.bz2
[Clang] Loop over FieldDecls instead of all Decls (#89453)
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.
-rw-r--r--clang/lib/CodeGen/CGBuiltin.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 4319501..4ab844d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -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;