summaryrefslogtreecommitdiff
path: root/clang/lib/AST/Interp/Pointer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/Interp/Pointer.cpp')
-rw-r--r--clang/lib/AST/Interp/Pointer.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/Pointer.cpp b/clang/lib/AST/Interp/Pointer.cpp
index 2b1f8b460510..ba9683a059e1 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -597,3 +597,30 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
return std::nullopt;
return Result;
}
+
+IntPointer IntPointer::atOffset(const ASTContext &ASTCtx,
+ unsigned Offset) const {
+ if (!this->Desc)
+ return *this;
+ const Record *R = this->Desc->ElemRecord;
+ if (!R)
+ return *this;
+
+ const Record::Field *F = nullptr;
+ for (auto &It : R->fields()) {
+ if (It.Offset == Offset) {
+ F = &It;
+ break;
+ }
+ }
+ if (!F)
+ return *this;
+
+ const FieldDecl *FD = F->Decl;
+ const ASTRecordLayout &Layout = ASTCtx.getASTRecordLayout(FD->getParent());
+ unsigned FieldIndex = FD->getFieldIndex();
+ uint64_t FieldOffset =
+ ASTCtx.toCharUnitsFromBits(Layout.getFieldOffset(FieldIndex))
+ .getQuantity();
+ return IntPointer{this->Desc, FieldOffset};
+}