[PATCH] D151076: [IRGen] Handle infinite cycles in findDominatingStoreToReturnValue.

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 12:17:04 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0687b47a0ce: [IRGen] Handle infinite cycles in findDominatingStoreToReturnValue. (authored by fhahn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151076

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/dominating-store-infinite-cycle.c


Index: clang/test/CodeGen/dominating-store-infinite-cycle.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/dominating-store-infinite-cycle.c
@@ -0,0 +1,33 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s
+
+// Test for PR62830 where there are 2 infinite cycles using goto. Make sure
+// clang codegen doesn't hang.
+int a;
+
+// CHECK-LABEL: define dso_local i32 @main
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
+// CHECK-NEXT:    store i32 0, ptr [[RETVAL]], align 4
+// CHECK-NEXT:    br label [[L1:%.*]]
+// CHECK:       L1:
+// CHECK-NEXT:    br label [[L1]]
+// CHECK:       L2:
+// CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr @a, align 4
+// CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[TMP0]], 0
+// CHECK-NEXT:    br i1 [[TOBOOL]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
+// CHECK:       if.then:
+// CHECK-NEXT:    br label [[L2:%.*]]
+// CHECK:       if.end:
+// CHECK-NEXT:    [[TMP1:%.*]] = load i32, ptr [[RETVAL]], align 4
+// CHECK-NEXT:    ret i32 [[TMP1]]
+//
+int main() {
+L1:
+  goto L1;
+
+L2:
+  if (!a)
+    goto L2;
+}
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3461,8 +3461,9 @@
   // single-predecessors chain from the current insertion point.
   llvm::BasicBlock *StoreBB = store->getParent();
   llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock();
+  llvm::SmallPtrSet<llvm::BasicBlock *, 4> SeenBBs;
   while (IP != StoreBB) {
-    if (!(IP = IP->getSinglePredecessor()))
+    if (!SeenBBs.insert(IP).second || !(IP = IP->getSinglePredecessor()))
       return nullptr;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151076.525290.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/f5795679/attachment-0001.bin>


More information about the cfe-commits mailing list