[clang] [Clang] Handle structs with inner structs and no fields (PR #89126)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 18 13:33:47 PDT 2024


================
@@ -844,7 +847,18 @@ const FieldDecl *CodeGenFunction::FindFlexibleArrayMemberField(
       if (const FieldDecl *Field =
----------------
efriedma-quic wrote:

>  if there's an inner struct that's not accessible, that doesn't affect the offsets of fields outside of that inner struct.

Yes, the only thing that's relevant to offsets in a struct is the fields.  A struct declaration inside another struct declaration has exactly the same semantics as a struct definition anywhere else (unless it's an anonymous struct/union).

----

Maybe also try the following testcase.

```
struct foo {
  int x,y,z;
  struct bar {
    int count;
    int array[] __attribute__((counted_by(count)));
  };
};
void init(void * __attribute__((pass_dynamic_object_size(0))));
void test1(struct bar *p) {
  init(p->array);
}
```

https://github.com/llvm/llvm-project/pull/89126


More information about the cfe-commits mailing list