[clang] [CIR] Add implicit return zero handling (PR #194490)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 28 08:13:03 PDT 2026
================
@@ -0,0 +1,84 @@
+// RUN: split-file %s %t
+
+// 'main' implicitly returns 0 if it falls off the end of the function. CIR
+// must initialize the return slot to 0 in the prologue so that loading it for
+// the implicit return does not yield an undefined value.
+
+
+//--- empty_body.c
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %t/empty_body.c -o %t/empty_body.cir
+// RUN: FileCheck --input-file=%t/empty_body.cir %s --check-prefix=CIR
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %t/empty_body.c -o %t/empty_body-cir.ll
+// RUN: FileCheck --input-file=%t/empty_body-cir.ll %s --check-prefix=LLVM
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %t/empty_body.c -o %t/empty_body.ll
+// RUN: FileCheck --input-file=%t/empty_body.ll %s --check-prefix=OGCG
+
+int main(void) {
+}
+
+// CIR-LABEL: cir.func{{.*}} @main
+// CIR: %[[RET:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
+// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i
+// CIR: cir.store %[[ZERO]], %[[RET]] : !s32i, !cir.ptr<!s32i>
+// CIR: %[[LOAD:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i
+// CIR: cir.return %[[LOAD]] : !s32i
+
+// LLVM-LABEL: define{{.*}} i32 @main(
+// LLVM: %[[RET:.*]] = alloca i32
+// LLVM: store i32 0, ptr %[[RET]]
+// LLVM: %[[LOAD:.*]] = load i32, ptr %[[RET]]
+// LLVM: ret i32 %[[LOAD]]
+
+// OGCG-LABEL: define{{.*}} i32 @main(
+// OGCG: ret i32 0
+
+
+//--- nonempty_body.c
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %t/nonempty_body.c -o %t/nonempty_body.cir
+// RUN: FileCheck --input-file=%t/nonempty_body.cir %s --check-prefix=CIR2
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %t/nonempty_body.c -o %t/nonempty_body-cir.ll
+// RUN: FileCheck --input-file=%t/nonempty_body-cir.ll %s --check-prefix=LLVM2
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %t/nonempty_body.c -o %t/nonempty_body.ll
+// RUN: FileCheck --input-file=%t/nonempty_body.ll %s --check-prefix=OGCG2
----------------
xlauko wrote:
why are these LLVM2, CIR2, OGCG2?
https://github.com/llvm/llvm-project/pull/194490
More information about the cfe-commits
mailing list