Skip to content

Commit 3891619

Browse files
authored
[CIR][CIRGen] Fix CXX codegen for default args (#1278)
This PR adds a support for for default arguments
1 parent ef20d05 commit 3891619

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,11 @@ LValue CIRGenFunction::emitLValue(const Expr *E) {
26342634
// bitfield lvalue or some other non-simple lvalue?
26352635
return LV;
26362636
}
2637+
case Expr::CXXDefaultArgExprClass: {
2638+
auto *DAE = cast<CXXDefaultArgExpr>(E);
2639+
CXXDefaultArgExprScope Scope(*this, DAE);
2640+
return emitLValue(DAE->getExpr());
2641+
}
26372642
case Expr::ParenExprClass:
26382643
return emitLValue(cast<ParenExpr>(E)->getSubExpr());
26392644
case Expr::DeclRefExprClass:

clang/test/CIR/CodeGen/defaultarg.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -std=c++17 %s -o - | FileCheck %s
2+
3+
void bar(const int &i = 42);
4+
5+
void foo() {
6+
bar();
7+
}
8+
9+
// CHECK: [[TMP0:%.*]] = cir.alloca !s32i
10+
// CHECK: [[TMP1:%.*]] = cir.const #cir.int<42>
11+
// CHECK: cir.store [[TMP1]], [[TMP0]]
12+
// CHECK: cir.call @_Z3barRKi([[TMP0]])

0 commit comments

Comments
 (0)