Skip to content

Commit e5936b2

Browse files
committed
[clang][Interp][NFC] Fix toAPValue() for array root pointers
isArrayElement() returns false for them, so we used to add the decl to the path, causing wrong APValues to be generated.
1 parent 5cb2ea5 commit e5936b2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ APValue Pointer::toAPValue() const {
144144

145145
// TODO: compute the offset into the object.
146146
CharUnits Offset = CharUnits::Zero();
147-
bool IsOnePastEnd = isOnePastEnd();
148147

149148
// Build the path into the object.
150149
Pointer Ptr = *this;
151150
while (Ptr.isField() || Ptr.isArrayElement()) {
152-
if (Ptr.isArrayElement()) {
153-
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getIndex()));
151+
if (Ptr.isArrayRoot()) {
152+
Path.push_back(APValue::LValuePathEntry::ArrayIndex(0));
153+
Ptr = Ptr.getBase();
154+
} else if (Ptr.isArrayElement()) {
155+
if (Ptr.isOnePastEnd())
156+
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getArray().getNumElems()));
157+
else
158+
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getIndex()));
154159
Ptr = Ptr.getArray();
155160
} else {
156161
// TODO: figure out if base is virtual
@@ -173,7 +178,7 @@ APValue Pointer::toAPValue() const {
173178
// Just invert the order of the elements.
174179
std::reverse(Path.begin(), Path.end());
175180

176-
return APValue(Base, Offset, Path, IsOnePastEnd, /*IsNullPtr=*/false);
181+
return APValue(Base, Offset, Path, /*IsOnePastEnd=*/false, /*IsNullPtr=*/false);
177182
}
178183

179184
void Pointer::print(llvm::raw_ostream &OS) const {

0 commit comments

Comments
 (0)