https://github.com/amanmaurya92 updated 
https://github.com/llvm/llvm-project/pull/223603

>From 765966be3835f54f04d3288f79a9a55128019334 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <[email protected]>
Date: Tue, 15 Sep 2026 11:11:38 +0530
Subject: [PATCH 1/3] [CIR] Support SubstNonTypeTemplateParmExpr for aggregates

Visit the replacement expression for aggregate NTTPs, matching classic Clang 
codegen and existing CIR NTTP emitters. The gap was analyzed with LLM 
assistance.

Issue #223533

Assisted-by: Antigravity
---
 clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp |  3 +-
 .../CIR/CodeGen/non-type-template-param.cpp   | 81 ++++++++++++-------
 2 files changed, 55 insertions(+), 29 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
index afc32a3d24c421..2fb66232d806cd 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
@@ -402,8 +402,7 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
   }
   void VisitUnaryExtension(UnaryOperator *e) { Visit(e->getSubExpr()); }
   void VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) {
-    cgf.cgm.errorNYI(e->getSourceRange(),
-                     "AggExprEmitter: VisitSubstNonTypeTemplateParmExpr");
+    Visit(e->getReplacement());
   }
   void VisitConstantExpr(ConstantExpr *e) {
     ensureDest(cgf.getLoc(e->getSourceRange()), e->getType());
diff --git a/clang/test/CIR/CodeGen/non-type-template-param.cpp 
b/clang/test/CIR/CodeGen/non-type-template-param.cpp
index 9edb7c0ae53d75..4711c1dbf10e07 100644
--- a/clang/test/CIR/CodeGen/non-type-template-param.cpp
+++ b/clang/test/CIR/CodeGen/non-type-template-param.cpp
@@ -1,27 +1,54 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-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 -Wno-unused-value 
-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 -Wno-unused-value 
-emit-llvm %s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
-
-template <const int N>
-void template_foo() {
-  int a = N + 5;
-}
-
-// CIR: %[[INIT:.*]] = cir.alloca "a" {{.*}} init : !cir.ptr<!s32i>
-// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
-// CIR: %[[CONST_2:.*]] = cir.const #cir.int<5> : !s32i
-// CIR: %[[ADD:.*]] = cir.add nsw %[[CONST_1]], %[[CONST_2]] : !s32i
-// CIR: cir.store{{.*}} %[[ADD]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
-
-// LLVM: %[[INIT:.*]] = alloca i32, align 4
-// LLVM: store i32 6, ptr %[[INIT]], align 4
-
-// OGCG: %[[INIT:.*]] = alloca i32, align 4
-// OGCG: store i32 6, ptr %[[INIT]], align 4
-
-void foo() {
-  template_foo<1>();
-}
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
+
+template <const int N>
+void template_foo() {
+  int a = N + 5;
+}
+
+// CIR: %[[INIT:.*]] = cir.alloca "a" {{.*}} init : !cir.ptr<!s32i>
+// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
+// CIR: %[[CONST_2:.*]] = cir.const #cir.int<5> : !s32i
+// CIR: %[[ADD:.*]] = cir.add nsw %[[CONST_1]], %[[CONST_2]] : !s32i
+// CIR: cir.store{{.*}} %[[ADD]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
+
+// LLVM: %[[INIT:.*]] = alloca i32, align 4
+// LLVM: store i32 6, ptr %[[INIT]], align 4
+
+// OGCG: %[[INIT:.*]] = alloca i32, align 4
+// OGCG: store i32 6, ptr %[[INIT]], align 4
+
+void foo() {
+  template_foo<1>();
+}
+
+struct Point {
+  int x;
+  int y;
+};
+
+template <Point P>
+void template_agg() {
+  Point a = P;
+}
+
+// CIR: %[[A:.*]] = cir.alloca {{.*}}
+// CIR: %[[GLOBAL:.*]] = cir.get_global @{{.*}}
+// CIR: cir.copy %[[GLOBAL]] to %[[A]] : !cir.ptr<{{.*}}>
+// CIR: cir.return
+
+// LLVM: %[[A:.*]] = alloca %struct.Point
+// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %[[A]], ptr 
align {{[0-9]+}} @{{.*}}, i64 8, i1 false)
+// LLVM: ret void
+
+// OGCG: %[[A:.*]] = alloca %struct.Point
+// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %[[A]], ptr 
align {{[0-9]+}} @{{.*}}, i64 8, i1 false)
+// OGCG: ret void
+
+void bar() {
+  template_agg<Point{1, 2}>();
+}

>From 30ccdf3d79efc1e6d014525699af21860513bc12 Mon Sep 17 00:00:00 2001
From: Aman Maurya <[email protected]>
Date: Tue, 15 Sep 2026 11:30:18 +0530
Subject: [PATCH 2/3] Update clang/test/CIR/CodeGen/non-type-template-param.cpp

Co-authored-by: Andy Kaylor <[email protected]>
---
 clang/test/CIR/CodeGen/non-type-template-param.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CIR/CodeGen/non-type-template-param.cpp 
b/clang/test/CIR/CodeGen/non-type-template-param.cpp
index 4711c1dbf10e07..97567cb3c14b07 100644
--- a/clang/test/CIR/CodeGen/non-type-template-param.cpp
+++ b/clang/test/CIR/CodeGen/non-type-template-param.cpp
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
 // RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -emit-llvm %s -o %t.ll
-// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
 
 template <const int N>
 void template_foo() {

>From 9229f940136b1bc30e3bb4619e2800e8ffa48320 Mon Sep 17 00:00:00 2001
From: amanmaurya92 <[email protected]>
Date: Tue, 15 Sep 2026 11:32:07 +0530
Subject: [PATCH 3/3] [CIR] Remove redundant OGCG check lines from NTTP test

---
 clang/test/CIR/CodeGen/non-type-template-param.cpp | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/clang/test/CIR/CodeGen/non-type-template-param.cpp 
b/clang/test/CIR/CodeGen/non-type-template-param.cpp
index 97567cb3c14b07..db792700363d42 100644
--- a/clang/test/CIR/CodeGen/non-type-template-param.cpp
+++ b/clang/test/CIR/CodeGen/non-type-template-param.cpp
@@ -19,9 +19,6 @@ void template_foo() {
 // LLVM: %[[INIT:.*]] = alloca i32, align 4
 // LLVM: store i32 6, ptr %[[INIT]], align 4
 
-// OGCG: %[[INIT:.*]] = alloca i32, align 4
-// OGCG: store i32 6, ptr %[[INIT]], align 4
-
 void foo() {
   template_foo<1>();
 }
@@ -45,10 +42,6 @@ void template_agg() {
 // LLVM: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %[[A]], ptr 
align {{[0-9]+}} @{{.*}}, i64 8, i1 false)
 // LLVM: ret void
 
-// OGCG: %[[A:.*]] = alloca %struct.Point
-// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %[[A]], ptr 
align {{[0-9]+}} @{{.*}}, i64 8, i1 false)
-// OGCG: ret void
-
 void bar() {
   template_agg<Point{1, 2}>();
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to