Skip to content

Commit 59d641a

Browse files
authored
[CIR] Upstream support for SubstNonTypeTemplateParmExpr (#146751)
Upstream support for SubstNonTypeTemplateParmExpr
1 parent a244907 commit 59d641a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
371371
return builder.create<cir::CastOp>(src.getLoc(), fullDstTy, *castKind, src);
372372
}
373373

374+
mlir::Value
375+
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e) {
376+
return Visit(e->getReplacement());
377+
}
378+
374379
mlir::Value VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *e);
375380
mlir::Value
376381
VisitAbstractConditionalOperator(const AbstractConditionalOperator *e);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
template <const int N>
9+
void template_foo() {
10+
int a = N + 5;
11+
}
12+
13+
// CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
14+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
15+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<5> : !s32i
16+
// CIR: %[[ADD:.*]] = cir.binop(add, %[[CONST_1]], %[[CONST_2]]) nsw : !s32i
17+
// CIR: cir.store{{.*}} %[[ADD]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
18+
19+
// LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
20+
// LLVM: store i32 6, ptr %[[INIT]], align 4
21+
22+
// OGCG: %[[INIT:.*]] = alloca i32, align 4
23+
// OGCG: store i32 6, ptr %[[INIT]], align 4
24+
25+
void foo() {
26+
template_foo<1>();
27+
}

0 commit comments

Comments
 (0)