[clang][bytecode] Add init link for the RVO ptr (#122904)

This commit is contained in:
Timm Baeder 2025-01-14 17:18:04 +01:00 committed by GitHub
parent 193ea83dd7
commit 58fa55c04b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View File

@ -90,6 +90,8 @@ bool InitLink::emit(Compiler<Emitter> *Ctx, const Expr *E) const {
if (!Ctx->emitConstUint32(Offset, E))
return false;
return Ctx->emitArrayElemPtrPopUint32(E);
case K_RVO:
return Ctx->emitRVOPtr(E);
case K_InitList:
return true;
default:
@ -4998,6 +5000,7 @@ bool Compiler<Emitter>::visitReturnStmt(const ReturnStmt *RS) {
if (!this->visit(RE))
return false;
} else {
InitLinkScope<Emitter> ILS(this, InitLink::RVO());
// RVO - construct the value in the return location.
if (!this->emitRVOPtr(RE))
return false;

View File

@ -51,11 +51,13 @@ public:
K_Temp = 2,
K_Decl = 3,
K_Elem = 5,
K_InitList = 6
K_RVO = 6,
K_InitList = 7
};
static InitLink This() { return InitLink{K_This}; }
static InitLink InitList() { return InitLink{K_InitList}; }
static InitLink RVO() { return InitLink{K_RVO}; }
static InitLink Field(unsigned Offset) {
InitLink IL{K_Field};
IL.Offset = Offset;

View File

@ -174,3 +174,14 @@ void lambdas() {
int d;
int a9[1] = {[d = 0] = 1}; // both-error {{not an integral constant expression}}
}
namespace InitLinkToRVO {
struct A {
int y = 3;
int z = 1 + y;
};
constexpr A make() { return A {}; }
static_assert(make().z == 4, "");
}