Skip to content

Conversation

@andykaylor
Copy link
Contributor

This adds a handle for VisitImplicitValueInitExpr in ConstExprEmitter.

This adds a handle for VisitImplicitValueInitExpr in ConstExprEmitter.
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Oct 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clangir

Author: Andy Kaylor (andykaylor)

Changes

This adds a handle for VisitImplicitValueInitExpr in ConstExprEmitter.


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

2 Files Affected:

  • (modified) clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp (+1-3)
  • (modified) clang/test/CIR/CodeGen/struct-init.cpp (+6)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
index 19ed6560245b4..65e6a3915f241 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
@@ -1028,9 +1028,7 @@ class ConstExprEmitter
 
   mlir::Attribute VisitImplicitValueInitExpr(ImplicitValueInitExpr *e,
                                              QualType t) {
-    cgm.errorNYI(e->getBeginLoc(),
-                 "ConstExprEmitter::VisitImplicitValueInitExpr");
-    return {};
+    return cgm.getBuilder().getZeroInitAttr(cgm.convertType(t));
   }
 
   mlir::Attribute VisitInitListExpr(InitListExpr *ile, QualType t) {
diff --git a/clang/test/CIR/CodeGen/struct-init.cpp b/clang/test/CIR/CodeGen/struct-init.cpp
index a47ef530b8369..2887e6f404ffc 100644
--- a/clang/test/CIR/CodeGen/struct-init.cpp
+++ b/clang/test/CIR/CodeGen/struct-init.cpp
@@ -9,6 +9,12 @@ struct S {
   int a, b, c;
 };
 
+S partial_init = { 1 };
+
+// CIR: cir.global external @partial_init = #cir.const_record<{#cir.int<1> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i}> : !rec_S
+// LLVM: @partial_init = global %struct.S { i32 1, i32 0, i32 0 }
+// OGCG: @partial_init = global %struct.S { i32 1, i32 0, i32 0 }
+
 void init() {
   S s1 = {1, 2, 3};
   S s2 = {4, 5};

@andykaylor andykaylor merged commit c89eb13 into llvm:main Oct 21, 2025
13 checks passed
@andykaylor andykaylor deleted the cir-implicit-value-init branch October 21, 2025 22:20
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
This adds a handle for VisitImplicitValueInitExpr in ConstExprEmitter.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
This adds a handle for VisitImplicitValueInitExpr in ConstExprEmitter.
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