[clang] [CIR][CodeGen] Implement VisitImplicitValueInitExpr in CIRGenExprScalar.cpp (PR #182256)
Gauravsingh Sisodia via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 24 09:37:10 PST 2026
https://github.com/xaerru updated https://github.com/llvm/llvm-project/pull/182256
>From 782bdc8c87946c15eea9b819343e9574c848a6da Mon Sep 17 00:00:00 2001
From: Gauravsingh Sisodia <xaerru at gmail.com>
Date: Thu, 19 Feb 2026 12:14:11 +0000
Subject: [PATCH 1/2] [CIR][CodeGen] Implement VisitImplicitValueInitExpr in
CIRGenExprScalar.cpp
---
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 2c5a57e1ba2ee..3d51a5c7e1979 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -420,9 +420,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
}
mlir::Value VisitImplicitValueInitExpr(const ImplicitValueInitExpr *e) {
- cgf.cgm.errorNYI(e->getSourceRange(),
- "ScalarExprEmitter: implicit value init");
- return {};
+ return emitNullValue(e->getType(), cgf.getLoc(e->getSourceRange()));
}
mlir::Value VisitExplicitCastExpr(ExplicitCastExpr *e) {
>From 1dbc21f0acaf615290f3b3eab52c28e134dd8931 Mon Sep 17 00:00:00 2001
From: Gauravsingh Sisodia <xaerru at gmail.com>
Date: Tue, 24 Feb 2026 17:34:20 +0000
Subject: [PATCH 2/2] [CIR][CodeGen] Add test for VisitImplicitValueInitExpr
---
.../CIR/CodeGen/implicit-value-init-expr.cpp | 35 +++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
new file mode 100644
index 0000000000000..ad9f430411fba
--- /dev/null
+++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
@@ -0,0 +1,35 @@
+// 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 -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// 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
+
+void* operator new(__SIZE_TYPE__, void* p) noexcept { return p; }
+
+void test(void *p) {
+ new (p) int();
+}
+
+// CIR: cir.func{{.*}} @_Z4testPv
+// CIR-NEXT: %[[P:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["p", init] {alignment = 8 : i64}
+// CIR-NEXT: cir.store %arg0, %[[P]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
+// CIR-NEXT: %[[P1:.*]] = cir.load align(8) %[[P]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
+// CIR-NEXT: %[[P2:.*]] = cir.cast bitcast %[[P1]] : !cir.ptr<!void> -> !cir.ptr<!s32i>
+// CIR-NEXT: %[[P3:.*]] = cir.const #cir.int<0> : !s32i
+// CIR-NEXT: cir.store align(4) %[[P3]], %[[P2]] : !s32i, !cir.ptr<!s32i>
+
+// LLVM: define{{.*}} void @_Z4testPv(ptr{{.*}} %[[ARG:.*]])
+// LLVM-NEXT: %[[P:.*]] = alloca ptr, i64 1, align 8
+// LLVM-NEXT: store ptr %[[ARG]], ptr %[[P]], align 8
+// LLVM-NEXT: %[[P1:.*]] = load ptr, ptr %[[P]], align 8
+// LLVM-NEXT: store i32 0, ptr %[[P1]], align 4
+// LLVM-NEXT: ret void
+
+// OGCG: define{{.*}} void @_Z4testPv(ptr{{.*}} %[[ARG:.*]])
+// OGCG-NEXT: {{.*}}:
+// OGCG-NEXT: %[[P:.*]] = alloca ptr, align 8
+// OGCG-NEXT: store ptr %[[ARG]], ptr %[[P]], align 8
+// OGCG-NEXT: %[[P1:.*]] = load ptr, ptr %[[P]], align 8
+// OGCG-NEXT: store i32 0, ptr %[[P1]], align 4
+// OGCG-NEXT: ret void
More information about the cfe-commits
mailing list