[CodeGen] Don't crash on for loops with cond variables and no increment

This looks like an oversight from a875721d8a, creating IR that refers
to `for.inc` even if it doesn't exist.

Differential Revision: https://reviews.llvm.org/D98980
This commit is contained in:
Benjamin Kramer 2021-03-19 20:35:17 +01:00
parent 9d081a7ffe
commit 19d2c65ddd
2 changed files with 14 additions and 1 deletions

View file

@ -992,7 +992,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
// We have entered the condition variable's scope, so we're now able to
// jump to the continue block.
Continue = getJumpDestInCurrentScope("for.inc");
Continue = S.getInc() ? getJumpDestInCurrentScope("for.inc") : CondDest;
BreakContinueStack.back().ContinueBlock = Continue;
}

View file

@ -123,3 +123,16 @@ void PR49585_break() {
// CHECK [[for_end]]:
// CHECK: ret void
}
// CHECK: define {{.*}} void @_Z16incless_for_loopv(
void incless_for_loop() {
// CHECK: br label %[[for_cond:.*]]
// CHECK: [[for_cond]]:
// CHECK: br i1 {{.*}}, label %[[for_body:.*]], label %[[for_end:.*]]
// CHECK: [[for_body]]:
// CHECK: br label %[[for_cond]]
// CHECK: [[for_end]]:
// CHECK: ret void
// CHECK: }
for (; int b = 0;) continue;
}