[clang][Interp] Fix Pointer::toAPValue() LValuePath order
authorTimm Bäder <tbaeder@redhat.com>
Mon, 26 Sep 2022 06:44:09 +0000 (08:44 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Fri, 14 Oct 2022 10:31:24 +0000 (12:31 +0200)
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/records.cpp

index ec00afc..ad4e4e8 100644 (file)
@@ -129,6 +129,12 @@ APValue Pointer::toAPValue() const {
     }
   }
 
+  // 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);
 }
 
index 8839c59..d0a40c8 100644 (file)
@@ -177,11 +177,7 @@ struct FourBoolPairs {
 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, "");