Skip to content

Commit 58fa55c

Browse files
authored
[clang][bytecode] Add init link for the RVO ptr (#122904)
1 parent 193ea83 commit 58fa55c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ bool InitLink::emit(Compiler<Emitter> *Ctx, const Expr *E) const {
9090
if (!Ctx->emitConstUint32(Offset, E))
9191
return false;
9292
return Ctx->emitArrayElemPtrPopUint32(E);
93+
case K_RVO:
94+
return Ctx->emitRVOPtr(E);
9395
case K_InitList:
9496
return true;
9597
default:
@@ -4998,6 +5000,7 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
49985000
if (!this->visit(RE))
49995001
return false;
50005002
} else {
5003+
InitLinkScope<Emitter> ILS(this, InitLink::RVO());
50015004
// RVO - construct the value in the return location.
50025005
if (!this->emitRVOPtr(RE))
50035006
return false;

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ struct InitLink {
5151
K_Temp = 2,
5252
K_Decl = 3,
5353
K_Elem = 5,
54-
K_InitList = 6
54+
K_RVO = 6,
55+
K_InitList = 7
5556
};
5657

5758
static InitLink This() { return InitLink{K_This}; }
5859
static InitLink InitList() { return InitLink{K_InitList}; }
60+
static InitLink RVO() { return InitLink{K_RVO}; }
5961
static InitLink Field(unsigned Offset) {
6062
InitLink IL{K_Field};
6163
IL.Offset = Offset;

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,14 @@ void lambdas() {
174174
int d;
175175
int a9[1] = {[d = 0] = 1}; // both-error {{not an integral constant expression}}
176176
}
177+
178+
179+
namespace InitLinkToRVO {
180+
struct A {
181+
int y = 3;
182+
int z = 1 + y;
183+
};
184+
185+
constexpr A make() { return A {}; }
186+
static_assert(make().z == 4, "");
187+
}

0 commit comments

Comments
 (0)