[PATCH] D134629: [clang][Interp] Fix Pointer::toAPValue() LValuePath order

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 25 23:58:08 PDT 2022


tbaeder updated this revision to Diff 462823.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134629/new/

https://reviews.llvm.org/D134629

Files:
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -153,11 +153,7 @@
 constexpr FourBoolPairs LT;
 // Copy ctor
 constexpr FourBoolPairs LT2 = LT;
-// FIXME: The copy constructor call above
-//   works, but APValue we generate for it is
-//   not sufficiently correct, so the lvalue-to-rvalue
-//   conversion in ExprConstant.c runs into an assertion.
-//static_assert(LT2.v[0].first == false, "");
-//static_assert(LT2.v[0].second == false, "");
-//static_assert(LT2.v[2].first == true, "");
-//static_assert(LT2.v[2].second == false, "");
+static_assert(LT2.v[0].first == false, "");
+static_assert(LT2.v[0].second == false, "");
+static_assert(LT2.v[2].first == true, "");
+static_assert(LT2.v[2].second == false, "");
Index: clang/lib/AST/Interp/Pointer.cpp
===================================================================
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -148,6 +148,12 @@
     }
   }
 
+  // We assemble the LValuePath starting from the innermost pointer to the
+  // outermost one. SO in a.b.c, the first element in Path will refer to
+  // the field 'c', while later code expects it to refer to 'a'.
+  // Just invert the order of the elements.
+  std::reverse(Path.begin(), Path.end());
+
   return APValue(Base, Offset, Path, IsOnePastEnd, IsNullPtr);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134629.462823.patch
Type: text/x-patch
Size: 1451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220926/ef7ffec8/attachment.bin>


More information about the cfe-commits mailing list