[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)
Bill Wendling via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 8 12:54:49 PST 2024
================
@@ -1155,15 +1159,14 @@ const FieldDecl *CodeGenFunction::FindCountedByField(const FieldDecl *FD) {
return nullptr;
auto GetNonAnonStructOrUnion = [](const RecordDecl *RD) {
- while (RD && !RD->getDeclName())
- if (const auto *R = dyn_cast<RecordDecl>(RD->getDeclContext()))
- RD = R;
- else
+ while (RD && RD->isAnonymousStructOrUnion()) {
+ const auto *R = dyn_cast<RecordDecl>(RD->getDeclContext());
+ if (!R)
----------------
bwendling wrote:
I think you could have:
```
int foo(void) {
struct {
int a, b;
} x;
...
}
```
Though in the case of a struct with a flexible array member, probably not. Then again, you might be able to do this:
```
int foo(void) {
struct {
int count;
int array[] __counted_by(count);
} x = { 3 };
...
}
```
I just didn't want to make any assumptions. I can make this an assert if you'd like.
https://github.com/llvm/llvm-project/pull/76348
More information about the cfe-commits
mailing list