[clang] 39d751a - [clang][Interp] Use an array root's field decl in the LValuePath
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 17 02:27:03 PDT 2024
Author: Timm Bäder
Date: 2024-07-17T11:26:50+02:00
New Revision: 39d751ad976ba9f5e8a1ad3880559faba38c3c3f
URL: https://github.com/llvm/llvm-project/commit/39d751ad976ba9f5e8a1ad3880559faba38c3c3f
DIFF: https://github.com/llvm/llvm-project/commit/39d751ad976ba9f5e8a1ad3880559faba38c3c3f.diff
LOG: [clang][Interp] Use an array root's field decl in the LValuePath
Instead of pushing the index 0.
Added:
Modified:
clang/lib/AST/Interp/Pointer.cpp
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index b2e3a7ff70881..ff4da0fa805dc 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -152,8 +152,9 @@ APValue Pointer::toAPValue() const {
Pointer Ptr = *this;
while (Ptr.isField() || Ptr.isArrayElement()) {
if (Ptr.isArrayRoot()) {
- Path.push_back(APValue::LValuePathEntry::ArrayIndex(0));
- Ptr = Ptr.getBase();
+ Path.push_back(APValue::LValuePathEntry(
+ {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
+ Ptr = Ptr.getBase();
} else if (Ptr.isArrayElement()) {
if (Ptr.isOnePastEnd())
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Ptr.getArray().getNumElems()));
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index fa29e08a30175..f190262ad3ebe 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -644,3 +644,21 @@ namespace FunctionCast {
// both-warning {{are a Clang extension}}
int b[(int)IntFn(f)()]; // ok
}
+
+#if __cplusplus >= 202002L
+namespace StableAddress {
+ template<unsigned N> struct str {
+ char arr[N];
+ };
+ // FIXME: Deduction guide not needed with P1816R0.
+ template<unsigned N> str(const char (&)[N]) -> str<N>;
+
+ template<str s> constexpr int sum() {
+ int n = 0;
+ for (char c : s.arr)
+ n += c;
+ return n;
+ }
+ static_assert(sum<str{"$hello $world."}>() == 1234, "");
+}
+#endif
More information about the cfe-commits
mailing list