[clang] [clang][Interp] Integral pointers (PR #84159)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 6 05:55:48 PST 2024
================
@@ -172,72 +217,107 @@ class Pointer {
Adjust = sizeof(InitMapPtr);
else
Adjust = sizeof(InlineDescriptor);
- return Pointer(Pointee, Base, Base + getSize() + Adjust);
+ return Pointer(asBlockPointer().Pointee, asBlockPointer().Base,
+ asBlockPointer().Base + getSize() + Adjust);
}
// Do not step out of array elements.
- if (Base != Offset)
+ if (asBlockPointer().Base != Offset)
return *this;
// If at base, point to an array of base types.
- if (Base == 0 || Base == sizeof(InlineDescriptor))
- return Pointer(Pointee, RootPtrMark, 0);
+ if (asBlockPointer().Base == 0 ||
+ asBlockPointer().Base == sizeof(InlineDescriptor))
+ return Pointer(asBlockPointer().Pointee, RootPtrMark, 0);
// Step into the containing array, if inside one.
- unsigned Next = Base - getInlineDesc()->Offset;
+ unsigned Next = asBlockPointer().Base - getInlineDesc()->Offset;
const Descriptor *Desc =
Next == 0 ? getDeclDesc() : getDescriptor(Next)->Desc;
if (!Desc->IsArray)
return *this;
- return Pointer(Pointee, Next, Offset);
+ return Pointer(asBlockPointer().Pointee, Next, Offset);
}
/// Checks if the pointer is null.
- bool isZero() const { return Pointee == nullptr; }
+ bool isZero() const {
+ if (Offset != 0)
+ return false;
+
+ if (isBlockPointer())
+ return asBlockPointer().Pointee == nullptr;
+ else if (isIntegralPointer())
+ return asIntPointer().Value == 0;
+ llvm_unreachable("zomg");
----------------
AaronBallman wrote:
```suggestion
assert(isIntegralPointer() && "expected an integral pointer");
return asIntPointer().Value == 0;
```
https://github.com/llvm/llvm-project/pull/84159
More information about the cfe-commits
mailing list