https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117743

            Bug ID: 117743
           Summary: manually zeroing "pad" fields is worse than using
                    __builtin_clear_padding
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
struct A1 {
    char c;
    char pad[3];
    int l;
};

struct A {
    char c;
    int l;
};

A clear_padding(A x) {
  __builtin_clear_padding(&x);
  return x;
}

A clear_padding1(A x) {
  __builtin_memset(((char*)&x)+1, 0, 3);
  return x;
}


A1 clear_padding2(A1 x) {
  x.pad[0] = 0;
  x.pad[1] = 0;
  x.pad[2] = 0;
  return x;
}

```

All 3 should produce the same code.
But they don't.

note clear_padding1 is the same as PR36602.

But clear_padding2 is because store_merge does not merge the char/short store
into a char[3] store of {} which is what clear_padding produces.

Reply via email to