Skip to content

Commit ae73706

Browse files
committed
[clang][Interp] Fix references to objects
The previous commit tried to handle this in a way that's too general. Move the !Initializing case down to the array type.
1 parent a959ad1 commit ae73706

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

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

1110-
// Prepare composite return value.
1111-
if (!Initializing) {
1112-
if (GlobalDecl) {
1113-
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
1114-
if (!GlobalIndex)
1115-
return false;
1116-
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
1117-
return false;
1118-
} else {
1119-
std::optional<unsigned> LocalIndex = allocateLocal(E);
1120-
if (!LocalIndex)
1121-
return false;
1122-
if (!this->emitGetPtrGlobal(*LocalIndex, E))
1123-
return false;
1124-
}
1125-
}
1126-
11271110
QualType T = E->getType();
11281111
if (T->isRecordType()) {
11291112
const Record *R = getRecord(E->getType());
@@ -1224,6 +1207,23 @@ bool ByteCodeExprGen<Emitter>::visitInitList(ArrayRef<const Expr *> Inits,
12241207
}
12251208

12261209
if (T->isArrayType()) {
1210+
// Prepare composite return value.
1211+
if (!Initializing) {
1212+
if (GlobalDecl) {
1213+
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
1214+
if (!GlobalIndex)
1215+
return false;
1216+
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
1217+
return false;
1218+
} else {
1219+
std::optional<unsigned> LocalIndex = allocateLocal(E);
1220+
if (!LocalIndex)
1221+
return false;
1222+
if (!this->emitGetPtrLocal(*LocalIndex, E))
1223+
return false;
1224+
}
1225+
}
1226+
12271227
unsigned ElementIndex = 0;
12281228
for (const Expr *Init : Inits) {
12291229
if (!this->visitArrayElemInit(ElementIndex, Init))

clang/test/SemaCXX/cxx0x-initializer-references.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2+
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
23

34
struct one { char c; };
45
struct two { char c[2]; };

0 commit comments

Comments
 (0)