[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:41:46 PDT 2021


bkramer created this revision.
bkramer added reviewers: rupprecht, rjmccall, rsmith.
bkramer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This looks like an oversight from a875721d8a2d <https://reviews.llvm.org/rGa875721d8a2dacb894106a2cefa18828bf08f25d>, creating IR that refers
to `for.inc` even if it doesn't exist.


Repository:
  rG LLVM Github Monorepo

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.331980.patch
Type: text/x-patch
Size: 1173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210319/71b11c98/attachment.bin>


More information about the cfe-commits mailing list