@@ -209,6 +209,10 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
209209 return ASTCtx.toCharUnitsFromBits (Layout.getFieldOffset (FieldIndex));
210210 };
211211
212+ bool UsePath = true ;
213+ if (getType ()->isLValueReferenceType ())
214+ UsePath = false ;
215+
212216 // Build the path into the object.
213217 Pointer Ptr = *this ;
214218 while (Ptr.isField () || Ptr.isArrayElement ()) {
@@ -217,38 +221,42 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
217221 // An array root may still be an array element itself.
218222 if (Ptr.isArrayElement ()) {
219223 Ptr = Ptr.expand ();
224+ const Descriptor *Desc = Ptr.getFieldDesc ();
220225 unsigned Index = Ptr.getIndex ();
221- Path.push_back (APValue::LValuePathEntry::ArrayIndex (Index));
222- QualType ElemType = Ptr.getFieldDesc ()->getElemQualType ();
226+ QualType ElemType = Desc->getElemQualType ();
223227 Offset += (Index * ASTCtx.getTypeSizeInChars (ElemType));
228+ if (Ptr.getArray ().getType ()->isArrayType ())
229+ Path.push_back (APValue::LValuePathEntry::ArrayIndex (Index));
224230 Ptr = Ptr.getArray ();
225231 } else {
226- Path.push_back (APValue::LValuePathEntry (
227- {Ptr.getFieldDesc ()->asDecl (), /* IsVirtual=*/ false }));
232+ const Descriptor *Desc = Ptr.getFieldDesc ();
233+ const auto *Dcl = Desc->asDecl ();
234+ Path.push_back (APValue::LValuePathEntry ({Dcl, /* IsVirtual=*/ false }));
228235
229- if (const auto *FD =
230- dyn_cast_if_present<FieldDecl>(Ptr.getFieldDesc ()->asDecl ()))
236+ if (const auto *FD = dyn_cast_if_present<FieldDecl>(Dcl))
231237 Offset += getFieldOffset (FD);
232238
233239 Ptr = Ptr.getBase ();
234240 }
235241 } else if (Ptr.isArrayElement ()) {
236242 Ptr = Ptr.expand ();
243+ const Descriptor *Desc = Ptr.getFieldDesc ();
237244 unsigned Index;
238245 if (Ptr.isOnePastEnd ())
239246 Index = Ptr.getArray ().getNumElems ();
240247 else
241248 Index = Ptr.getIndex ();
242249
243- QualType ElemType = Ptr. getFieldDesc () ->getElemQualType ();
250+ QualType ElemType = Desc ->getElemQualType ();
244251 Offset += (Index * ASTCtx.getTypeSizeInChars (ElemType));
245- Path.push_back (APValue::LValuePathEntry::ArrayIndex (Index));
252+ if (Ptr.getArray ().getType ()->isArrayType ())
253+ Path.push_back (APValue::LValuePathEntry::ArrayIndex (Index));
246254 Ptr = Ptr.getArray ();
247255 } else {
256+ const Descriptor *Desc = Ptr.getFieldDesc ();
248257 bool IsVirtual = false ;
249258
250259 // Create a path entry for the field.
251- const Descriptor *Desc = Ptr.getFieldDesc ();
252260 if (const auto *BaseOrMember = Desc->asDecl ()) {
253261 if (const auto *FD = dyn_cast<FieldDecl>(BaseOrMember)) {
254262 Ptr = Ptr.getBase ();
@@ -281,8 +289,11 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
281289 // Just invert the order of the elements.
282290 std::reverse (Path.begin (), Path.end ());
283291
284- return APValue (Base, Offset, Path, /* IsOnePastEnd=*/ isOnePastEnd (),
285- /* IsNullPtr=*/ false );
292+ if (UsePath)
293+ return APValue (Base, Offset, Path,
294+ /* IsOnePastEnd=*/ !isElementPastEnd () && isOnePastEnd ());
295+
296+ return APValue (Base, Offset, APValue::NoLValuePath ());
286297}
287298
288299void Pointer::print (llvm::raw_ostream &OS) const {
0 commit comments