Timm =?utf-8?q?Bäder?= <[email protected]>,
Timm =?utf-8?q?Bäder?= <[email protected]>,
Timm =?utf-8?q?Bäder?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>
================
@@ -3225,6 +3278,84 @@ bool CastFloatingIntegralAPS(InterpState &S, CodePtr
OpPC, uint32_t BitWidth,
return floatAPCast<true>(S, OpPC, F, BitWidth, FPOI);
}
+bool arrayElemPtrOpaque(InterpState &S, CodePtr OpPC, const OpaquePointer &OP,
+ int64_t Offset) {
+ QualType ArrTy;
+ if (OP.PathLength > 0) {
+ if (OP.path().back().Kind == PointerPathEntry::Array) {
+ ArrTy = OP.getSurroundingArray(S.getASTContext());
+ } else {
+ ArrTy = OP.getFieldType();
+ }
+ } else {
+ ArrTy = OP.getObjectType();
+ }
+
+ QualType ElemType;
+ bool PastEnd = true;
+ if (ArrTy->isArrayType()) {
+ const auto *AT = ArrTy->getAsArrayTypeUnsafe();
+ ElemType = AT->getElementType();
+ if (const auto *CAT = dyn_cast<ConstantArrayType>(AT))
+ PastEnd = Offset >= CAT->getSExtSize();
+ } else if (ArrTy->isRecordType()) {
+ ElemType = ArrTy;
+ } else {
+ ElemType = ArrTy;
+ }
+ if (ElemType.isNull())
+ return false;
+
+ unsigned NewPathLength = OP.PathLength + 1;
+ PointerPathEntry *NewPath = S.allocPointerPath(NewPathLength);
+ if (OP.Path)
+ std::memcpy(NewPath, OP.Path,
+ sizeof(PointerPathEntry) * (NewPathLength - 1));
+
+ NewPath[NewPathLength - 1] = PointerPathEntry::array(Offset);
+ S.Stk.push<Pointer>(OpaqueTag{}, OP.Base, ElemType.getTypePtr(), NewPath,
+ NewPathLength, PastEnd);
+ return true;
+}
+
+bool addSubOffsetOpaque(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
+ uint64_t Offset, bool Add) {
+ assert(Ptr.isOpaquePointer());
+ const OpaquePointer &OP = Ptr.asOpaquePointer();
+
+ QualType ArrTy = OP.getFieldType();
+ QualType ElemTy;
+ if (ArrTy->isArrayType())
+ ElemTy = ArrTy->getAsArrayTypeUnsafe()->getElementType();
+ else
+ ElemTy = ArrTy;
+
+ if (Offset != 0) {
+ if (isa<IncompleteArrayType>(ArrTy)) {
+ const SourceInfo &E = S.Current->getSource(OpPC);
+ S.FFDiag(E, diag::note_constexpr_unsized_array_indexed);
+ return false;
+ }
+
+ S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
+ << Offset << /*non-array*/ true << 0;
+ }
+
+ unsigned ElemSize =
+ S.getASTContext().getTypeSizeInChars(ElemTy).getQuantity();
+ unsigned NewOffset;
+ if (Add)
+ NewOffset = Ptr.getByteOffset() + (ElemSize * Offset);
+ else
+ NewOffset = Ptr.getByteOffset() - (ElemSize * Offset);
----------------
tbaederr wrote:
That code is a lot less clear than the current version IMO.
https://github.com/llvm/llvm-project/pull/213017
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits