kit

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

6_5_13b_logical_or_in_if.c (847B)


      1 /* `||` and `&&` results must remain coherent when consumed by control
      2  * flow. Earlier the merge of the short-circuit arms left two values on
      3  * the cg abstract stack instead of one, so `if (a || b)` always entered
      4  * the body and `if (a && b)` always skipped it, regardless of operands. */
      5 int test_main(void) {
      6   int a = 0, b = 0;
      7   if (a || b) return 1; /* 0 || 0 → false; must skip */
      8   if (!(a || (b = 1))) return 2;
      9   if (b != 1) return 3; /* short-circuit right side did run */
     10 
     11   int c = 1, d = 0;
     12   if (c && d) return 4; /* 1 && 0 → false; must skip */
     13   if (!(c && (d = 7))) return 5;
     14   if (d != 7) return 6;
     15 
     16   /* Nested with `!` — the failing test/libc shape. */
     17   const char* msg = "hi";
     18   if (!msg || !*msg) return 7;
     19 
     20   /* Constant-folded paths still work. */
     21   if (!(1 || 0)) return 8;
     22   if (0 && 1) return 9;
     23   return 0;
     24 }