Skip to content

Commit

Permalink
[clang][Interp] Prepare return value for composite InitListExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr authored and EthanLuisMcDonough committed Aug 13, 2024
1 parent f29bad3 commit ffbb050
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,23 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
return this->delegate(Inits[0]);
}

// Prepare composite return value.
if (!Initializing) {
if (GlobalDecl) {
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
if (!GlobalIndex)
return false;
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
return false;
} else {
std::optional<unsigned> 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());
Expand Down
5 changes: 5 additions & 0 deletions clang/test/AST/Interp/references.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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', "");

0 comments on commit ffbb050

Please sign in to comment.