diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 77a1c64d40189c..e0500983a31b5d 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1101,6 +1101,23 @@ bool ByteCodeExprGen::visitInitList(ArrayRef Inits, return this->delegate(Inits[0]); } + // Prepare composite return value. + if (!Initializing) { + if (GlobalDecl) { + std::optional GlobalIndex = P.createGlobal(E); + if (!GlobalIndex) + return false; + if (!this->emitGetPtrGlobal(*GlobalIndex, E)) + return false; + } else { + std::optional LocalIndex = allocateLocal(E); + if (!LocalIndex) + return false; + if (!this->emitGetPtrGlobal(*LocalIndex, E)) + return false; + } + } + QualType T = E->getType(); if (T->isRecordType()) { const Record *R = getRecord(E->getType()); diff --git a/clang/test/AST/Interp/references.cpp b/clang/test/AST/Interp/references.cpp index 5dc6067db6a642..efb756545b4aa1 100644 --- a/clang/test/AST/Interp/references.cpp +++ b/clang/test/AST/Interp/references.cpp @@ -125,3 +125,8 @@ constexpr int RecordWithRef2() { return r.a; } static_assert(RecordWithRef2() == 200, ""); + +const char (&nonextended_string_ref)[3] = {"hi"}; +static_assert(nonextended_string_ref[0] == 'h', ""); +static_assert(nonextended_string_ref[1] == 'i', ""); +static_assert(nonextended_string_ref[2] == '\0', "");