Skip to content

Commit 2cae03e

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp] Use an array root's field decl in the LValuePath
Summary: Instead of pushing the index 0. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251017
1 parent b6d6893 commit 2cae03e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

clang/lib/AST/Interp/Pointer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ APValue Pointer::toAPValue() const {
152152
Pointer Ptr = *this;
153153
while (Ptr.isField() || Ptr.isArrayElement()) {
154154
if (Ptr.isArrayRoot()) {
155-
Path.push_back(APValue::LValuePathEntry::ArrayIndex(0));
156-
Ptr = Ptr.getBase();
155+
Path.push_back(APValue::LValuePathEntry(
156+
{Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
157+
Ptr = Ptr.getBase();
157158
} else if (Ptr.isArrayElement()) {
158159
if (Ptr.isOnePastEnd())
159160
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getArray().getNumElems()));

clang/test/AST/Interp/functions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,3 +644,21 @@ namespace FunctionCast {
644644
// both-warning {{are a Clang extension}}
645645
int b[(int)IntFn(f)()]; // ok
646646
}
647+
648+
#if __cplusplus >= 202002L
649+
namespace StableAddress {
650+
template<unsigned N> struct str {
651+
char arr[N];
652+
};
653+
// FIXME: Deduction guide not needed with P1816R0.
654+
template<unsigned N> str(const char (&)[N]) -> str<N>;
655+
656+
template<str s> constexpr int sum() {
657+
int n = 0;
658+
for (char c : s.arr)
659+
n += c;
660+
return n;
661+
}
662+
static_assert(sum<str{"$hello $world."}>() == 1234, "");
663+
}
664+
#endif

0 commit comments

Comments
 (0)