Skip to content

Commit 518b38c

Browse files
authored
[CIR] Upstream handling for C++ default argument l-values (llvm#167999)
This adds handling emitting C++ default arguments as l-values.
1 parent 0a5be0f commit 518b38c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,11 @@ LValue CIRGenFunction::emitLValue(const Expr *e) {
928928
assert(!cir::MissingFeatures::cleanupWithPreservedValues());
929929
return lv;
930930
}
931+
case Expr::CXXDefaultArgExprClass: {
932+
auto *dae = cast<CXXDefaultArgExpr>(e);
933+
CXXDefaultArgExprScope scope(*this, dae);
934+
return emitLValue(dae->getExpr());
935+
}
931936
case Expr::ParenExprClass:
932937
return emitLValue(cast<ParenExpr>(e)->getSubExpr());
933938
case Expr::GenericSelectionExprClass:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -std=c++17 %s -o %t.cir
2+
// RUN: FileCheck %s --input-file=%t.cir --check-prefix=CIR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -std=c++17 %s -o %t-cir.ll
4+
// RUN: FileCheck %s --input-file=%t-cir.ll --check-prefix=LLVM
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -std=c++17 %s -o %t.ll
6+
// RUN: FileCheck %s --input-file=%t.ll --check-prefix=OGCG
7+
8+
void bar(const int &i = 42);
9+
10+
void foo() {
11+
bar();
12+
}
13+
14+
// CIR: cir.func {{.*}} @_Z3foov()
15+
// CIR: cir.scope {
16+
// CIR: %[[TMP0:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["ref.tmp0"]
17+
// CIR: %[[TMP1:.*]] = cir.const #cir.int<42>
18+
// CIR: cir.store{{.*}} %[[TMP1]], %[[TMP0]]
19+
// CIR: cir.call @_Z3barRKi(%[[TMP0]])
20+
// CIR: }
21+
22+
// LLVM: define{{.*}} @_Z3foov()
23+
// LLVM: %[[TMP0:.*]] = alloca i32
24+
// LLVM: br label %[[SCOPE_LABEL:.*]]
25+
// LLVM: [[SCOPE_LABEL]]:
26+
// LLVM: store i32 42, ptr %[[TMP0]]
27+
// LLVM: call void @_Z3barRKi(ptr %[[TMP0]])
28+
29+
// OGCG: define{{.*}} @_Z3foov()
30+
// OGCG: %[[TMP0:.*]] = alloca i32
31+
// OGCG: store i32 42, ptr %[[TMP0]]
32+
// OGCG: call void @_Z3barRKi(ptr {{.*}} %[[TMP0]])

0 commit comments

Comments
 (0)