<div dir="ltr"><div>I'm trying to implement a continue statement like in C</div><div><br></div><div>                if (i % 2 == 0)<br>                {<br>                    i = i + 1;<br>                    continue;<br>                }<br>                else<br>                {<br>                    i = i + 1;<br>                }</div><div><br></div><div>My code generates IR like this, because of how I visit my AST, so when I encounter a continue or break statement I go and find the corresponding while.</div><div><br></div><div>I was hoping LLVM would do the right thing which is ignore the unreachable IR (br label %if.end). But it seems to somehow get to execute statements after my br<br></div><p>I've marked it with "SHOULD NOT HAPPEN"</p><div>define i32 @Main() {<br>entry:<br>  %i = alloca i32<br>  %loopCounter = alloca i32<br>  store i32 0, i32* %i<br>  store i32 0, i32* %loopCounter<br>  br label %while.cond</div><div>while.cond:                                       ; preds = %if.end, %if.then, %<br>entry<br>  %0 = load i32* %i<br>  %cmptmp = icmp slt i32 %0, 100<br>  br i1 %cmptmp, label %while.body, label %while.end</div><div>while.body:                                       ; preds = %while.cond<br>  %1 = load i32* %i<br>  %modtmp = srem i32 %1, 2<br>  %cmptmp1 = icmp eq i32 %modtmp, 0<br>  br i1 %cmptmp1, label %if.then, label %if.else</div><div>while.end:                                        ; preds = %while.cond<br>  %2 = load i32* %loopCounter<br>  ret i32 %2</div><div>if.then:                                          ; preds = %while.body<br>  %3 = load i32* %i<br>  %add = add i32 %3, 1<br>  store i32 %add, i32* %i<br>  br label %while.cond<br>  %4 = load i32* %I                      <----------- SHOULD NOT HAPPEN<br>  %sub = sub i32 %4, 1<br>  store i32 %sub, i32* %i<br>  br label %if.end</div><div>if.else:                                          ; preds = %while.body<br>  %5 = load i32* %i<br>  %add2 = add i32 %5, 1<br>  store i32 %add2, i32* %i<br>  br label %if.end</div><div>if.end:                                           ; preds = %if.else, %if.then<br>  %6 = load i32* %loopCounter<br>  %add3 = add i32 %6, 1<br>  store i32 %add3, i32* %loopCounter<br>  br label %while.cond</div><div>after_ret:                                        ; No predecessors!<br>  ret i32 0<br>}</div></div>