[clang] [CIR] Upstream GotoOp (PR #153701)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 14 17:26:10 PDT 2025


================
@@ -0,0 +1,203 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG
+
+int shouldNotGenBranchRet(int x) {
+  if (x > 5)
+    goto err;
+  return 0;
+err:
+  return -1;
+}
+// CIR:  cir.func dso_local @_Z21shouldNotGenBranchReti
+// CIR:    cir.if {{.*}} {
+// CIR:      cir.goto "err"
+// CIR:    }
+// CIR:  ^bb1:
+// CIR:    [[LOAD:%.*]] = cir.load [[ZERO:%.*]] : !cir.ptr<!s32i>, !s32i
----------------
andykaylor wrote:

This test is very confusing, partly because of the check names, and partly because some critical pieces are omitted. The thing being loaded here is the return value, which is either set to zero after the `if` or set to `-1` in the "err" label block which then branches to `^bb1`. Can you add more of this to the test to make it more sensible?

https://godbolt.org/z/zbY1Wv5Y5

https://github.com/llvm/llvm-project/pull/153701


More information about the cfe-commits mailing list