Author: Benjamin Kramer Date: 2021-03-19T20:43:52+01:00 New Revision: 19d2c65ddd757997785163709800f837857f686d
URL: https://github.com/llvm/llvm-project/commit/19d2c65ddd757997785163709800f837857f686d DIFF: https://github.com/llvm/llvm-project/commit/19d2c65ddd757997785163709800f837857f686d.diff LOG: [CodeGen] Don't crash on for loops with cond variables and no increment This looks like an oversight from a875721d8a2d, creating IR that refers to `for.inc` even if it doesn't exist. Differential Revision: https://reviews.llvm.org/D98980 Added: Modified: clang/lib/CodeGen/CGStmt.cpp clang/test/CodeGenCXX/for-cond-var.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index 6461e2011216..38f3aa941415 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -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; } diff --git a/clang/test/CodeGenCXX/for-cond-var.cpp b/clang/test/CodeGenCXX/for-cond-var.cpp index 45b4a82cb905..60e54d4141f7 100644 --- a/clang/test/CodeGenCXX/for-cond-var.cpp +++ b/clang/test/CodeGenCXX/for-cond-var.cpp @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits