[CIR] Implement ImplicitValueInitExpr for ComplexType - #183836
Merged
AmrDeveloper merged 2 commits intoFeb 28, 2026
Merged
Conversation
AmrDeveloper
requested review from
andykaylor,
bcardosolopes,
lanza and
xlauko
as code owners
February 27, 2026 21:24
Member
|
@llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesImplement ImplicitValueInitExpr for ComplexType Full diff: https://github.com/llvm/llvm-project/pull/183836.diff 2 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index b909623aa662b..e8d7e7e1427c9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -223,9 +223,9 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
return builder.getNullValue(complexTy, loc);
}
mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
- cgf.cgm.errorNYI(e->getExprLoc(),
- "ComplexExprEmitter VisitImplicitValueInitExpr");
- return {};
+ mlir::Location loc = cgf.getLoc(e->getExprLoc());
+ mlir::Type complexTy = cgf.convertType(e->getType());
+ return builder.getNullValue(complexTy, loc);
}
struct BinOpInfo {
diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
index ad9f430411fba..1fa26fdc47a8c 100644
--- a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
+++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
@@ -33,3 +33,28 @@ void test(void *p) {
// OGCG-NEXT: %[[P1:.*]] = load ptr, ptr %[[P]], align 8
// OGCG-NEXT: store i32 0, ptr %[[P1]], align 4
// OGCG-NEXT: ret void
+
+void test_complex(void *p) { new (p) int _Complex(); }
+
+// CIR: cir.func{{.*}} @_Z12test_complexPv
+// CIR: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["p", init]
+// CIR: cir.store %[[ARG_0:.*]], %[[P_ADDR:.*]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
+// CIR: %[[TMP_P:.*]] = cir.load {{.*}} %[[P_ADDR]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
+// CIR: %[[P_COMPLEX:.*]] = cir.cast bitcast %[[TMP_P:.*]] : !cir.ptr<!void> -> !cir.ptr<!cir.complex<!s32i>>
+// CIR: %[[CONST_0:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
+// CIR: cir.store {{.*}} %[[CONST_0]], %[[P_COMPLEX]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
+
+// LLVM: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// LLVM: %[[P_ADDR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// LLVM: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// LLVM: store { i32, i32 } zeroinitializer, ptr %[[TMP_P]], align 4
+
+// OGCG: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// OGCG: %[[P_ADDR:.*]] = alloca ptr, align 8
+// OGCG: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// OGCG: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// OGCG: %[[P_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 0
+// OGCG: %[[P_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 1
+// OGCG: store i32 0, ptr %[[P_REAL_PTR]], align 4
+// OGCG: store i32 0, ptr %[[P_IMAG_PTR]], align 4
|
Member
|
@llvm/pr-subscribers-clangir Author: Amr Hesham (AmrDeveloper) ChangesImplement ImplicitValueInitExpr for ComplexType Full diff: https://github.com/llvm/llvm-project/pull/183836.diff 2 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index b909623aa662b..e8d7e7e1427c9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -223,9 +223,9 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
return builder.getNullValue(complexTy, loc);
}
mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
- cgf.cgm.errorNYI(e->getExprLoc(),
- "ComplexExprEmitter VisitImplicitValueInitExpr");
- return {};
+ mlir::Location loc = cgf.getLoc(e->getExprLoc());
+ mlir::Type complexTy = cgf.convertType(e->getType());
+ return builder.getNullValue(complexTy, loc);
}
struct BinOpInfo {
diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
index ad9f430411fba..1fa26fdc47a8c 100644
--- a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
+++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
@@ -33,3 +33,28 @@ void test(void *p) {
// OGCG-NEXT: %[[P1:.*]] = load ptr, ptr %[[P]], align 8
// OGCG-NEXT: store i32 0, ptr %[[P1]], align 4
// OGCG-NEXT: ret void
+
+void test_complex(void *p) { new (p) int _Complex(); }
+
+// CIR: cir.func{{.*}} @_Z12test_complexPv
+// CIR: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["p", init]
+// CIR: cir.store %[[ARG_0:.*]], %[[P_ADDR:.*]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
+// CIR: %[[TMP_P:.*]] = cir.load {{.*}} %[[P_ADDR]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
+// CIR: %[[P_COMPLEX:.*]] = cir.cast bitcast %[[TMP_P:.*]] : !cir.ptr<!void> -> !cir.ptr<!cir.complex<!s32i>>
+// CIR: %[[CONST_0:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
+// CIR: cir.store {{.*}} %[[CONST_0]], %[[P_COMPLEX]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
+
+// LLVM: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// LLVM: %[[P_ADDR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// LLVM: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// LLVM: store { i32, i32 } zeroinitializer, ptr %[[TMP_P]], align 4
+
+// OGCG: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// OGCG: %[[P_ADDR:.*]] = alloca ptr, align 8
+// OGCG: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// OGCG: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// OGCG: %[[P_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 0
+// OGCG: %[[P_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 1
+// OGCG: store i32 0, ptr %[[P_REAL_PTR]], align 4
+// OGCG: store i32 0, ptr %[[P_IMAG_PTR]], align 4
|
andykaylor
approved these changes
Feb 27, 2026
andykaylor
left a comment
Contributor
There was a problem hiding this comment.
lgtm, with one minor suggestion
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
AmrDeveloper
force-pushed
the
cir_complex_implict_value_init
branch
from
February 28, 2026 14:29
8f84e76 to
2249a38
Compare
sahas3
pushed a commit
to sahas3/llvm-project
that referenced
this pull request
Mar 4, 2026
Implement ImplicitValueInitExpr for ComplexType
sujianIBM
pushed a commit
to sujianIBM/llvm-project
that referenced
this pull request
Mar 5, 2026
Implement ImplicitValueInitExpr for ComplexType
This was referenced Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement ImplicitValueInitExpr for ComplexType