llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/122904.diff


3 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3) 
- (modified) clang/lib/AST/ByteCode/Compiler.h (+3-1) 
- (modified) clang/test/AST/ByteCode/cxx11.cpp (+11) 


``````````diff
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, "");
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/122904
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to