https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/122904
None >From 24b323b514d130b12898eaeb63da05f6456e2f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 14 Jan 2025 15:09:50 +0100 Subject: [PATCH] [clang][bytecode] Add init link for the RVO ptr --- clang/lib/AST/ByteCode/Compiler.cpp | 3 +++ clang/lib/AST/ByteCode/Compiler.h | 4 +++- clang/test/AST/ByteCode/cxx11.cpp | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 2326480fe2eaf4..a5dfaaf3196559 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -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; diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index 2d5b76f789543e..f9a597a16ef4ae 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -51,11 +51,13 @@ struct InitLink { 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; diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 86b58283023bc8..23582e9ab556a8 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -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, ""); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits