kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

sw_fallthrough.c (665B)


      1 /* A switch with deliberate fall-through: cases without a break flow into the
      2  * next case body, so the lowering must NOT insert a branch at the boundary.
      3  * volatile selector and accumulator defeat folding so the additions + the
      4  * dispatch are really emitted. Selector 2 falls through 2 -> 1 -> 0, adding
      5  * 20 + 12 + 10 = 42. Exit code 42. */
      6 int sel(int x) {
      7   volatile int acc = 0;
      8   switch (x) {
      9     case 2:
     10       acc += 20; /* fall through */
     11     case 1:
     12       acc += 12; /* fall through */
     13     case 0:
     14       acc += 10;
     15       break;
     16     default:
     17       acc = 99;
     18       break;
     19   }
     20   return acc;
     21 }
     22 int test_main(void) {
     23   volatile int x = 2;
     24   return sel(x);
     25 }