Skip to content

Commit 4212838

Browse files
gitoleglanza
authored andcommittedMar 17, 2025
[CIR][CIRGen] Fix CXX codegen for default args (#1278)
This PR adds a support for for default arguments
1 parent 3cf0d5f commit 4212838

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
@@ -2636,6 +2636,11 @@ LValue CIRGenFunction::emitLValue(const Expr *E) {
26362636
// bitfield lvalue or some other non-simple lvalue?
26372637
return LV;
26382638
}
2639+
case Expr::CXXDefaultArgExprClass: {
2640+
auto *DAE = cast<CXXDefaultArgExpr>(E);
2641+
CXXDefaultArgExprScope Scope(*this, DAE);
2642+
return emitLValue(DAE->getExpr());
2643+
}
26392644
case Expr::ParenExprClass:
26402645
return emitLValue(cast<ParenExpr>(E)->getSubExpr());
26412646
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)
Please sign in to comment.