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

            Bug ID: 121357
           Summary: Bad codegen when generically 1-filling a struct in C
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pskocik at gmail dot com
  Target Milestone: ---

I tried having

#define filled$(Tp_t) (*(typeof(Tp_t)*)memset(&(Tp_t){0},255,sizeof(Tp_t)))

for generically filling (to all bits 1) a struct in C. I tested it on

struct it { unsigned long x[1]; };
void takeit(struct it X);
void wanted_codegen(void){ takeit((struct it){-1ul}); }
void wanted_ccode(void){ takeit(filled$(struct it)); }
struct it2 { unsigned long x[2]; };
void takeit2(struct it2 X);
void wanted_codegen2(void){ takeit2((struct it2){-1ul,-1ul}); }
void wanted_ccode2(void){ takeit2(filled$(struct it2)); }

On clang, the wanted codegen matches the one rendered for the wanted c-code.
On gcc, however, the code generated for the wanted c-code spills the struct to
the stack (which also blocks tailcalling).

https://godbolt.org/z/xvTPEToh3

Could this be fixed please?

Reply via email to