boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

334-struct-assign-rval-rhs.c (1160B)


      1 /* Regression: struct `=` rhs may be a struct *rvalue* (frame opnd
      2  * with lval? = #f), not just an lvalue. The comma operator forces
      3  * rval! on its right-hand subexpression, so `y = (e, s);` lands a
      4  * struct rvalue on the vstack as the rhs of cg-assign-struct.
      5  *
      6  * Before the addr-of-any fix, cg-assign-struct used %cg-emit-addr-of
      7  * which dies on any non-lvalue, so cc.scm aborted with
      8  * "cg-emit-addr-of: not an lvalue" before emitting any code. The
      9  * fix routes the src through %cg-emit-addr-of-any, which computes
     10  * the address of a frame slot regardless of the lval flag.
     11  *
     12  * Struct kept ≤ 8 bytes so the underlying cg-load-on-struct
     13  * truncation (separate bug) doesn't mask the addr-of regression
     14  * with a wrong-bytes failure.
     15  */
     16 
     17 struct Pair { int a; int b; };
     18 
     19 static int side_effect(int x) { return x; }
     20 
     21 int main(int argc, char **argv) {
     22     struct Pair a;
     23     struct Pair y;
     24     a.a = 11; a.b = 22;
     25     /* Comma operator: lhs `side_effect(0)` is discarded, rhs `a`
     26      * is rval!'d into a struct rvalue, then assigned to `y`. */
     27     y = (side_effect(0), a);
     28     if (y.a != 11) return 1;
     29     if (y.b != 22) return 2;
     30     return 0;
     31 }