aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Pointer.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2024-10-31 15:15:59 +0100
committerGitHub <noreply@github.com>2024-10-31 15:15:59 +0100
commit2c82079924f1e43b211a6f233ea04ea911a7b581 (patch)
tree222155d7a4e9575301e6a7642827a6dcdcc7821a /clang/lib/AST/ByteCode/Pointer.cpp
parent1e072ae289d77c3c9704a9ae832c076a303c435b (diff)
downloadllvm-2c82079924f1e43b211a6f233ea04ea911a7b581.zip
llvm-2c82079924f1e43b211a6f233ea04ea911a7b581.tar.gz
llvm-2c82079924f1e43b211a6f233ea04ea911a7b581.tar.bz2
[clang][bytecode] Fix Pointer::toAPValue() for multidimensional arrays (#114400)
When we see an array root, that pointer might yet again be an array element, so check for that.
Diffstat (limited to 'clang/lib/AST/ByteCode/Pointer.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Pointer.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp
index c9de039..5448485 100644
--- a/clang/lib/AST/ByteCode/Pointer.cpp
+++ b/clang/lib/AST/ByteCode/Pointer.cpp
@@ -200,15 +200,26 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
// Build the path into the object.
Pointer Ptr = *this;
while (Ptr.isField() || Ptr.isArrayElement()) {
+
if (Ptr.isArrayRoot()) {
- Path.push_back(APValue::LValuePathEntry(
- {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
+ // An array root may still be an array element itself.
+ if (Ptr.isArrayElement()) {
+ Ptr = Ptr.expand();
+ unsigned Index = Ptr.getIndex();
+ Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
+ QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
+ Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
+ Ptr = Ptr.getArray();
+ } else {
+ Path.push_back(APValue::LValuePathEntry(
+ {Ptr.getFieldDesc()->asDecl(), /*IsVirtual=*/false}));
- if (const auto *FD =
- dyn_cast_if_present<FieldDecl>(Ptr.getFieldDesc()->asDecl()))
- Offset += getFieldOffset(FD);
+ if (const auto *FD =
+ dyn_cast_if_present<FieldDecl>(Ptr.getFieldDesc()->asDecl()))
+ Offset += getFieldOffset(FD);
- Ptr = Ptr.getBase();
+ Ptr = Ptr.getBase();
+ }
} else if (Ptr.isArrayElement()) {
Ptr = Ptr.expand();
unsigned Index;
@@ -219,7 +230,6 @@ APValue Pointer::toAPValue(const ASTContext &ASTCtx) const {
QualType ElemType = Ptr.getFieldDesc()->getElemQualType();
Offset += (Index * ASTCtx.getTypeSizeInChars(ElemType));
-
Path.push_back(APValue::LValuePathEntry::ArrayIndex(Index));
Ptr = Ptr.getArray();
} else {