From: Timm Bäder Date: Mon, 26 Sep 2022 06:44:09 +0000 (+0200) Subject: [clang][Interp] Fix Pointer::toAPValue() LValuePath order X-Git-Tag: upstream/17.0.6~30581 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d2d426a51e122231443d89b196b0c6e91a5b147;p=platform%2Fupstream%2Fllvm.git [clang][Interp] Fix Pointer::toAPValue() LValuePath order --- diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp index ec00afc..ad4e4e8 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 8839c59..d0a40c8 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, "");