Skip to content

[CIR] Implement ImplicitValueInitExpr for ComplexType - #183836

Merged
AmrDeveloper merged 2 commits into
llvm:mainfrom
AmrDeveloper:cir_complex_implict_value_init
Feb 28, 2026
Merged

AmrDeveloper merged 2 commits into
llvm:mainfrom
AmrDeveloper:cir_complex_implict_value_init

Conversation

@AmrDeveloper

Copy link
Copy Markdown
Member

Implement ImplicitValueInitExpr for ComplexType

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Feb 27, 2026
@llvmbot

llvmbot commented Feb 27, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-clang

Author: Amr Hesham (AmrDeveloper)

Changes

Implement ImplicitValueInitExpr for ComplexType


Full diff: https://github.com/llvm/llvm-project/pull/183836.diff

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+3-3)
  • (modified) clang/test/CIR/CodeGen/implicit-value-init-expr.cpp (+25)
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

@llvmbot

llvmbot commented Feb 27, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)

Changes

Implement ImplicitValueInitExpr for ComplexType


Full diff: https://github.com/llvm/llvm-project/pull/183836.diff

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp (+3-3)
  • (modified) clang/test/CIR/CodeGen/implicit-value-init-expr.cpp (+25)
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 andykaylor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, with one minor suggestion

Comment thread clang/test/CIR/CodeGen/implicit-value-init-expr.cpp Outdated
@github-actions

github-actions Bot commented Feb 27, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 115473 tests passed
  • 4051 tests skipped

✅ The build succeeded and all tests passed.

@AmrDeveloper
AmrDeveloper force-pushed the cir_complex_implict_value_init branch from 8f84e76 to 2249a38 Compare February 28, 2026 14:29
@AmrDeveloper
AmrDeveloper merged commit 3d086f5 into llvm:main Feb 28, 2026
10 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants