================
@@ -265,3 +265,125 @@ void test_empty_while_true() {
 // OGCG:   br label %[[WHILE_BODY:.*]]
 // OGCG: [[WHILE_BODY]]:
 // OGCG:   ret void
+
+void unreachable_after_continue() {
+  for (;;) {
+    continue;
+    int x = 1;
+  }
+}
+
+// CIR: cir.func @unreachable_after_continue
+// CIR:   cir.scope {
+// CIR:     cir.for : cond {
+// CIR:       %[[TRUE:.*]] = cir.const #true
+// CIR:       cir.condition(%[[TRUE]])
+// CIR:     } body {
+// CIR:       cir.scope {
+// CIR:         %[[X:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] 
{alignment = 4 : i64}
+// CIR:         cir.continue
+// CIR:       ^bb1:  // no predecessors
+// CIR:         %[[ONE:.*]] = cir.const #cir.int<1> : !s32i
+// CIR:         cir.store %[[ONE]], %[[X]] : !s32i, !cir.ptr<!s32i>
+// CIR:         cir.yield
+// CIR:       }
+// CIR:       cir.yield
+// CIR:     } step {
+// CIR:       cir.yield
+// CIR:     }
+// CIR:   }
+// CIR:   cir.return
+// CIR: }
+
+// LLVM: define void @unreachable_after_continue()
----------------
andykaylor wrote:

Yeah, this is a bit messy. This is the result of "flattening" the CIR above and 
then transcribing that directly to LLVM IR. Each region ends up getting its own 
block, and the explicit `cir.scope` gets a different block than its implicit 
parent region. So, the unlabeled entry block is the function parent region. 
LABEL1 corresponds to the `cir.scope` on line 277 (and is where the 
initialization would happen). LABEL2 corresponds to the `cir.cond` region of 
the for loop. LABEL3 is the "step" region. LABEL4 is the entry to the for-loop 
body. LABEL5 is the portion of the body below the `continue` statement. LABEL6 
is where the `cir.yield` on line 288 jumps. LABEL7 is the `cir.yield` statement 
on line 290. LABEL8 is the portion of the `cir.scope` below the loop (i.e. line 
294). And label is the part of the function region below the explicit 
`cir.scope`.

It would make a bit more sense if most of these regions weren't empty. Ideally, 
we'd not cleaning all this up in the CIRCanonicalize pass. but I think right 
now that gets run before CIR flattening. That's something we should revisit.

https://github.com/llvm/llvm-project/pull/134181
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to