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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2025-10-29

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mason from comment #2)
> Questions for WG14 & WG21 experts (all 7 of you)
> 
> Why is foo3 handled differently in C & C++ ?
> 
> Why is foo2 not equivalent to foo3 in C++ ?

It is handled differently because the front-end handles the assignments
slightly differently. No other reasons.
In the case of foo3 for C++, the C++ front-end produces:
```
  <<cleanup_point   struct s1 vv = {.f_1=0};>>;
  <<cleanup_point <<< Unknown tree: expr_stmt
    vv.f_2 = (<unnamed-unsigned:24>) u >>>>>;
  <<cleanup_point <<< Unknown tree: expr_stmt
    (void) (*NON_LVALUE_EXPR <out> = *(const struct s1 &) &vv) >>>>>;
```

While the C front-end produces:
```
    struct s1 vv = {.f_1=0, .f_2=(<unnamed-unsigned:24>) u};
  *out = vv;
```

Which gets gimplified slightly differently.
For the C++ one:
      vv = {};
      _1 = (<unnamed-unsigned:24>) u;
      vv.f_2 = _1;

While C gets:
      vv.f_1 = 0;
      _1 = (<unnamed-unsigned:24>) u;
      vv.f_2 = _1;

Which only the C++ IR here produces decent results but only on x86_64 with the
RTL optimizers.

foo3 with the C++ front-end on aarch64 produces:
```
        mov     w3, 0
        mov     w2, 0
        bfi     w2, w3, 0, 8 // still 0
        bfi     w2, w1, 8, 24 // shift really
        str     w2, [x0]
```

Reply via email to