Skip to content

Commit 5563d91

Browse files
committed
[clang][Interp] Prepare return value for composite InitListExprs
1 parent e439d22 commit 5563d91

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,23 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
11011101
return this->delegate(Inits[0]);
11021102
}
11031103

1104+
// Prepare composite return value.
1105+
if (!Initializing) {
1106+
if (GlobalDecl) {
1107+
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
1108+
if (!GlobalIndex)
1109+
return false;
1110+
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
1111+
return false;
1112+
} else {
1113+
std::optional<unsigned> LocalIndex = allocateLocal(E);
1114+
if (!LocalIndex)
1115+
return false;
1116+
if (!this->emitGetPtrGlobal(*LocalIndex, E))
1117+
return false;
1118+
}
1119+
}
1120+
11041121
QualType T = E->getType();
11051122
if (T->isRecordType()) {
11061123
const Record *R = getRecord(E->getType());

clang/test/AST/Interp/references.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ constexpr int RecordWithRef2() {
125125
return r.a;
126126
}
127127
static_assert(RecordWithRef2() == 200, "");
128+
129+
const char (&nonextended_string_ref)[3] = {"hi"};
130+
static_assert(nonextended_string_ref[0] == 'h', "");
131+
static_assert(nonextended_string_ref[1] == 'i', "");
132+
static_assert(nonextended_string_ref[2] == '\0', "");

0 commit comments

Comments
 (0)