[clang] 4d2d426 - [clang][Interp] Fix Pointer::toAPValue() LValuePath order
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 03:31:46 PDT 2022
Author: Timm Bäder
Date: 2022-10-14T12:31:24+02:00
New Revision: 4d2d426a51e122231443d89b196b0c6e91a5b147
URL: https://github.com/llvm/llvm-project/commit/4d2d426a51e122231443d89b196b0c6e91a5b147
DIFF: https://github.com/llvm/llvm-project/commit/4d2d426a51e122231443d89b196b0c6e91a5b147.diff
LOG: [clang][Interp] Fix Pointer::toAPValue() LValuePath order
Added:
Modified:
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index ec00afc37124..ad4e4e8a8a85 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -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);
}
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index 8839c597530c..d0a40c8d2583 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -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, "");
More information about the cfe-commits
mailing list