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

Benjamin Kramer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 19 12:48:10 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG19d2c65ddd75: [CodeGen] Don't crash on for loops with cond variables and no increment (authored by bkramer).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98980/new/

https://reviews.llvm.org/D98980

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGenCXX/for-cond-var.cpp


Index: clang/test/CodeGenCXX/for-cond-var.cpp
===================================================================
--- clang/test/CodeGenCXX/for-cond-var.cpp
+++ clang/test/CodeGenCXX/for-cond-var.cpp
@@ -123,3 +123,16 @@
   // 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;
+}
Index: clang/lib/CodeGen/CGStmt.cpp
===================================================================
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -992,7 +992,7 @@
 
       // 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;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98980.331983.patch
Type: text/x-patch
Size: 1173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210319/be633e42/attachment-0001.bin>


More information about the cfe-commits mailing list